You are here

public function QuizNavigationTestCase::testQuestionNavigationBackwards in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 tests/QuizNavigationTestCase.test \QuizNavigationTestCase::testQuestionNavigationBackwards()

Test preventing backwards navigation of questions.

File

tests/QuizNavigationTestCase.test, line 151
Unit tests for the quiz question Module.

Class

QuizNavigationTestCase
Base test class for Quiz questions.

Code

public function testQuestionNavigationBackwards() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'backwards_navigation' => 0,
    'allow_skipping' => 0,
    'allow_jumping' => 0,
  ));

  // 3 questions.
  $question_node1 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question_node1, $quiz_node);
  $question_node2 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question_node2, $quiz_node);
  $question_node3 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question_node3, $quiz_node);

  // Testing basic navigation.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/1");
  $this
    ->assertResponse(200);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/2");
  $this
    ->assertResponse(403);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/3");
  $this
    ->assertResponse(403);

  // Answer a question, ensure next question is available. Ensure previous
  // question is not.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/1");
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node1->nid}][answer]" => 1,
  ), t('Next'));
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/2");
  $this
    ->assertResponse(200);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/1");
  $this
    ->assertResponse(403);
}