public function QuizNavigationTest::testQuestionNavigationSkipping in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationSkipping()
- 8.5 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationSkipping()
Test that a user can skip a question.
File
- tests/
src/ Functional/ QuizNavigationTest.php, line 129
Class
- QuizNavigationTest
- Test question navigation.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuestionNavigationSkipping() {
$this
->drupalLogin($this->admin);
// Default behavior, anyway.
$quiz_node = $this
->createQuiz([
'allow_skipping' => 1,
]);
// 3 questions.
$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);
$question3 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
]);
$this
->linkQuestionToQuiz($question3, $quiz_node);
// Ensure next questions are blocked until skipped.
$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);
// Leave a question blank.
$this
->drupalGet("quiz/{$quiz_node->id()}/take/1");
$this
->drupalPostForm(NULL, [], t('Leave blank'));
// Now question 2 is accessible.
$this
->drupalGet("quiz/{$quiz_node->id()}/take/2");
$this
->assertResponse(200);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/3");
$this
->assertResponse(403);
}