public function QuizAccessTest::testQuizTakerAnswerScore in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizAccessTest.php \Drupal\Tests\quiz\Functional\QuizAccessTest::testQuizTakerAnswerScore()
- 8.5 tests/src/Functional/QuizAccessTest.php \Drupal\Tests\quiz\Functional\QuizAccessTest::testQuizTakerAnswerScore()
Test quiz takers being able to grade their own results.
File
- tests/
src/ Functional/ QuizAccessTest.php, line 57 - Unit tests for the quiz question Module.
Class
- QuizAccessTest
- Test aspects of quiz access and permissions.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuizTakerAnswerScore() {
$question = $this
->createQuestion([
'type' => 'short_answer',
'title' => 'SA 1 title',
'short_answer_evaluation' => ShortAnswerQuestion::ANSWER_MANUAL,
'short_answer_correct' => 'blue',
'body' => 'SA 1 body text',
]);
$quiz = $this
->linkQuestionToQuiz($question);
$grader = $this
->drupalCreateUser([
'update own quiz_result',
]);
$other = $this
->drupalCreateUser([
'update own quiz_result',
]);
$this
->drupalLogin($grader);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, [
"question[{$question->id()}][answer]" => 'bluish',
], t('Finish'));
// Make sure others cannot edit.
$this
->drupalLogin($other);
// Check unevaluated quiz results view.
$this
->drupalGet("user/{$other->id()}/quiz-result-score");
$this
->assertNoLink(t('Score'));
$this
->drupalGet("quiz/{$quiz->id()}/result/1/edit");
$this
->assertResponse(403);
// Score.
$this
->drupalLogin($grader);
// Check unevaluated quiz results view.
$this
->drupalGet("user/{$grader->id()}/quiz-result-score");
$this
->clickLink(t('Score'));
$this
->drupalPostForm(NULL, [
"question[{$question->id()}][score]" => 5,
], t('Save score'));
}