You are here

public function QuizResumeTest::testQuizResuming in Quiz 8.5

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

Test the quiz resuming from database.

File

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

Class

QuizResumeTest
Test quiz resume functionality.

Namespace

Drupal\Tests\quiz\Functional

Code

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

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

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

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

  // Login again.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");
  $this
    ->assertText('Resuming');

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

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