public function QuizNavigationTest::testQuestionNavigationJumping in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationJumping()
- 8.5 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationJumping()
Test that all questions are available when quiz jumping is on.
File
- tests/
src/ Functional/ QuizNavigationTest.php, line 64
Class
- QuizNavigationTest
- Test question navigation.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuestionNavigationJumping() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->createQuiz([
'allow_jumping' => 1,
]);
// 5 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);
$question4 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
]);
$this
->linkQuestionToQuiz($question4, $quiz_node);
$question5 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
]);
$this
->linkQuestionToQuiz($question5, $quiz_node);
// Testing jumpable 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(200);
$this
->drupalGet("quiz/{$quiz_node->id()}/take/3");
$this
->assertResponse(200);
// We should have a selectbox right now.
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->assertFieldById('edit-question-number', NULL);
// Check that the "first" pager link does not appear.
$this
->assertNoLinkByHref("quiz/{$quiz_node->id()}/take/1");
// Test the switch between select/pager.
$config = \Drupal::configFactory()
->getEditable('quiz.settings');
$config
->set('pager_start', 5);
// One on each side.
$config
->set('pager_siblings', 2);
$config
->save();
$this
->drupalGet("quiz/{$quiz_node->id()}/take/3");
$this
->assertNoFieldById('edit-question-number');
$this
->assertNoLink('1');
$this
->assertLinkByHref("quiz/{$quiz_node->id()}/take/2");
$this
->assertNoLinkByHref("quiz/{$quiz_node->id()}/take/3");
$this
->assertLinkByHref("quiz/{$quiz_node->id()}/take/4");
$this
->assertNoLink('5');
}