QuizResumeTest.php in Quiz 6.x
File
tests/src/Functional/QuizResumeTest.php
View source
<?php
namespace Drupal\Tests\quiz\Functional;
class QuizResumeTest extends QuizTestBase {
protected static $modules = [
'quiz_truefalse',
];
public function testQuizResuming() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->createQuiz([
'allow_resume' => 1,
'takes' => 1,
]);
$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/2");
$this
->assertResponse(403);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 1,
], t('Next'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->assertText('Resuming');
$this
->assertUrl("quiz/{$quiz_node->id()}/take/2");
$this
->drupalGet("quiz/{$quiz_node->id()}/take/2");
$this
->assertResponse(200);
}
public function testQuizNoResuming() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->createQuiz([
'allow_resume' => 0,
'takes' => 1,
]);
$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/2");
$this
->assertResponse(403);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->drupalPostForm(NULL, [
"question[{$question1->id()}][answer]" => 1,
], t('Next'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->assertNoText('Resuming');
$this
->drupalGet("quiz/{$quiz_node->id()}/take/2");
$this
->assertResponse(403);
}
}