Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400]
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 * Contains the helper class for the select missing words question type tests. 19 * 20 * @package qtype_gapselect 21 * @copyright 2011 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 select missing words question type. 31 * 32 * @copyright 2011 The Open University 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class qtype_gapselect_test_helper extends question_test_helper { 36 37 public function get_test_questions() { 38 return array('fox', 'maths', 'currency', 'multilang', 'missingchoiceno'); 39 } 40 41 /** 42 * Get data you would get by loading a typical select missing words question. 43 * 44 * @return stdClass as returned by question_bank::load_question_data for this qtype. 45 */ 46 public static function get_gapselect_question_data_fox() { 47 global $USER; 48 49 $gapselect = new stdClass(); 50 $gapselect->id = 0; 51 $gapselect->category = 0; 52 $gapselect->contextid = 0; 53 $gapselect->parent = 0; 54 $gapselect->questiontextformat = FORMAT_HTML; 55 $gapselect->generalfeedbackformat = FORMAT_HTML; 56 $gapselect->defaultmark = 1; 57 $gapselect->penalty = 0.3333333; 58 $gapselect->length = 1; 59 $gapselect->stamp = make_unique_id_code(); 60 $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 61 $gapselect->versionid = 0; 62 $gapselect->version = 1; 63 $gapselect->questionbankentryid = 0; 64 $gapselect->idnumber = null; 65 $gapselect->timecreated = time(); 66 $gapselect->timemodified = time(); 67 $gapselect->createdby = $USER->id; 68 $gapselect->modifiedby = $USER->id; 69 70 $gapselect->name = 'Selection from drop down list question'; 71 $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.'; 72 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; 73 $gapselect->qtype = 'gapselect'; 74 75 $gapselect->options = new stdClass(); 76 $gapselect->options->shuffleanswers = true; 77 78 test_question_maker::set_standard_combined_feedback_fields($gapselect->options); 79 80 $gapselect->options->answers = array( 81 (object) array('answer' => 'quick', 'feedback' => '1'), 82 (object) array('answer' => 'fox', 'feedback' => '2'), 83 (object) array('answer' => 'lazy', 'feedback' => '3'), 84 (object) array('answer' => 'assiduous', 'feedback' => '3'), 85 (object) array('answer' => 'dog', 'feedback' => '2'), 86 (object) array('answer' => 'slow', 'feedback' => '1'), 87 ); 88 89 return $gapselect; 90 } 91 92 /** 93 * Get data required to save a select missing words question where 94 * the author missed out one of the group numbers. 95 * 96 * @return stdClass data to create a gapselect question. 97 */ 98 public function get_gapselect_question_form_data_missingchoiceno() { 99 $fromform = new stdClass(); 100 101 $fromform->name = 'Select missing words question'; 102 $fromform->questiontext = ['text' => 'The [[1]] sat on the [[3]].', 'format' => FORMAT_HTML]; 103 $fromform->defaultmark = 1.0; 104 $fromform->generalfeedback = ['text' => 'The right answer is: "The cat sat on the mat."', 'format' => FORMAT_HTML]; 105 $fromform->choices = [ 106 ['answer' => 'cat', 'choicegroup' => '1'], 107 ['answer' => '', 'choicegroup' => '1'], 108 ['answer' => 'mat', 'choicegroup' => '1'], 109 ]; 110 test_question_maker::set_standard_combined_feedback_form_data($fromform); 111 $fromform->shownumcorrect = 0; 112 $fromform->penalty = 0.3333333; 113 $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 114 115 return $fromform; 116 } 117 118 /** 119 * Get an example gapselect question to use for testing. This examples has one of each item. 120 * @return qtype_gapselect_question 121 */ 122 public static function make_gapselect_question_fox() { 123 question_bank::load_question_definition_classes('gapselect'); 124 $gapselect = new qtype_gapselect_question(); 125 126 test_question_maker::initialise_a_question($gapselect); 127 128 $gapselect->name = 'Selection from drop down list question'; 129 $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.'; 130 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; 131 $gapselect->qtype = question_bank::get_qtype('gapselect'); 132 $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 133 134 $gapselect->shufflechoices = true; 135 136 test_question_maker::set_standard_combined_feedback_fields($gapselect); 137 138 $gapselect->choices = array( 139 1 => array( 140 1 => new qtype_gapselect_choice('quick', 1), 141 2 => new qtype_gapselect_choice('slow', 1)), 142 2 => array( 143 1 => new qtype_gapselect_choice('fox', 2), 144 2 => new qtype_gapselect_choice('dog', 2)), 145 3 => array( 146 1 => new qtype_gapselect_choice('lazy', 3), 147 2 => new qtype_gapselect_choice('assiduous', 3)), 148 ); 149 150 $gapselect->places = array(1 => 1, 2 => 2, 3 => 3); 151 $gapselect->rightchoices = array(1 => 1, 2 => 1, 3 => 1); 152 $gapselect->textfragments = array('The ', ' brown ', ' jumped over the ', ' dog.'); 153 154 return $gapselect; 155 } 156 157 /** 158 * Get an example gapselect question to use for testing. This exmples had unlimited items. 159 * @return qtype_gapselect_question 160 */ 161 public static function make_gapselect_question_maths() { 162 question_bank::load_question_definition_classes('gapselect'); 163 $gapselect = new qtype_gapselect_question(); 164 165 test_question_maker::initialise_a_question($gapselect); 166 167 $gapselect->name = 'Selection from drop down list question'; 168 $gapselect->questiontext = 'Fill in the operators to make this equation work: ' . 169 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; 170 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; 171 $gapselect->qtype = question_bank::get_qtype('gapselect'); 172 $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 173 174 $gapselect->shufflechoices = true; 175 176 test_question_maker::set_standard_combined_feedback_fields($gapselect); 177 178 $gapselect->choices = array( 179 1 => array( 180 1 => new qtype_gapselect_choice('+', 1), 181 2 => new qtype_gapselect_choice('-', 1), 182 3 => new qtype_gapselect_choice('*', 1), 183 4 => new qtype_gapselect_choice('/', 1), 184 )); 185 186 $gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1); 187 $gapselect->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); 188 $gapselect->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3'); 189 190 return $gapselect; 191 } 192 193 /** 194 * Get an example gapselect question with multilang entries to use for testing. 195 * @return qtype_gapselect_question 196 */ 197 public static function make_gapselect_question_multilang() { 198 question_bank::load_question_definition_classes('gapselect'); 199 $gapselect = new qtype_gapselect_question(); 200 201 test_question_maker::initialise_a_question($gapselect); 202 203 $gapselect->name = 'Multilang select missing words question'; 204 $gapselect->questiontext = '<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>[[1]] ' . 205 '<span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> [[2]].'; 206 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; 207 $gapselect->qtype = question_bank::get_qtype('gapselect'); 208 $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 209 210 $gapselect->shufflechoices = true; 211 212 test_question_maker::set_standard_combined_feedback_fields($gapselect); 213 214 $gapselect->choices = array( 215 1 => array( 216 1 => new qtype_gapselect_choice('<span lang="en" class="multilang">cat</span><span lang="ru" ' . 217 'class="multilang">кошка</span>', 1), 218 2 => new qtype_gapselect_choice('<span lang="en" class="multilang">dog</span><span lang="ru" ' . 219 'class="multilang">пес</span>', 1)), 220 2 => array( 221 1 => new qtype_gapselect_choice('<span lang="en" class="multilang">mat</span><span lang="ru" ' . 222 'class="multilang">коврике</span>', 2), 223 2 => new qtype_gapselect_choice('<span lang="en" class="multilang">bat</span><span lang="ru" ' . 224 'class="multilang">бита</span>', 2)) 225 ); 226 227 $gapselect->places = array(1 => 1, 2 => 2); 228 $gapselect->rightchoices = array(1 => 1, 2 => 1); 229 $gapselect->textfragments = array('<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>', 230 ' <span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> ', '.'); 231 232 return $gapselect; 233 } 234 235 /** 236 * This examples includes choices with currency like options. 237 * @return qtype_gapselect_question 238 */ 239 public static function make_gapselect_question_currency() { 240 question_bank::load_question_definition_classes('gapselect'); 241 $gapselect = new qtype_gapselect_question(); 242 243 test_question_maker::initialise_a_question($gapselect); 244 245 $gapselect->name = 'Selection from currency like choices'; 246 $gapselect->questiontext = 'The price of the ball is [[1]] approx.'; 247 $gapselect->generalfeedback = 'The choice is yours'; 248 $gapselect->qtype = question_bank::get_qtype('gapselect'); 249 $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 250 251 $gapselect->shufflechoices = true; 252 253 test_question_maker::set_standard_combined_feedback_fields($gapselect); 254 255 $gapselect->choices = [ 256 1 => [ 257 1 => new qtype_gapselect_choice('$2', 1), 258 2 => new qtype_gapselect_choice('$3', 1), 259 3 => new qtype_gapselect_choice('$4.99', 1), 260 4 => new qtype_gapselect_choice('-1', 1) 261 ] 262 ]; 263 264 $gapselect->places = array(1 => 1); 265 $gapselect->rightchoices = array(1 => 1); 266 $gapselect->textfragments = array('The price of the ball is ', ' approx.'); 267 268 return $gapselect; 269 } 270 271 /** 272 * Just for backwards compatibility. 273 * 274 * @return qtype_gapselect_question 275 */ 276 public static function make_a_gapselect_question() { 277 debugging('qtype_gapselect_test_helper::make_a_gapselect_question is deprecated. ' . 278 "Please use test_question_maker::make_question('gapselect') instead."); 279 return self::make_gapselect_question_fox(); 280 } 281 282 /** 283 * Just for backwards compatibility. 284 * 285 * @return qtype_gapselect_question 286 */ 287 public static function make_a_maths_gapselect_question() { 288 debugging('qtype_gapselect_test_helper::make_a_maths_gapselect_question is deprecated. ' . 289 "Please use test_question_maker::make_question('gapselect', 'maths') instead."); 290 return self::make_gapselect_question_maths(); 291 } 292 293 /** 294 * Just for backwards compatibility. 295 * 296 * @return qtype_gapselect_question 297 */ 298 public static function make_a_currency_gapselect_question() { 299 debugging('qtype_gapselect_test_helper::make_a_currency_gapselect_question is deprecated. ' . 300 "Please use test_question_maker::make_question('gapselect', 'currency') instead."); 301 return self::make_gapselect_question_currency(); 302 } 303 304 /** 305 * Just for backwards compatibility. 306 * 307 * @return qtype_gapselect_question 308 */ 309 public static function make_a_multilang_gapselect_question() { 310 debugging('qtype_gapselect_test_helper::make_a_multilang_gapselect_question is deprecated. ' . 311 "Please use test_question_maker::make_question('gapselect', 'multilang') instead."); 312 return self::make_gapselect_question_multilang(); 313 } 314 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body