public function QuizResultTest::testQuizResultCrud in Quiz 8.6
Same name and namespace in other branches
- 8.5 tests/src/Functional/QuizResultTest.php \Drupal\Tests\quiz\Functional\QuizResultTest::testQuizResultCrud()
- 6.x tests/src/Functional/QuizResultTest.php \Drupal\Tests\quiz\Functional\QuizResultTest::testQuizResultCrud()
Test result CRUD operations.
We have (at least) 3 different tables to clean up from on a Quiz result deletion - the quiz_result, the result answers, and the question type's answer storage. Let's ensure at least that happens.
@todo rework for D8, at least we don't have to clean up question storage because it's attached to QuizResultAnswer.
File
- tests/
src/ Functional/ QuizResultTest.php, line 147
Class
- QuizResultTest
- Test quiz results behavior.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuizResultCrud() {
$this
->drupalLogin($this->admin);
$question1 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
));
$quiz = $this
->linkQuestionToQuiz($question1);
// Submit an answer.
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, array(
"question[{$question1->id()}][answer]" => 1,
), t('Finish'));
$q = Quiz::load(1);
$qq = QuizQuestion::load(1);
$qqr = QuizQuestionRelationship::load(1);
$qr = QuizResult::load(1);
$qra = QuizResultAnswer::load(1);
$this
->assertEquals($qq
->id(), $qqr
->getQuiz()
->id(), 'Question belongs to the relationship.');
$this
->assertEquals($qqr
->getQuiz()
->id(), $q
->id(), 'Relationship belongs to the quiz.');
$this
->assertEquals($qr
->id(), $qra
->getQuizResult()
->id(), 'Answer belongs to the result.');
// Delete the quiz.
$q
->delete();
$q = Quiz::load(1);
$qq = QuizQuestion::load(1);
$qqr = QuizQuestionRelationship::load(1);
$qr = QuizResult::load(1);
$qra = QuizResultAnswer::load(1);
// Check that only the question remains.
$this
->assertEquals($q, NULL);
$this
->assertEquals($qqr, NULL);
$this
->assertNotEquals($qq, NULL);
$this
->assertEquals($qr, NULL);
$this
->assertEquals($qra, NULL);
}