You are here

public function QuizFeedbackTest::testQuestionFeedback in Quiz 6.x

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

Test general Quiz question feedback.

File

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

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([
    'review_options' => [
      'end' => [
        'question_feedback' => 'question_feedback',
      ],
    ],
  ]);

  // Add 2 questions with general question feedback.
  $question1 = $this
    ->createQuestion([
    'type' => 'truefalse',
    'truefalse_correct' => 1,
    'feedback' => 'Feedback for TF test.',
  ]);
  $this
    ->linkQuestionToQuiz($question1, $quiz);
  $question2 = $this
    ->createQuestion([
    '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, [
    "question[{$question1->id()}][answer]" => 1,
  ], t('Next'));
  $this
    ->assertNoText('Feedback for TF test.');
  $this
    ->drupalPostForm(NULL, [
    "question[{$question2->id()}][answer]" => 1,
  ], t('Finish'));
  $this
    ->assertText('Feedback for TF test.');
}