You are here

function MultichoiceTestCase::testReorderingUI in Quiz 7.6

Same name and namespace in other branches
  1. 7.5 question_types/multichoice/multichoice.test \MultichoiceTestCase::testReorderingUI()

Test the reordering UI.

File

question_types/multichoice/multichoice.test, line 187
Test suite for choice Questions type module.

Class

MultichoiceTestCase
Test class for multichoice questions.

Code

function testReorderingUI() {
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet('node/add/multichoice');
  $question_node = $this
    ->testCreateQuizQuestion();
  $quiz_node = $this
    ->linkQuestionToQuiz($question_node);
  $this
    ->drupalGet("node/{$question_node->nid}/edit");
  $this
    ->drupalPost(NULL, array(
    'alternatives[0][answer][value]' => 'Correct answer 1',
    'alternatives[0][weight]' => 1,
    'alternatives[1][answer][value]' => 'Incorrect answer 2',
    'alternatives[1][weight]' => 2,
    'alternatives[2][answer][value]' => 'Incorrect answer 3',
    'alternatives[2][weight]' => 3,
  ), t('Save'));
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $a = strpos($this->content, 'Correct answer 1');
  $b = strpos($this->content, 'Incorrect answer 2');
  $c = strpos($this->content, 'Incorrect answer 3');
  $this
    ->assertTrue($a < $b, 'A comes before B');
  $this
    ->assertTrue($b < $c, 'B comes before C');
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer][user_answer]" => 1,
  ), t('Finish'));
  $this
    ->assertText('You got 1 of 1 possible points.');
  $this
    ->assertText('Your score: 100%');

  // Now screw them up.
  $this
    ->drupalGet("node/{$question_node->nid}/edit");
  $this
    ->drupalPost(NULL, array(
    'alternatives[0][weight]' => 3,
    'alternatives[1][weight]' => 2,
    'alternatives[2][weight]' => 1,
  ), t('Save'));
  $question_node = node_load($question_node->nid);
  $this
    ->drupalGet("node/{$quiz_node->nid}/quiz/questions");
  $this
    ->drupalPost(NULL, array(
    "revision[{$question_node->nid}-{$question_node->vid}]" => TRUE,
  ), t('Submit'));

  // Take the quiz again.
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $a = strpos($this->content, 'Correct answer 1');
  $b = strpos($this->content, 'Incorrect answer 2');
  $c = strpos($this->content, 'Incorrect answer 3');
  $this
    ->assertTrue($a > $b, 'A comes after B');
  $this
    ->assertTrue($b > $c, 'B comes after C');

  // Check that the correct answer did not change even with the weight
  // adjustment.
  $this
    ->drupalPost(NULL, array(
    "question[{$question_node->nid}][answer][user_answer]" => 4,
  ), t('Finish'));
  $this
    ->assertText('You got 1 of 1 possible points.');
  $this
    ->assertText('Your score: 100%');
}