You are here

public function QuizAccessTest::testQuizOwnerResultEdit in Quiz 6.x

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

Test quiz authors being able to score results for own quiz.

File

tests/src/Functional/QuizAccessTest.php, line 24
Unit tests for the quiz question Module.

Class

QuizAccessTest
Test aspects of quiz access and permissions.

Namespace

Drupal\Tests\quiz\Functional

Code

public function testQuizOwnerResultEdit() {
  $grader = $this
    ->drupalCreateUser([
    'score own quiz',
  ]);
  $question = $this
    ->createQuestion([
    'type' => 'short_answer',
    'title' => 'SA 1 title',
    'short_answer_evaluation' => ShortAnswerQuestion::ANSWER_MANUAL,
    'short_answer_correct' => 'blue',
    'body' => 'SA 1 body text',
  ]);
  $quiz = $this
    ->createQuiz([
    'uid' => $grader
      ->id(),
  ]);
  $this
    ->linkQuestionToQuiz($question, $quiz);
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, [
    "question[{$question->id()}][answer]" => 'bluish',
  ], t('Finish'));

  // Score.
  $this
    ->drupalLogin($grader);

  // Check unevaluated quiz results view.
  $this
    ->drupalGet("user/{$grader->id()}/quiz-score");
  $this
    ->clickLink(t('Score'));
  $this
    ->drupalPostForm(NULL, [
    "question[{$question->id()}][score]" => 5,
  ], t('Save score'));
}