You are here

public function QuizPageTestCase::testPageFeedback in Quiz 8.6

Same name in this branch
  1. 8.6 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.php \QuizPageTestCase::testPageFeedback()
  2. 8.6 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.test \QuizPageTestCase::testPageFeedback()
Same name and namespace in other branches
  1. 8.5 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.php \QuizPageTestCase::testPageFeedback()
  2. 8.5 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.test \QuizPageTestCase::testPageFeedback()
  3. 7.5 question_types/quiz_page/QuizPageTestCase.test \QuizPageTestCase::testPageFeedback()

File

question_types/quiz_page/tests/src/Functional/QuizPageTestCase.php, line 150

Class

QuizPageTestCase
Test quiz page behavior.

Code

public function testPageFeedback() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->createQuiz(array(
    'review_options' => array(
      'question' => array(
        'question_feedback' => 'question_feedback',
      ),
    ),
  ));

  // Create the questions.
  $question_node1 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
    'body' => 'TF 1 body text',
    'feedback' => 'This is the feedback for question 1.',
  ));
  $this
    ->linkQuestionToQuiz($question_node1, $quiz_node);

  // QNR ID 1
  $question_node2 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
    'body' => 'TF 2 body text',
    'feedback' => 'This is the feedback for question 2.',
  ));
  $this
    ->linkQuestionToQuiz($question_node2, $quiz_node);

  // QNR ID 2
  $question_node3 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
    'body' => 'TF 3 body text',
    'feedback' => 'This is the feedback for question 3.',
  ));
  $this
    ->linkQuestionToQuiz($question_node3, $quiz_node);

  // QNR ID 3
  //
  // Create the page.
  $page_node1 = $this
    ->createQuestion(array(
    'type' => 'page',
    'body' => 'PG 1 body text',
  ));
  $this
    ->linkQuestionToQuiz($page_node1, $quiz_node);

  // QNR ID 4
  // Go to the manage questions form.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/questions");
  $post = array(
    // Make the questions have parents.
    "question_list[{$question_node1->getRevisionId()}][qqr_pid]" => 4,
    "question_list[{$question_node2->getRevisionId()}][qqr_pid]" => 4,
    // Mirror what JS would have done by adjusting the weights.
    "question_list[{$page_node1->getRevisionId()}][weight]" => 1,
    "question_list[{$question_node1->getRevisionId()}][weight]" => 2,
    "question_list[{$question_node2->getRevisionId()}][weight]" => 3,
    "question_list[{$question_node3->getRevisionId()}][weight]" => 4,
  );
  $this
    ->drupalPostForm(NULL, $post, t('Submit'));
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question_node1->id()}][answer]" => 1,
    "question[{$question_node2->id()}][answer]" => 1,
  ), t('Next'));
  $this
    ->assertText('This is the feedback for question 1.');
  $this
    ->assertText('This is the feedback for question 2.');
  $this
    ->assertNoText('This is the feedback for question 3.');
}