public function ShortAnswerTestCase::testGradeAnswerRegex in Quiz 8.6
Same name and namespace in other branches
- 8.5 question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php \Drupal\Tests\quiz_short_answer\Functional\ShortAnswerTestCase::testGradeAnswerRegex()
- 6.x question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php \Drupal\Tests\quiz_short_answer\Functional\ShortAnswerTestCase::testGradeAnswerRegex()
Test regex graded questions.
File
- question_types/
quiz_short_answer/ tests/ src/ Functional/ ShortAnswerTestCase.php, line 112 - Unit tests for the short_answer Module.
Class
- ShortAnswerTestCase
- Test class for short answer.
Namespace
Drupal\Tests\quiz_short_answer\FunctionalCode
public function testGradeAnswerRegex() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz();
$question = QuizQuestion::create(array(
'type' => 'short_answer',
'short_answer_evaluation' => ShortAnswerQuestion::ANSWER_REGEX,
'short_answer_correct' => '/Zero One Infinity/i',
));
$question
->save();
$this
->linkQuestionToQuiz($question, $quiz);
// Test incorrect.
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, array(
"question[{$question->id()}][answer]" => 'um some rule, I forget',
), t('Finish'));
$this
->assertText('Your score: 0%');
// Test correct.
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, array(
"question[{$question->id()}][answer]" => 'the answer is the zero one infinity rule',
), t('Finish'));
$this
->assertText('Your score: 100%');
}