You are here

public function QuizTrueFalseTestCase::testTakeQuestion in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 question_types/quiz_truefalse/tests/src/Functional/QuizTrueFalseTestCase.php \Drupal\Tests\quiz_truefalse\Functional\QuizTrueFalseTestCase::testTakeQuestion()
  2. 6.x question_types/quiz_truefalse/tests/src/Functional/QuizTrueFalseTestCase.php \Drupal\Tests\quiz_truefalse\Functional\QuizTrueFalseTestCase::testTakeQuestion()

File

question_types/quiz_truefalse/tests/src/Functional/QuizTrueFalseTestCase.php, line 40

Class

QuizTrueFalseTestCase
Test class for true false questions.

Namespace

Drupal\Tests\quiz_truefalse\Functional

Code

public function testTakeQuestion() {
  $question = $this
    ->testCreateQuizQuestion();

  // Link the question.
  $quiz = $this
    ->linkQuestionToQuiz($question);

  // Test that question appears in lists.
  $this
    ->drupalGet("quiz/{$quiz->id()}/questions");
  $this
    ->assertText('TF 1 title');

  // Login as non-admin.
  $this
    ->drupalLogin($this->user);

  // Take the quiz.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->assertNoText('TF 1 title');
  $this
    ->assertText('TF 1 body text');
  $this
    ->assertText('True');
  $this
    ->assertText('False');

  // Test validation.
  $this
    ->drupalPostForm(NULL, array(), t('Finish'));
  $this
    ->assertText('You must provide an answer.');

  // Test correct question.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question->id()}][answer]" => 1,
  ), t('Finish'));
  $this
    ->assertText('You got 1 of 1 possible points.');

  // Test incorrect question.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question->id()}][answer]" => 0,
  ), t('Finish'));
  $this
    ->assertText('You got 0 of 1 possible points.');
}