You are here

public function QuizTakingTestCase::testQuizResuming in Quiz 7.5

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

Test the quiz resuming from database.

File

tests/QuizTakingTestCase.test, line 78

Class

QuizTakingTestCase

Code

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

  // Resuming is default behavior.
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'allow_resume' => 1,
    '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
    ->assertText('Resuming');

  // We should have been advanced to the next question.
  $this
    ->assertUrl("node/{$quiz_node->nid}/take/2");

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