Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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   * Unit tests for the question type base class.
  19   *
  20   * @package    moodlecore
  21   * @subpackage questiontypes
  22   * @copyright  2008 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($CFG->dirroot . '/question/type/questiontypebase.php');
  31  
  32  
  33  /**
  34   * Tests for some of ../questionbase.php
  35   *
  36   * @copyright  2008 The Open University
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class question_type_testcase extends advanced_testcase {
  40      public static $includecoverage = array('question/type/questiontypebase.php');
  41  
  42      public function test_save_question_name() {
  43          $this->resetAfterTest();
  44  
  45          $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
  46          $cat = $questiongenerator->create_question_category(array());
  47  
  48          $saq = $questiongenerator->create_question('shortanswer', null,
  49                  array('category' => $cat->id, 'name' => 'Test question'));
  50          $actual = question_bank::load_question_data($saq->id);
  51  
  52          $this->assertSame('Test question', $actual->name);
  53      }
  54  
  55      public function test_save_question_zero_name() {
  56          $this->resetAfterTest();
  57  
  58          $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
  59          $cat = $questiongenerator->create_question_category(array());
  60  
  61          $saq = $questiongenerator->create_question('shortanswer', null,
  62                  array('category' => $cat->id, 'name' => '0'));
  63          $actual = question_bank::load_question_data($saq->id);
  64  
  65          $this->assertSame('0', $actual->name);
  66      }
  67  }