public function QuizNavigationTest::testQuestionNavigationBackwards in Quiz 8.6
Same name and namespace in other branches
- 8.5 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationBackwards()
- 6.x tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationBackwards()
Test preventing backwards navigation of questions.
File
- tests/
src/ Functional/ QuizNavigationTest.php, line 141
Class
- QuizNavigationTest
- Test question navigation.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuestionNavigationBackwards() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->createQuiz(array(
'backwards_navigation' => 0,
'allow_skipping' => 0,
'allow_jumping' => 0,
));
// 3 questions.
$question1 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
));
$this
->linkQuestionToQuiz($question1, $quiz_node);
$question2 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
));
$this
->linkQuestionToQuiz($question2, $quiz_node);
$question3 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
));
$this
->linkQuestionToQuiz($question3, $quiz_node);
// Testing basic navigation.
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->assertResponse(200);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/2");
$this
->assertResponse(403);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/3");
$this
->assertResponse(403);
// Answer a question, ensure next question is available. Ensure previous
// question is not.
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->drupalPostForm(NULL, array(
"question[{$question1->id()}][answer]" => 1,
), t('Next'));
$this
->drupalGet("quiz/{$quiz_node->id()}/take/2");
$this
->assertResponse(200);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->assertResponse(403);
}