You are here

public function QuizNavigationTest::testQuestionNavigationBasic in Quiz 8.5

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

Test the question navigation and access.

File

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

Class

QuizNavigationTest
Test question navigation.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testQuestionNavigationBasic() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->createQuiz();

  // 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);

  // Testing basic navigation. Ensure next questions are not yet available.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/1");
  $this
    ->assertText("Page 1 of 3");
  $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);

  // Answer a question, ensure next question is available.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/1");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question1->id()}][answer]" => 1,
  ), t('Next'));
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/2");
  $this
    ->assertText("Page 2 of 3");
  $this
    ->assertResponse(200);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/3");
  $this
    ->assertResponse(403);
}