You are here

public function QuizNavigationTest::testQuestionNavigationBackwards in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationBackwards()
  2. 8.5 tests/src/Functional/QuizNavigationTest.php \Drupal\Tests\quiz\Functional\QuizNavigationTest::testQuestionNavigationBackwards()

Test preventing backwards navigation of questions.

File

tests/src/Functional/QuizNavigationTest.php, line 174

Class

QuizNavigationTest
Test question navigation.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testQuestionNavigationBackwards() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->createQuiz([
    'backwards_navigation' => 0,
    'allow_skipping' => 0,
    'allow_jumping' => 0,
  ]);

  // 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);

  // 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, [
    "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);
}