You are here

public function QuizRandomTestCase::testRandomOrder in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 tests/QuizRandomTestCase.test \QuizRandomTestCase::testRandomOrder()

Test random order of questions.

File

tests/QuizRandomTestCase.test, line 29

Class

QuizRandomTestCase
Tests for random questions.

Code

public function testRandomOrder() {
  $this
    ->drupalLogin($this->admin);
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'randomization' => 1,
  ));
  $question_node1 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'TF 1 body text',
        ),
      ),
    ),
  ));
  $question_node2 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'TF 2 body text',
        ),
      ),
    ),
  ));
  $question_node3 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'TF 3 body text',
        ),
      ),
    ),
  ));
  $question_node4 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'TF 4 body text',
        ),
      ),
    ),
  ));
  $question_node5 = $this
    ->drupalCreateNode(array(
    'type' => 'truefalse',
    'correct_answer' => 1,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'TF 5 body text',
        ),
      ),
    ),
  ));
  $this
    ->linkQuestionToQuiz($question_node1, $quiz_node);
  $this
    ->linkQuestionToQuiz($question_node2, $quiz_node);
  $this
    ->linkQuestionToQuiz($question_node3, $quiz_node);
  $this
    ->linkQuestionToQuiz($question_node4, $quiz_node);
  $this
    ->linkQuestionToQuiz($question_node5, $quiz_node);
  for ($i = 1; $i <= 10; $i++) {
    $questions = quiz_build_question_list($quiz_node);
    $out[$i] = '';
    foreach ($questions as $question) {
      $out[$i] .= $question['nid'];
    }
  }

  // Check that at least one of the orders is different.
  $this
    ->assertNotEqual(count(array_unique($out)), 1, t('At least one set of questions was different.'));

  // Start the quiz.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet("node/{$quiz_node->nid}");
}