[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/question/engine/tests/ -> questionbank_test.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file contains tests for the question_bank class.
  19   *
  20   * @package    moodlecore
  21   * @subpackage questionbank
  22   * @copyright  2011 The Open University
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  require_once(dirname(__FILE__) . '/../lib.php');
  31  
  32  
  33  /**
  34   *Unit tests for the {@link question_bank} class.
  35   *
  36   * @copyright  2011 The Open University
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class question_bank_test extends advanced_testcase {
  40  
  41      public function test_sort_qtype_array() {
  42          $config = new stdClass();
  43          $config->multichoice_sortorder = '1';
  44          $config->calculated_sortorder = '2';
  45          $qtypes = array(
  46              'frog' => 'toad',
  47              'calculated' => 'newt',
  48              'multichoice' => 'eft',
  49          );
  50          $this->assertEquals(question_bank::sort_qtype_array($qtypes, $config), array(
  51              'multichoice' => 'eft',
  52              'calculated' => 'newt',
  53              'frog' => 'toad',
  54          ));
  55      }
  56  
  57      public function test_fraction_options() {
  58          $fractions = question_bank::fraction_options();
  59          $this->assertSame(get_string('none'), reset($fractions));
  60          $this->assertSame('0.0', key($fractions));
  61          $this->assertSame('5%', end($fractions));
  62          $this->assertSame('0.05', key($fractions));
  63          array_shift($fractions);
  64          array_pop($fractions);
  65          array_pop($fractions);
  66          $this->assertSame('100%', reset($fractions));
  67          $this->assertSame('1.0', key($fractions));
  68          $this->assertSame('11.11111%', end($fractions));
  69          $this->assertSame('0.1111111', key($fractions));
  70      }
  71  
  72      public function test_fraction_options_full() {
  73          $fractions = question_bank::fraction_options_full();
  74          $this->assertSame(get_string('none'), reset($fractions));
  75          $this->assertSame('0.0', key($fractions));
  76          $this->assertSame('-100%', end($fractions));
  77          $this->assertSame('-1.0', key($fractions));
  78          array_shift($fractions);
  79          array_pop($fractions);
  80          array_pop($fractions);
  81          $this->assertSame('100%', reset($fractions));
  82          $this->assertSame('1.0', key($fractions));
  83          $this->assertSame('-83.33333%', end($fractions));
  84          $this->assertSame('-0.8333333', key($fractions));
  85      }
  86  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1