You are here

QuizQuestionNumberingTest.php in Quiz 8.5

File

tests/src/Functional/QuizQuestionNumberingTest.php
View source
<?php

namespace Drupal\Tests\quiz\Functional;


/**
 * Test question numbering.
 *
 * @group Quiz
 */
class QuizQuestionNumberingTest extends QuizTestBase {
  public static $modules = array(
    'quiz_truefalse',
    'quiz_directions',
    'quiz_page',
  );
  public function testQuestionNumbering() {
    $this
      ->drupalLogin($this->admin);

    // Create Quiz with review of score.
    $quiz = $this
      ->createQuiz();

    // Create the questions.
    $question1 = $this
      ->createQuestion(array(
      'type' => 'truefalse',
      'truefalse_correct' => 1,
      'body' => 'TF 1 body text',
    ));
    $this
      ->linkQuestionToQuiz($question1, $quiz);
    $question2 = $this
      ->createQuestion(array(
      'type' => 'truefalse',
      'truefalse_correct' => 1,
      'body' => 'TF 2 body text',
    ));
    $this
      ->linkQuestionToQuiz($question2, $quiz);
    $question3 = $this
      ->createQuestion(array(
      'type' => 'directions',
      'body' => 'QD 3 body text',
    ));
    $this
      ->linkQuestionToQuiz($question3, $quiz);

    // Create the page.
    $page1 = $this
      ->createQuestion(array(
      'type' => 'page',
      'body' => 'PG 1 body text',
    ));
    $this
      ->linkQuestionToQuiz($page1, $quiz);

    // Go to the manage questions form.
    $this
      ->drupalGet("quiz/{$quiz->id()}/questions");
    $post = array(
      // Make the questions have parents.
      "question_list[{$question1->getRevisionId()}][qqr_pid]" => 4,
      "question_list[{$question2->getRevisionId()}][qqr_pid]" => 4,
      "question_list[{$question3->getRevisionId()}][qqr_pid]" => 4,
      // Mirror what JS would have done by adjusting the weights.
      "question_list[{$page1->getRevisionId()}][weight]" => 2,
      "question_list[{$question1->getRevisionId()}][weight]" => 3,
      "question_list[{$question2->getRevisionId()}][weight]" => 4,
      "question_list[{$question3->getRevisionId()}][weight]" => 5,
    );
    $this
      ->drupalPostForm(NULL, $post, t('Submit'));
    $this
      ->drupalLogin($this->user);
    $this
      ->drupalGet("quiz/{$quiz->id()}/take");
    $this
      ->assertText("PG 1 body text");
    $this
      ->assertText("Question 1");
    $this
      ->assertText("TF 1 body text");
    $this
      ->assertText("Question 2");
    $this
      ->assertText("TF 2 body text");

    // There we only 2 real questions. Verify another question is present
    // but we stopped numbering at 2.
    $this
      ->assertNoText("Question 3");
    $this
      ->assertText("QD 3 body text");
  }

}

Classes

Namesort descending Description
QuizQuestionNumberingTest Test question numbering.