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 helper code for the multiple choice question type. 19 * 20 * @package qtype_multichoice 21 * @copyright 2013 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 multiple choice question type. 31 * 32 * @copyright 2013 The Open University 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class qtype_multichoice_test_helper extends question_test_helper { 36 public function get_test_questions() { 37 return array('two_of_four', 'one_of_four'); 38 } 39 40 /** 41 * Get the question data, as it would be loaded by get_question_options. 42 * @return object 43 */ 44 public static function get_multichoice_question_data_two_of_four() { 45 global $USER; 46 47 $qdata = new stdClass(); 48 49 $qdata->createdby = $USER->id; 50 $qdata->modifiedby = $USER->id; 51 $qdata->qtype = 'multichoice'; 52 $qdata->name = 'Multiple choice question'; 53 $qdata->questiontext = 'Which are the odd numbers?'; 54 $qdata->questiontextformat = FORMAT_HTML; 55 $qdata->generalfeedback = 'The odd numbers are One and Three.'; 56 $qdata->generalfeedbackformat = FORMAT_HTML; 57 $qdata->defaultmark = 1; 58 $qdata->length = 1; 59 $qdata->penalty = 0.3333333; 60 $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 61 $qdata->versionid = 0; 62 $qdata->version = 1; 63 $qdata->questionbankentryid = 0; 64 $qdata->options = new stdClass(); 65 $qdata->options->shuffleanswers = 1; 66 $qdata->options->answernumbering = '123'; 67 $qdata->options->showstandardinstruction = 0; 68 $qdata->options->layout = 0; 69 $qdata->options->single = 0; 70 $qdata->options->correctfeedback = 71 test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK; 72 $qdata->options->correctfeedbackformat = FORMAT_HTML; 73 $qdata->options->partiallycorrectfeedback = 74 test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK; 75 $qdata->options->partiallycorrectfeedbackformat = FORMAT_HTML; 76 $qdata->options->shownumcorrect = 1; 77 $qdata->options->incorrectfeedback = 78 test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK; 79 $qdata->options->incorrectfeedbackformat = FORMAT_HTML; 80 81 $qdata->options->answers = array( 82 13 => (object) array( 83 'id' => 13, 84 'answer' => 'One', 85 'answerformat' => FORMAT_PLAIN, 86 'fraction' => 0.5, 87 'feedback' => 'One is odd.', 88 'feedbackformat' => FORMAT_HTML, 89 ), 90 14 => (object) array( 91 'id' => 14, 92 'answer' => 'Two', 93 'answerformat' => FORMAT_PLAIN, 94 'fraction' => 0.0, 95 'feedback' => 'Two is even.', 96 'feedbackformat' => FORMAT_HTML, 97 ), 98 15 => (object) array( 99 'id' => 15, 100 'answer' => 'Three', 101 'answerformat' => FORMAT_PLAIN, 102 'fraction' => 0.5, 103 'feedback' => 'Three is odd.', 104 'feedbackformat' => FORMAT_HTML, 105 ), 106 16 => (object) array( 107 'id' => 16, 108 'answer' => 'Four', 109 'answerformat' => FORMAT_PLAIN, 110 'fraction' => 0.0, 111 'feedback' => 'Four is even.', 112 'feedbackformat' => FORMAT_HTML, 113 ), 114 ); 115 116 $qdata->hints = array( 117 1 => (object) array( 118 'hint' => 'Hint 1.', 119 'hintformat' => FORMAT_HTML, 120 'shownumcorrect' => 1, 121 'clearwrong' => 0, 122 'options' => 0, 123 ), 124 2 => (object) array( 125 'hint' => 'Hint 2.', 126 'hintformat' => FORMAT_HTML, 127 'shownumcorrect' => 1, 128 'clearwrong' => 1, 129 'options' => 1, 130 ), 131 ); 132 133 return $qdata; 134 } 135 /** 136 * Get the question data, as it would be loaded by get_question_options. 137 * @return object 138 */ 139 public static function get_multichoice_question_form_data_two_of_four() { 140 $qdata = new stdClass(); 141 142 $qdata->name = 'multiple choice question'; 143 $qdata->questiontext = array('text' => 'Which are the odd numbers?', 'format' => FORMAT_HTML); 144 $qdata->generalfeedback = array('text' => 'The odd numbers are One and Three.', 'format' => FORMAT_HTML); 145 $qdata->defaultmark = 1; 146 $qdata->noanswers = 5; 147 $qdata->numhints = 2; 148 $qdata->penalty = 0.3333333; 149 $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 150 $qdata->versionid = 0; 151 $qdata->version = 1; 152 $qdata->questionbankentryid = 0; 153 154 $qdata->shuffleanswers = 1; 155 $qdata->answernumbering = '123'; 156 $qdata->showstandardinstruction = 0; 157 $qdata->single = '0'; 158 $qdata->correctfeedback = array('text' => test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK, 159 'format' => FORMAT_HTML); 160 $qdata->partiallycorrectfeedback = array('text' => test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK, 161 'format' => FORMAT_HTML); 162 $qdata->shownumcorrect = 1; 163 $qdata->incorrectfeedback = array('text' => test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK, 164 'format' => FORMAT_HTML); 165 $qdata->fraction = array('0.5', '0.0', '0.5', '0.0', '0.0'); 166 $qdata->answer = array( 167 0 => array( 168 'text' => 'One', 169 'format' => FORMAT_PLAIN 170 ), 171 1 => array( 172 'text' => 'Two', 173 'format' => FORMAT_PLAIN 174 ), 175 2 => array( 176 'text' => 'Three', 177 'format' => FORMAT_PLAIN 178 ), 179 3 => array( 180 'text' => 'Four', 181 'format' => FORMAT_PLAIN 182 ), 183 4 => array( 184 'text' => '', 185 'format' => FORMAT_PLAIN 186 ) 187 ); 188 189 $qdata->feedback = array( 190 0 => array( 191 'text' => 'One is odd.', 192 'format' => FORMAT_HTML 193 ), 194 1 => array( 195 'text' => 'Two is even.', 196 'format' => FORMAT_HTML 197 ), 198 2 => array( 199 'text' => 'Three is odd.', 200 'format' => FORMAT_HTML 201 ), 202 3 => array( 203 'text' => 'Four is even.', 204 'format' => FORMAT_HTML 205 ), 206 4 => array( 207 'text' => '', 208 'format' => FORMAT_HTML 209 ) 210 ); 211 212 $qdata->hint = array( 213 0 => array( 214 'text' => 'Hint 1.', 215 'format' => FORMAT_HTML 216 ), 217 1 => array( 218 'text' => 'Hint 2.', 219 'format' => FORMAT_HTML 220 ) 221 ); 222 $qdata->hintclearwrong = array(0, 1); 223 $qdata->hintshownumcorrect = array(1, 1); 224 225 return $qdata; 226 } 227 228 /** 229 * Get the question data, as it would be loaded by get_question_options. 230 * @return object 231 */ 232 public static function get_multichoice_question_data_one_of_four() { 233 global $USER; 234 235 $qdata = new stdClass(); 236 237 $qdata->createdby = $USER->id; 238 $qdata->modifiedby = $USER->id; 239 $qdata->qtype = 'multichoice'; 240 $qdata->name = 'Multiple choice question'; 241 $qdata->questiontext = 'Which is the oddest number?'; 242 $qdata->questiontextformat = FORMAT_HTML; 243 $qdata->generalfeedback = 'The oddest number is One.'; // Arguable possibly but it is a quick way to make a variation on 244 //this question with one correct answer. 245 $qdata->generalfeedbackformat = FORMAT_HTML; 246 $qdata->defaultmark = 1; 247 $qdata->length = 1; 248 $qdata->penalty = 0.3333333; 249 $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 250 $qdata->versionid = 0; 251 $qdata->version = 1; 252 $qdata->questionbankentryid = 0; 253 254 $qdata->options = new stdClass(); 255 $qdata->options->shuffleanswers = 1; 256 $qdata->options->answernumbering = '123'; 257 $qdata->options->showstandardinstruction = 0; 258 $qdata->options->layout = 0; 259 $qdata->options->single = 1; 260 $qdata->options->correctfeedback = 261 test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK; 262 $qdata->options->correctfeedbackformat = FORMAT_HTML; 263 $qdata->options->partiallycorrectfeedback = 264 test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK; 265 $qdata->options->partiallycorrectfeedbackformat = FORMAT_HTML; 266 $qdata->options->shownumcorrect = 1; 267 $qdata->options->incorrectfeedback = 268 test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK; 269 $qdata->options->incorrectfeedbackformat = FORMAT_HTML; 270 271 $qdata->options->answers = array( 272 13 => (object) array( 273 'id' => 13, 274 'answer' => 'One', 275 'answerformat' => FORMAT_PLAIN, 276 'fraction' => 1, 277 'feedback' => 'One is the oddest.', 278 'feedbackformat' => FORMAT_HTML, 279 ), 280 14 => (object) array( 281 'id' => 14, 282 'answer' => 'Two', 283 'answerformat' => FORMAT_PLAIN, 284 'fraction' => 0.0, 285 'feedback' => 'Two is even.', 286 'feedbackformat' => FORMAT_HTML, 287 ), 288 15 => (object) array( 289 'id' => 15, 290 'answer' => 'Three', 291 'answerformat' => FORMAT_PLAIN, 292 'fraction' => 0, 293 'feedback' => 'Three is odd.', 294 'feedbackformat' => FORMAT_HTML, 295 ), 296 16 => (object) array( 297 'id' => 16, 298 'answer' => 'Four', 299 'answerformat' => FORMAT_PLAIN, 300 'fraction' => 0.0, 301 'feedback' => 'Four is even.', 302 'feedbackformat' => FORMAT_HTML, 303 ), 304 ); 305 306 $qdata->hints = array( 307 1 => (object) array( 308 'hint' => 'Hint 1.', 309 'hintformat' => FORMAT_HTML, 310 'shownumcorrect' => 1, 311 'clearwrong' => 0, 312 'options' => 0, 313 ), 314 2 => (object) array( 315 'hint' => 'Hint 2.', 316 'hintformat' => FORMAT_HTML, 317 'shownumcorrect' => 1, 318 'clearwrong' => 1, 319 'options' => 1, 320 ), 321 ); 322 323 return $qdata; 324 } 325 /** 326 * Get the question data, as it would be loaded by get_question_options. 327 * @return object 328 */ 329 public static function get_multichoice_question_form_data_one_of_four() { 330 $qdata = new stdClass(); 331 332 $qdata->name = 'multiple choice question'; 333 $qdata->questiontext = array('text' => 'Which is the oddest number?', 'format' => FORMAT_HTML); 334 $qdata->generalfeedback = array('text' => 'The oddest number is One.', 'format' => FORMAT_HTML); 335 $qdata->defaultmark = 1; 336 $qdata->noanswers = 5; 337 $qdata->numhints = 2; 338 $qdata->penalty = 0.3333333; 339 $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 340 $qdata->versionid = 0; 341 $qdata->version = 1; 342 $qdata->questionbankentryid = 0; 343 344 $qdata->shuffleanswers = 1; 345 $qdata->answernumbering = '123'; 346 $qdata->showstandardinstruction = 0; 347 $qdata->single = '1'; 348 $qdata->correctfeedback = array('text' => test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK, 349 'format' => FORMAT_HTML); 350 $qdata->partiallycorrectfeedback = array('text' => test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK, 351 'format' => FORMAT_HTML); 352 $qdata->shownumcorrect = 1; 353 $qdata->incorrectfeedback = array('text' => test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK, 354 'format' => FORMAT_HTML); 355 $qdata->fraction = array('1.0', '0.0', '0.0', '0.0', '0.0'); 356 $qdata->answer = array( 357 0 => array( 358 'text' => 'One', 359 'format' => FORMAT_PLAIN 360 ), 361 1 => array( 362 'text' => 'Two', 363 'format' => FORMAT_PLAIN 364 ), 365 2 => array( 366 'text' => 'Three', 367 'format' => FORMAT_PLAIN 368 ), 369 3 => array( 370 'text' => 'Four', 371 'format' => FORMAT_PLAIN 372 ), 373 4 => array( 374 'text' => '', 375 'format' => FORMAT_PLAIN 376 ) 377 ); 378 379 $qdata->feedback = array( 380 0 => array( 381 'text' => 'One is the oddest.', 382 'format' => FORMAT_HTML 383 ), 384 1 => array( 385 'text' => 'Two is even.', 386 'format' => FORMAT_HTML 387 ), 388 2 => array( 389 'text' => 'Three is odd.', 390 'format' => FORMAT_HTML 391 ), 392 3 => array( 393 'text' => 'Four is even.', 394 'format' => FORMAT_HTML 395 ), 396 4 => array( 397 'text' => '', 398 'format' => FORMAT_HTML 399 ) 400 ); 401 402 $qdata->hint = array( 403 0 => array( 404 'text' => 'Hint 1.', 405 'format' => FORMAT_HTML 406 ), 407 1 => array( 408 'text' => 'Hint 2.', 409 'format' => FORMAT_HTML 410 ) 411 ); 412 $qdata->hintclearwrong = array(0, 1); 413 $qdata->hintshownumcorrect = array(1, 1); 414 415 return $qdata; 416 } 417 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body