You are here

scale.test in Quiz 7.6

Test suite for scale question type module.

File

question_types/scale/scale.test
View source
<?php

/**
 * @file
 * Test suite for scale question type module.
 */

/**
 * Test class for scale questions.
 */
class ScaleTestCase extends QuizQuestionTestCase {
  var $question_node_type = 'scale';

  /**
   * The getInfo() method provides information about the test.
   * In order for the test to be run, the getInfo() method needs
   * to be implemented.
   */
  public static function getInfo() {
    return array(
      'name' => t('Scale'),
      'description' => t('Unit test for scale question type.'),
      'group' => t('Quiz'),
    );
  }

  /**
   * Implementing setUp() to enable scale module testing
   */
  function setUp($modules = array(), $admin_permissions = array(), $user_permissions = array()) {
    parent::setUp(array(
      'scale',
    ));
  }

  /**
   * Create a new question with default settings.
   */
  public function testCreateQuizQuestion() {

    // Login as our privileged user.
    $this
      ->drupalLogin($this->admin);
    $settings = array();
    $settings['type'] = 'scale';
    $question_node = $this
      ->drupalCreateNode(array(
      'type' => 'scale',
      'title' => 'Scale 1 title',
      'alternative0' => 'This is alternative 1',
      'alternative1' => 'This is alternative 2',
      'alternative2' => 'This is alternative 3',
      'alternative3' => 'This is alternative 4',
      'alternative4' => 'This is alternative 5',
      'body' => array(
        LANGUAGE_NONE => array(
          array(
            'value' => 'Scale 1 body text',
          ),
        ),
      ),
    ));
    return $question_node;
  }
  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('Scale 1 title');

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

    // Take the quiz.
    $this
      ->drupalGet("node/{$quiz_node->nid}/take");
    $this
      ->assertNoText('Scale 1 title');
    $this
      ->assertText('Scale 1 body text');
    $this
      ->assertText('This is alternative 1');
    $this
      ->assertText('This is alternative 2');

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

    // Test any question.
    $this
      ->drupalGet("node/{$quiz_node->nid}/take");
    $this
      ->drupalPost(NULL, array(
      // Alternative #2 is actually 24 (because of the presets).
      "question[{$question_node->nid}][answer]" => 24,
    ), t('Finish'));
    $this
      ->assertText('You got 1 of 1 possible points.');
  }

}

Classes

Namesort descending Description
ScaleTestCase Test class for scale questions.