Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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   * Test helpers for the truefalse question type.
  19   *
  20   * @package    qtype
  21   * @subpackage truefalse
  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  
  30  /**
  31   * Test helper class for the truefalse question type.
  32   *
  33   * @copyright  2011 The Open University
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class qtype_truefalse_test_helper extends question_test_helper {
  37      public function get_test_questions() {
  38          return array('true', 'false');
  39      }
  40  
  41      /**
  42       * Makes a truefalse question with correct answer true.
  43       * @return qtype_truefalse_question
  44       */
  45      public function make_truefalse_question_true() {
  46          question_bank::load_question_definition_classes('truefalse');
  47          $tf = new qtype_truefalse_question();
  48          test_question_maker::initialise_a_question($tf);
  49          $tf->name = 'True/false question';
  50          $tf->questiontext = 'The answer is true.';
  51          $tf->generalfeedback = 'You should have selected true.';
  52          $tf->penalty = 1;
  53          $tf->qtype = question_bank::get_qtype('truefalse');
  54  
  55          $tf->rightanswer = true;
  56          $tf->truefeedback = 'This is the right answer.';
  57          $tf->falsefeedback = 'This is the wrong answer.';
  58          $tf->truefeedbackformat = FORMAT_HTML;
  59          $tf->falsefeedbackformat = FORMAT_HTML;
  60          $tf->trueanswerid = 13;
  61          $tf->falseanswerid = 14;
  62  
  63          return $tf;
  64      }
  65  
  66      public function get_truefalse_question_form_data_true() {
  67  
  68          $form = new stdClass();
  69          $form->name = 'True/false question';
  70          $form->questiontext = array();
  71          $form->questiontext['format'] = '1';
  72          $form->questiontext['text'] = 'The answer is true.';
  73  
  74          $form->defaultmark = 1;
  75          $form->generalfeedback = array();
  76          $form->generalfeedback['format'] = '1';
  77          $form->generalfeedback['text'] = 'You should have selected true.';
  78  
  79          $form->correctanswer = '1';
  80          $form->feedbacktrue = array();
  81          $form->feedbacktrue['format'] = '1';
  82          $form->feedbacktrue['text'] = 'This is the right answer.';
  83  
  84          $form->feedbackfalse = array();
  85          $form->feedbackfalse['format'] = '1';
  86          $form->feedbackfalse['text'] = 'This is the wrong answer.';
  87  
  88          $form->penalty = 1;
  89          $form->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
  90  
  91          return $form;
  92      }
  93  
  94      function get_truefalse_question_data_true() {
  95  
  96          $q = new stdClass();
  97          $q->name = 'True/false question';
  98          $q->questiontext = 'The answer is true.';
  99          $q->questiontextformat = FORMAT_HTML;
 100          $q->generalfeedback = 'You should have selected true.';
 101          $q->generalfeedbackformat = FORMAT_HTML;
 102          $q->defaultmark = 1;
 103          $q->penalty = 1;
 104          $q->qtype = 'truefalse';
 105          $q->length = '1';
 106          $q->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
 107          $q->createdby = '2';
 108          $q->modifiedby = '2';
 109          $q->options = new stdClass();
 110          $q->options->trueanswer = '0';
 111          $q->options->falseanswer = '1';
 112          $q->options->answers = array();
 113          $q->options->answers[0] = new stdClass();
 114          $q->options->answers[0]->answer = 'True';
 115          $q->options->answers[0]->fraction = 1.0;
 116          $q->options->answers[0]->feedback = 'This is the right answer.';
 117          $q->options->answers[0]->feedbackformat = FORMAT_HTML;
 118  
 119          $q->options->answers[1] = new stdClass();
 120          $q->options->answers[1]->answer = 'False';
 121          $q->options->answers[1]->fraction = 0.0;
 122          $q->options->answers[1]->feedback = 'This is the wrong answer.';
 123          $q->options->answers[1]->feedbackformat = FORMAT_HTML;
 124  
 125          return $q;
 126      }
 127  
 128      /**
 129       * Makes a truefalse question with correct answer false.
 130       * @return qtype_truefalse_question
 131       */
 132      public function make_truefalse_question_false() {
 133          question_bank::load_question_definition_classes('truefalse');
 134          $tf = new qtype_truefalse_question();
 135          test_question_maker::initialise_a_question($tf);
 136          $tf->name = 'True/false question';
 137          $tf->questiontext = 'The answer is false.';
 138          $tf->generalfeedback = 'You should have selected false.';
 139          $tf->penalty = 1;
 140          $tf->qtype = question_bank::get_qtype('truefalse');
 141  
 142          $tf->rightanswer = false;
 143          $tf->truefeedback = 'This is the wrong answer.';
 144          $tf->falsefeedback = 'This is the right answer.';
 145          $tf->truefeedbackformat = FORMAT_HTML;
 146          $tf->falsefeedbackformat = FORMAT_HTML;
 147          $tf->trueanswerid = 13;
 148          $tf->falseanswerid = 14;
 149  
 150          return $tf;
 151      }
 152  }