You are here

public function QuizTakingTestCase::testQuizNoResuming in Quiz 7.5

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

Test the quiz not resuming from database.

File

tests/QuizTakingTestCase.test, line 117

Class

QuizTakingTestCase

Code

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

  // Resuming is default behavior.
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'allow_resume' => 0,
    'takes' => 1,
  ));

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

  // Answer a question. Ensure the question navigation restrictions are
  // maintained.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/2");
  $this
    ->assertResponse(403);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/1");
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node1->nid}][answer]" => 1,
  ), t('Next'));

  // Login again.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertNoText('Resuming');

  // Assert 2nd question is not accessible (indicating the answer to #1 was
  // not saved.)
  $this
    ->drupalGet("node/{$quiz_node->nid}/take/2");
  $this
    ->assertResponse(403);
}