You are here

public function QuizMultichoiceTestCase::testCreateQuizQuestion in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php \Drupal\Tests\quiz_multichoice\Functional\QuizMultichoiceTestCase::testCreateQuizQuestion()
  2. 6.x question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php \Drupal\Tests\quiz_multichoice\Functional\QuizMultichoiceTestCase::testCreateQuizQuestion()

Create a default MCQ with default settings.

7 calls to QuizMultichoiceTestCase::testCreateQuizQuestion()
QuizMultichoiceTestCase::testAnswerMultiRestore in question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php
Test restoring a multiple choice answer.
QuizMultichoiceTestCase::testAnswerSingleRestore in question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php
Test restoring a single choice answer.
QuizMultichoiceTestCase::testEditQuestionResponse in question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php
Test that the question response can be edited.
QuizMultichoiceTestCase::testMultipleAnswers in question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php
Test multiple answers.
QuizMultichoiceTestCase::testQuestionFeedback in question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php

... See full list

File

question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php, line 21

Class

QuizMultichoiceTestCase
Test multiple choice questions.

Namespace

Drupal\Tests\quiz_multichoice\Functional

Code

public function testCreateQuizQuestion($settings = []) {

  // Set up some alternatives.
  $a = Paragraph::create([
    'type' => 'multichoice',
    'multichoice_correct' => 1,
    'multichoice_answer' => 'Alternative A',
    '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' => 'Alternative B',
    '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();
  $c = Paragraph::create([
    'type' => 'multichoice',
    'multichoice_answer' => 'Alternative C',
    'multichoice_feedback_chosen' => 'You chose C',
    'multichoice_feedback_not_chosen' => 'You did not choose C',
    'multichoice_score_chosen' => -1,
    'multichoice_score_not_chosen' => 0,
  ]);
  $c
    ->save();
  $question = QuizQuestion::create($settings + [
    '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
    ->get('alternatives')
    ->appendItem($c);
  $question
    ->save();
  return $question;
}