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