You are here

public function QuizTakingTest::testAnswerOnOldQuizRevisioning in Quiz 8.5

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

Make sure a user can answer or skip an old question's revision.

File

tests/src/Functional/QuizTakingTest.php, line 240

Class

QuizTakingTest
Test quiz taking behavior.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testAnswerOnOldQuizRevisioning() {
  $this
    ->drupalLogin($this->admin);
  $question1 = $this
    ->createQuestion(array(
    'title' => 'Q 1',
    'body' => 'Q 1',
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ));
  $quiz_node = $this
    ->linkQuestionToQuiz($question1);
  $question2 = $this
    ->createQuestion(array(
    'title' => 'Q 2',
    'body' => 'Q 2',
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question2, $quiz_node);
  $question1->revision = TRUE;
  $question1
    ->save();
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");

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

  // Submit the question.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take/1");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question1->id()}][answer]" => 1,
  ), t('Next'));
}