You are here

function MatchingTestCase::testTakeQuestion in Quiz 7.6

Same name and namespace in other branches
  1. 7.5 question_types/matching/matching.test \MatchingTestCase::testTakeQuestion()

File

question_types/matching/matching.test, line 55
Unit tests for the matching Module.

Class

MatchingTestCase
Test class for matching questions.

Code

function testTakeQuestion() {
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'review_options' => array(
      'end' => drupal_map_assoc(array(
        'answer_feedback',
        'score',
      )),
    ),
  ));
  $question_node = $this
    ->testCreateQuizQuestion();

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

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

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

  // Take the quiz.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertNoText('MA 1 title');
  $this
    ->assertText('MA 1 body text');
  $this
    ->assertText('MAQ 1');
  $this
    ->assertText('MAQ 2');
  $this
    ->assertText('MAQ 3');
  $this
    ->assertText('MAA 1');
  $this
    ->assertText('MAA 2');
  $this
    ->assertText('MAA 3');

  // Test validation.
  $this
    ->drupalPost(NULL, array(), t('Finish'));
  $this
    ->assertText('You need to match at least one of the items.');

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

  // Test incorrect question.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->drupalPost(NULL, array(
    "question[2][answer][1]" => 1,
    "question[2][answer][2]" => 2,
    "question[2][answer][3]" => 2,
  ), t('Finish'));
  $this
    ->assertText('MAF 1');
  $this
    ->assertText('MAF 2');

  // The behavior right now is that all the feedback shows.
  $this
    ->assertText('MAF 3');
  $this
    ->assertText('You got 2 of 3 possible points.');
}