public function QuizMultichoiceTestCase::testMultipleAnswers in Quiz 8.5
Same name and namespace in other branches
- 8.6 question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php \Drupal\Tests\quiz_multichoice\Functional\QuizMultichoiceTestCase::testMultipleAnswers()
- 6.x question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php \Drupal\Tests\quiz_multichoice\Functional\QuizMultichoiceTestCase::testMultipleAnswers()
Test multiple answers.
File
- question_types/
quiz_multichoice/ tests/ src/ Functional/ QuizMultichoiceTestCase.php, line 98
Class
- QuizMultichoiceTestCase
- Test multiple choice questions.
Namespace
Drupal\Tests\quiz_multichoice\FunctionalCode
public function testMultipleAnswers() {
$this
->drupalLogin($this->admin);
$question = $this
->testCreateQuizQuestion(array(
'choice_multi' => 1,
));
$quiz = $this
->linkQuestionToQuiz($question);
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, array(
"question[{$question->id()}][answer][user_answer][1]" => 1,
"question[{$question->id()}][answer][user_answer][3]" => 3,
), t('Finish'));
// 0 of 1, because user picked a correct answer and an incorrect answer.
$this
->assertText('You got 0 of 1 possible points.');
$this
->assertText('Your score: 0%');
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, array(
"question[{$question->id()}][answer][user_answer][1]" => 1,
), t('Finish'));
// 1 of 1, because user picked a correct answer and not an incorrect answer.
$this
->assertText('You got 1 of 1 possible points.');
$this
->assertText('Your score: 100%');
}