public function QuizTakingTest::testQuizMaxAttempts in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizTakingTest.php \Drupal\Tests\quiz\Functional\QuizTakingTest::testQuizMaxAttempts()
- 8.5 tests/src/Functional/QuizTakingTest.php \Drupal\Tests\quiz\Functional\QuizTakingTest::testQuizMaxAttempts()
File
- tests/
src/ Functional/ QuizTakingTest.php, line 198
Class
- QuizTakingTest
- Test quiz taking behavior.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuizMaxAttempts() {
$quiz_node = $this
->createQuiz([
'takes' => 2,
]);
$question1 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
]);
$this
->linkQuestionToQuiz($question1, $quiz_node);
$question2 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
]);
$this
->linkQuestionToQuiz($question2, $quiz_node);
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 0,
], t('Next'));
$this
->drupalPostForm(NULL, [
"question[{$question2->id()}][answer]" => 0,
], t('Finish'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->id()}");
$this
->assertText('You can only take this Quiz 2 times. You have taken it 1 time.');
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 0,
], t('Next'));
// Make sure we can get back.
$this
->drupalGet("quiz/{$quiz_node->id()}");
$this
->assertNoText('You can only take this Quiz 2 times. You have taken it 1 time.');
$this
->drupalGet("quiz/{$quiz_node->id()}/take/2");
$this
->drupalPostForm(NULL, [
"question[{$question2->id()}][answer]" => 0,
], t('Finish'));
// No more attempts.
$this
->drupalGet("quiz/{$quiz_node->id()}");
$this
->assertText('You have already taken this Quiz 2 times. You may not take it again.');
}