You are here

public function QuizTakingTest::testViewQuestionsOutsideQuiz in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 tests/src/Functional/QuizTakingTest.php \Drupal\Tests\quiz\Functional\QuizTakingTest::testViewQuestionsOutsideQuiz()
  2. 6.x tests/src/Functional/QuizTakingTest.php \Drupal\Tests\quiz\Functional\QuizTakingTest::testViewQuestionsOutsideQuiz()

Make sure questions cannot be viewed outside of quizzes.

File

tests/src/Functional/QuizTakingTest.php, line 71

Class

QuizTakingTest
Test quiz taking behavior.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testViewQuestionsOutsideQuiz() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->createQuiz();
  $question1 = $this
    ->createQuestion(array(
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ));
  $this
    ->linkQuestionToQuiz($question1, $quiz_node);
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz-question/{$question1->id()}");
  $this
    ->assertResponse(403);
  $user_with_privs = $this
    ->drupalCreateUser(array(
    'view quiz_question',
    'access quiz',
  ));
  $this
    ->drupalLogin($user_with_privs);
  $this
    ->drupalGet("quiz-question/{$question1->id()}");
  $this
    ->assertResponse(200);
}