You are here

public function ShortAnswerTestCase::testGradeAnswerSensitive in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php \Drupal\Tests\quiz_short_answer\Functional\ShortAnswerTestCase::testGradeAnswerSensitive()
  2. 8.5 question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php \Drupal\Tests\quiz_short_answer\Functional\ShortAnswerTestCase::testGradeAnswerSensitive()

Test case sensitive graded questions.

File

question_types/quiz_short_answer/tests/src/Functional/ShortAnswerTestCase.php, line 79
Unit tests for the short_answer Module.

Class

ShortAnswerTestCase
Test class for short answer.

Namespace

Drupal\Tests\quiz_short_answer\Functional

Code

public function testGradeAnswerSensitive() {

  // Login as our privileged user.
  $this
    ->drupalLogin($this->admin);
  $quiz = $this
    ->createQuiz([
    'review_options' => [
      'end' => [
        'score' => 'score',
      ],
    ],
  ]);
  $question = QuizQuestion::create([
    'type' => 'short_answer',
    'short_answer_evaluation' => ShortAnswerQuestion::ANSWER_MATCH,
    'short_answer_correct' => 'the Zero One Infinity rule',
  ]);
  $question
    ->save();
  $this
    ->linkQuestionToQuiz($question, $quiz);

  // Test incorrect.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, [
    "question[{$question->id()}][answer]" => 'the zero one Infinity rule',
  ], t('Finish'));
  $this
    ->assertText('Your score: 0%');

  // Test correct.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, [
    "question[{$question->id()}][answer]" => 'the Zero One Infinity rule',
  ], t('Finish'));
  $this
    ->assertText('Your score: 100%');
}