You are here

public function TrueFalseTestCase::testTakeQuestion in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 question_types/truefalse/truefalse.test \TrueFalseTestCase::testTakeQuestion()

File

question_types/truefalse/truefalse.test, line 44
Unit tests for the truefalse Module.

Class

TrueFalseTestCase
Test class for true false questions.

Code

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

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

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

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

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

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

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

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