public function ShortAnswerTestCase::testGradeAnswerManualFeedback in Quiz 6.x
Same name and namespace in other branches
- 8.6 question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php \Drupal\Tests\quiz_short_answer\Functional\ShortAnswerTestCase::testGradeAnswerManualFeedback()
- 8.5 question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php \Drupal\Tests\quiz_short_answer\Functional\ShortAnswerTestCase::testGradeAnswerManualFeedback()
Test manually graded questions.
Note: we use two questions here to make sure the grading form is handled correctly.
File
- question_types/
quiz_short_answer/ tests/ src/ Functional/ ShortAnswerTestCase.php, line 148 - Unit tests for the short_answer Module.
Class
- ShortAnswerTestCase
- Test class for short answer.
Namespace
Drupal\Tests\quiz_short_answer\FunctionalCode
public function testGradeAnswerManualFeedback() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz();
$question1 = QuizQuestion::create([
'type' => 'short_answer',
'short_answer_evaluation' => ShortAnswerQuestion::ANSWER_MANUAL,
'short_answer_correct' => 'the Zero One Infinity rule',
]);
$question1
->save();
$this
->linkQuestionToQuiz($question1, $quiz);
$question2 = QuizQuestion::create([
'type' => 'short_answer',
'short_answer_evaluation' => ShortAnswerQuestion::ANSWER_MANUAL,
'short_answer_correct' => 'The number two is ridiculous and cannot exist',
]);
$question2
->save();
$this
->linkQuestionToQuiz($question2, $quiz);
// Test correct.
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 'the answer is the zero one infinity rule',
], t('Next'));
$this
->drupalPostForm(NULL, [
"question[{$question2->id()}][answer]" => 'the number two really is ridiculous',
], t('Finish'));
$this
->assertText('Your score: 0%');
// Strange behavior - extra spaces in HTML.
//$this->assertText('Score ? of 10');
$this
->assertText('This answer has not yet been scored.');
$this
->assertNoFieldByName('question[1][score]');
$this
->assertNoFieldByName('question[2][score]');
$this
->assertNoFieldByName('question[1][answer_feedback][value]');
$this
->assertNoFieldByName('question[2][answer_feedback][value]');
$this
->assertNoRaw(t('Save score'));
$url_of_result = $this
->getUrl();
// Test grading the question.
$this
->drupalLogin($this->admin);
$this
->drupalGet('admin/quiz/reports/unevaluated');
$this
->clickLink(t('Score'));
$this
->assertFieldByName('question[1][score]');
$this
->assertFieldByName('question[2][score]');
$this
->drupalPostForm(NULL, [
"question[1][score]" => 2,
"question[2][score]" => 3,
"question[1][answer_feedback][value]" => 'Feedback for answer 1.',
"question[2][answer_feedback][value]" => 'Feedback for answer 2.',
"question[1][answer_feedback][format]" => 'basic_html',
"question[2][answer_feedback][format]" => 'basic_html',
], t('Save score'));
$this
->assertText('The scoring data you provided has been saved.');
// Test the score is visible to the user.
$this
->drupalLogin($this->user);
$this
->drupalGet($url_of_result);
$this
->assertText('You got 5 of 10 possible points.');
$this
->assertText('Your score: 50%');
// Strange behavior - extra spaces in HTML.
//$this->assertText('Score 2 of 5');
//$this->assertText('Score 3 of 5');
$this
->assertText('Feedback for answer 1.');
$this
->assertText('Feedback for answer 2.');
}