You are here

public function QuizFeedbackTest::testQuestionFeedback in Quiz 8.5

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

Test general Quiz question feedback.

File

tests/src/Functional/QuizFeedbackTest.php, line 88

Class

QuizFeedbackTest
Test quiz feedback.

Namespace

Drupal\Tests\quiz\Functional

Code

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

  // Turn on question feedback at the end.
  $quiz = $this
    ->createQuiz(array(
    'review_options' => array(
      'end' => array(
        'question_feedback' => 'question_feedback',
      ),
    ),
  ));

  // Add 2 questions with general question feedback.
  $question1 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
    'feedback' => 'Feedback for TF test.',
  ));
  $this
    ->linkQuestionToQuiz($question1, $quiz);
  $question2 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
    'feedback' => 'Feedback for TF test.',
  ));
  $this
    ->linkQuestionToQuiz($question2, $quiz);

  // Test.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question1->id()}][answer]" => 1,
  ), t('Next'));
  $this
    ->assertNoText('Feedback for TF test.');
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question2->id()}][answer]" => 1,
  ), t('Finish'));
  $this
    ->assertText('Feedback for TF test.');
}