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.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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  
  90          return $form;
  91      }
  92  
  93      function get_truefalse_question_data_true() {
  94  
  95          $q = new stdClass();
  96          $q->name = 'True/false question';
  97          $q->questiontext = 'The answer is true.';
  98          $q->questiontextformat = FORMAT_HTML;
  99          $q->generalfeedback = 'You should have selected true.';
 100          $q->generalfeedbackformat = FORMAT_HTML;
 101          $q->defaultmark = 1;
 102          $q->penalty = 1;
 103          $q->qtype = 'truefalse';
 104          $q->length = '1';
 105          $q->hidden = '0';
 106          $q->createdby = '2';
 107          $q->modifiedby = '2';
 108          $q->options = new stdClass();
 109          $q->options->trueanswer = '0';
 110          $q->options->falseanswer = '1';
 111          $q->options->answers = array();
 112          $q->options->answers[0] = new stdClass();
 113          $q->options->answers[0]->answer = 'True';
 114          $q->options->answers[0]->fraction = 1.0;
 115          $q->options->answers[0]->feedback = 'This is the right answer.';
 116          $q->options->answers[0]->feedbackformat = FORMAT_HTML;
 117  
 118          $q->options->answers[1] = new stdClass();
 119          $q->options->answers[1]->answer = 'False';
 120          $q->options->answers[1]->fraction = 0.0;
 121          $q->options->answers[1]->feedback = 'This is the wrong answer.';
 122          $q->options->answers[1]->feedbackformat = FORMAT_HTML;
 123  
 124          return $q;
 125      }
 126  
 127      /**
 128       * Makes a truefalse question with correct answer false.
 129       * @return qtype_truefalse_question
 130       */
 131      public function make_truefalse_question_false() {
 132          question_bank::load_question_definition_classes('truefalse');
 133          $tf = new qtype_truefalse_question();
 134          test_question_maker::initialise_a_question($tf);
 135          $tf->name = 'True/false question';
 136          $tf->questiontext = 'The answer is false.';
 137          $tf->generalfeedback = 'You should have selected false.';
 138          $tf->penalty = 1;
 139          $tf->qtype = question_bank::get_qtype('truefalse');
 140  
 141          $tf->rightanswer = false;
 142          $tf->truefeedback = 'This is the wrong answer.';
 143          $tf->falsefeedback = 'This is the right answer.';
 144          $tf->truefeedbackformat = FORMAT_HTML;
 145          $tf->falsefeedbackformat = FORMAT_HTML;
 146          $tf->trueanswerid = 13;
 147          $tf->falseanswerid = 14;
 148  
 149          return $tf;
 150      }
 151  }