Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

   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 drag-and-drop words into sentences question type.
  19   *
  20   * @package   qtype_ddwtos
  21   * @copyright 2010 The Open University
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  
  29  /**
  30   * Test helper class for the drag-and-drop words into sentences question type.
  31   *
  32   * @copyright  2010 The Open University
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class qtype_ddwtos_test_helper extends question_test_helper {
  36      public function get_test_questions() {
  37          return array('fox', 'maths', 'oddgroups', 'missingchoiceno', 'infinite');
  38      }
  39  
  40      /**
  41       * @return qtype_ddwtos_question
  42       */
  43      public function make_ddwtos_question_fox() {
  44          question_bank::load_question_definition_classes('ddwtos');
  45          $dd = new qtype_ddwtos_question();
  46  
  47          test_question_maker::initialise_a_question($dd);
  48  
  49          $dd->name = 'Drag-and-drop words into sentences question';
  50          $dd->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
  51          $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
  52          $dd->qtype = question_bank::get_qtype('ddwtos');
  53  
  54          $dd->shufflechoices = true;
  55  
  56          test_question_maker::set_standard_combined_feedback_fields($dd);
  57  
  58          $dd->choices = array(
  59              1 => array(
  60                  1 => new qtype_ddwtos_choice('quick', 1),
  61                  2 => new qtype_ddwtos_choice('slow', 1)),
  62              2 => array(
  63                  1 => new qtype_ddwtos_choice('fox', 2),
  64                  2 => new qtype_ddwtos_choice('dog', 2)),
  65              3 => array(
  66                  1 => new qtype_ddwtos_choice('lazy', 3),
  67                  2 => new qtype_ddwtos_choice('assiduous', 3)),
  68          );
  69  
  70          $dd->places = array(1 => 1, 2 => 2, 3 => 3);
  71          $dd->rightchoices = array(1 => 1, 2 => 1, 3 => 1);
  72          $dd->textfragments = array('The ', ' brown ', ' jumped over the ', ' dog.');
  73  
  74          return $dd;
  75      }
  76  
  77      /**
  78       * This is a simple question with choices in three groups.
  79       *
  80       * @return stdClass data to create a ddwtos question.
  81       */
  82      public function get_ddwtos_question_form_data_fox() {
  83          $fromform = new stdClass();
  84  
  85          $fromform->name = 'Drag-and-drop words into sentences question';
  86          $fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML);
  87          $fromform->defaultmark = 1.0;
  88          $fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML);
  89          $fromform->choices = array(
  90              array('answer' => 'quick',     'choicegroup' => '1'),
  91              array('answer' => 'fox',       'choicegroup' => '2'),
  92              array('answer' => 'lazy',      'choicegroup' => '3'),
  93              array('answer' => 'slow',      'choicegroup' => '1'),
  94              array('answer' => 'dog',       'choicegroup' => '2'),
  95              array('answer' => 'assiduous', 'choicegroup' => '3'),
  96          );
  97          test_question_maker::set_standard_combined_feedback_form_data($fromform);
  98          $fromform->shownumcorrect = 0;
  99          $fromform->penalty = 0.3333333;
 100          $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
 101  
 102          return $fromform;
 103      }
 104  
 105      /**
 106       * Similar to the 'fox' example above, but using different, non-continuous group numbers.
 107       *
 108       * @return stdClass data to create a ddwtos question.
 109       */
 110      public function get_ddwtos_question_form_data_oddgroups() {
 111          $fromform = new stdClass();
 112  
 113          $fromform->name = 'Drag-and-drop words with strange groups';
 114          $fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML);
 115          $fromform->defaultmark = 1.0;
 116          $fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML);
 117          $fromform->choices = array(
 118              array('answer' => 'quick',     'choicegroup' => '5'),
 119              array('answer' => 'fox',       'choicegroup' => '7'),
 120              array('answer' => 'lazy',      'choicegroup' => '3'),
 121              array('answer' => 'slow',      'choicegroup' => '5'),
 122              array('answer' => 'dog',       'choicegroup' => '7'),
 123              array('answer' => 'assiduous', 'choicegroup' => '3'),
 124          );
 125          test_question_maker::set_standard_combined_feedback_form_data($fromform);
 126          $fromform->shownumcorrect = 0;
 127          $fromform->penalty = 0.3333333;
 128          $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
 129  
 130          return $fromform;
 131      }
 132  
 133      /**
 134       * Get data required to save a drag-drop into text question where the author
 135       * missed out one of the group numbers.
 136       *
 137       * @return stdClass data to create a ddwtos question.
 138       */
 139      public function get_ddwtos_question_form_data_missingchoiceno() {
 140          $fromform = new stdClass();
 141  
 142          $fromform->name = 'Drag-drop into text question with one index missing';
 143          $fromform->questiontext = ['text' => 'The [[1]] sat on the [[3]].', 'format' => FORMAT_HTML];
 144          $fromform->defaultmark = 1.0;
 145          $fromform->generalfeedback = array('text' => 'The right answer is: "The cat sat on the mat."', 'format' => FORMAT_HTML);
 146          $fromform->choices = array(
 147                  array('answer' => 'cat', 'choicegroup' => '1'),
 148                  array('answer' => '',    'choicegroup' => '1'),
 149                  array('answer' => 'mat', 'choicegroup' => '1'),
 150          );
 151          test_question_maker::set_standard_combined_feedback_form_data($fromform);
 152          $fromform->shownumcorrect = 0;
 153          $fromform->penalty = 0.3333333;
 154          $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
 155  
 156          return $fromform;
 157      }
 158  
 159      /**
 160       * @return qtype_ddwtos_question
 161       */
 162      public function make_ddwtos_question_maths() {
 163          question_bank::load_question_definition_classes('ddwtos');
 164          $dd = new qtype_ddwtos_question();
 165  
 166          test_question_maker::initialise_a_question($dd);
 167  
 168          $dd->name = 'Drag-and-drop words into sentences question';
 169          $dd->questiontext = 'Fill in the operators to make this equation work: ' .
 170                  '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
 171          $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
 172          $dd->qtype = question_bank::get_qtype('ddwtos');
 173  
 174          $dd->shufflechoices = true;
 175  
 176          test_question_maker::set_standard_combined_feedback_fields($dd);
 177  
 178          $dd->choices = array(
 179              1 => array(
 180                  1 => new qtype_ddwtos_choice('+', 1, true),
 181                  2 => new qtype_ddwtos_choice('-', 1, true),
 182                  3 => new qtype_ddwtos_choice('*', 1, true),
 183                  4 => new qtype_ddwtos_choice('/', 1, true),
 184              ));
 185  
 186          $dd->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1);
 187          $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
 188          $dd->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3');
 189  
 190          return $dd;
 191      }
 192  
 193      /**
 194       * This is a simple question with infinite mode.
 195       *
 196       * @return stdClass data to create a ddwtos question.
 197       */
 198      public function get_ddwtos_question_form_data_infinite() {
 199          $fromform = new stdClass();
 200  
 201          $fromform->name = 'Drag-and-drop infinite question';
 202          $fromform->questiontext = ['text' => 'One [[1]] Two [[2]] Three [[3]]', 'format' => FORMAT_HTML];
 203          $fromform->defaultmark = 1.0;
 204          $fromform->generalfeedback = ['text' => 'This is general feedback', 'format' => FORMAT_HTML];
 205          $fromform->choices = [
 206                  ['answer' => 'Option1', 'choicegroup' => '1', 'infinite' => true],
 207                  ['answer' => 'Option2', 'choicegroup' => '1', 'infinite' => true],
 208                  ['answer' => 'Option3', 'choicegroup' => '1', 'infinite' => true]
 209          ];
 210          test_question_maker::set_standard_combined_feedback_form_data($fromform);
 211          $fromform->shownumcorrect = 0;
 212          $fromform->penalty = 0.3333333;
 213          $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
 214  
 215          return $fromform;
 216      }
 217  }