public function QuizFeedbackTest::testFeedbackTimes in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizFeedbackTest.php \Drupal\Tests\quiz\Functional\QuizFeedbackTest::testFeedbackTimes()
- 8.5 tests/src/Functional/QuizFeedbackTest.php \Drupal\Tests\quiz\Functional\QuizFeedbackTest::testFeedbackTimes()
Test custom feedback types.
File
- tests/
src/ Functional/ QuizFeedbackTest.php, line 238
Class
- QuizFeedbackTest
- Test quiz feedback.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testFeedbackTimes() {
$this
->drupalLogin($this->admin);
$component = [
'expression' => [
'id' => 'rules_and',
'conditions' => [
[
'id' => 'rules_condition',
'uuid' => 'ca2a6b2f-3b17-449e-b913-d64b52c17203',
'weight' => 2,
'context_values' => [
'operation' => '==',
'value' => '2',
],
'context_mapping' => [
'data' => 'quiz_result.attempt.value',
],
'condition_id' => 'rules_data_comparison',
'negate' => 0,
],
],
],
'context_definitions' => [
'quiz_result' => [
'type' => 'entity:quiz_result',
'label' => 'Quiz result',
'description' => 'Quiz result to evaluate feedback',
],
],
];
QuizFeedbackType::create([
'label' => 'After two attempts',
'id' => 'after2attempts',
'component' => $component,
])
->save();
// Feedback but, only after second attempt (rule).
$quiz = $this
->createQuiz([
'review_options' => [
'after2attempts' => [
'solution' => 'solution',
],
],
]);
// Set up a Quiz with one question that has a body and a summary.
$question1 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
]);
$this
->linkQuestionToQuiz($question1, $quiz);
// Test no feedback.
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 1,
], t('Finish'));
$this
->assertNoText('Correct answer');
// Take again.
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 1,
], t('Finish'));
$this
->assertText('Correct answer');
}