You are here

public function QuizNavigationTest::testQuestionNavigationSkipping in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationSkipping()
  2. 6.x tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationSkipping()

Test that a user can skip a question.

File

tests/src/Functional/QuizNavigationTest.php, line 105

Class

QuizNavigationTest
Test question navigation.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testQuestionNavigationSkipping() {
  $this
    ->drupalLogin($this->admin);

  // Default behavior, anyway.
  $quiz_node = $this
    ->createQuiz(array(
    'allow_skipping' => 1,
  ));

  // 3 questions.
  $question1 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question1, $quiz_node);
  $question2 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question2, $quiz_node);
  $question3 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question3, $quiz_node);

  // Ensure next questions are blocked until skipped.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/1");
  $this
    ->assertResponse(200);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/2");
  $this
    ->assertResponse(403);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/3");
  $this
    ->assertResponse(403);

  // Leave a question blank.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/1");
  $this
    ->drupalPostForm(NULL, array(), t('Leave blank'));

  // Now question 2 is accessible.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/2");
  $this
    ->assertResponse(200);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/3");
  $this
    ->assertResponse(403);
}