You are here

function QuizNavigationTestCase::testQuestionNavigationSkipping in Quiz 7.6

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

Test that a user can skip a question.

File

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

Class

QuizNavigationTestCase
Base test class for Quiz questions.

Code

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

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

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

  // Ensure next questions are blocked until skipped.
  $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);

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

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