You are here

public function QuizResultTest::testQuizResultAnswerExport in Quiz 6.x

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

Test our wildcard answer exporter.

File

tests/src/Functional/QuizResultTest.php, line 224

Class

QuizResultTest
Test quiz results behavior.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testQuizResultAnswerExport() {

  // Set up some alternatives.
  $a = Paragraph::create([
    'type' => 'multichoice',
    'multichoice_correct' => 1,
    'multichoice_answer' => 'This is the A answer',
    'multichoice_feedback_chosen' => 'You chose A',
    'multichoice_feedback_not_chosen' => 'You did not choose A',
    'multichoice_score_chosen' => 1,
    'multichoice_score_not_chosen' => 0,
  ]);
  $a
    ->save();
  $b = Paragraph::create([
    'type' => 'multichoice',
    'multichoice_answer' => 'This is the B answer',
    'multichoice_feedback_chosen' => 'You chose B',
    'multichoice_feedback_not_chosen' => 'You did not choose B',
    'multichoice_score_chosen' => -1,
    'multichoice_score_not_chosen' => 0,
  ]);
  $b
    ->save();
  $question = QuizQuestion::create([
    'title' => 'MCQ 1 Title',
    'type' => 'multichoice',
    'choice_multi' => 0,
    'choice_random' => 0,
    'choice_boolean' => 0,
    'body' => 'MCQ 1 body text',
  ]);
  $question
    ->get('alternatives')
    ->appendItem($a);
  $question
    ->get('alternatives')
    ->appendItem($b);
  $question
    ->save();
  $quiz = $this
    ->linkQuestionToQuiz($question);
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, [
    "question[{$question->id()}][answer][user_answer]" => 1,
  ], t('Finish'));

  // Verify the user's answer appears on our modified report.
  $this
    ->drupalGet("quiz/{$quiz->id()}/quiz-result-export-test");
  $this
    ->assertText('1. MCQ 1 Title');
  $this
    ->assertText('This is the A answer');
  $this
    ->assertNoText('This is the B answer');
}