You are here

public function QuizResultTest::testQuizResultAccess in Quiz 6.x

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

Test access to results.

File

tests/src/Functional/QuizResultTest.php, line 196

Class

QuizResultTest
Test quiz results behavior.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testQuizResultAccess() {
  $this
    ->drupalLogin($this->admin);
  $question1 = $this
    ->createQuestion([
    'type' => 'truefalse',
    'truefalse_correct' => 1,
  ]);
  $quiz_node = $this
    ->linkQuestionToQuiz($question1);

  // Submit an answer.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");
  $this
    ->drupalPostForm(NULL, [
    "question[{$question1->id()}][answer]" => 1,
  ], t('Finish'));
  $resultsUrl = $this
    ->getUrl();
  $this
    ->drupalGet($resultsUrl);
  $this
    ->assertResponse(200, t('User can view own result'));
  $this
    ->drupalLogout();
  $this
    ->drupalGet($resultsUrl);
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}