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 * Test helpers for the drag-and-drop markers question type. 19 * 20 * @package qtype_ddmarker 21 * @copyright 2012 The Open University 22 * @author Jamie Pratt <me@jamiep.org> 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 drag-and-drop markers question type. 32 * 33 * @copyright 2010 The Open University 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class qtype_ddmarker_test_helper extends question_test_helper { 37 public function get_test_questions() { 38 return array('fox', 'maths', 'mkmap', 'zerodrag'); 39 } 40 41 /** 42 * @return qtype_ddmarker_question 43 */ 44 public function make_ddmarker_question_fox() { 45 question_bank::load_question_definition_classes('ddmarker'); 46 $dd = new qtype_ddmarker_question(); 47 48 test_question_maker::initialise_a_question($dd); 49 50 $dd->name = 'Drag-and-drop markers question'; 51 $dd->questiontext = 'The quick brown fox jumped over the lazy dog.'; 52 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.'; 53 $dd->qtype = question_bank::get_qtype('ddmarker'); 54 55 $dd->shufflechoices = true; 56 57 test_question_maker::set_standard_combined_feedback_fields($dd); 58 59 $dd->choices = $this->make_choice_structure(array( 60 new qtype_ddmarker_drag_item('quick', 1, 0, 1), 61 new qtype_ddmarker_drag_item('fox', 2, 0, 1), 62 new qtype_ddmarker_drag_item('lazy', 3, 0, 1) 63 64 )); 65 66 $dd->places = $this->make_place_structure(array( 67 new qtype_ddmarker_drop_zone(1, 'circle', '50,50;50'), 68 new qtype_ddmarker_drop_zone(2, 'rectangle', '100,0;100,100'), 69 new qtype_ddmarker_drop_zone(3, 'polygon', '0,100;200,100;200,200;0,200') 70 )); 71 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 3); 72 73 return $dd; 74 } 75 76 protected function make_choice_structure($choices) { 77 $choicestructure = array(); 78 foreach ($choices as $choice) { 79 $group = $choice->choice_group(); 80 if (!isset($choicestructure[$group])) { 81 $choicestructure[$group] = array(); 82 } 83 $choicestructure[$group][$choice->no] = $choice; 84 } 85 return $choicestructure; 86 } 87 88 protected function make_place_structure($places) { 89 $placestructure = array(); 90 foreach ($places as $place) { 91 $placestructure[$place->no] = $place; 92 } 93 return $placestructure; 94 } 95 96 /** 97 * @return qtype_ddmarker_question 98 */ 99 public function make_ddmarker_question_maths() { 100 question_bank::load_question_definition_classes('ddmarker'); 101 $dd = new qtype_ddmarker_question(); 102 103 test_question_maker::initialise_a_question($dd); 104 105 $dd->name = 'Drag-and-drop markers question'; 106 $dd->questiontext = 'Fill in the operators to make this equation work: '; 107 $dd->generalfeedback = 'Hmmmm...'; 108 $dd->qtype = question_bank::get_qtype('ddmarker'); 109 110 $dd->shufflechoices = true; 111 112 test_question_maker::set_standard_combined_feedback_fields($dd); 113 114 $dd->choices = $this->make_choice_structure(array( 115 new qtype_ddmarker_drag_item('+', 1, 1, 0), 116 new qtype_ddmarker_drag_item('-', 2, 1, 0), 117 new qtype_ddmarker_drag_item('*', 3, 1, 0), 118 new qtype_ddmarker_drag_item('/', 4, 1, 0) 119 120 )); 121 122 $dd->places = $this->make_place_structure(array( 123 new qtype_ddmarker_drop_zone(1, 'circle', '50,50;50'), 124 new qtype_ddmarker_drop_zone(2, 'rectangle', '100,0;100,100'), 125 new qtype_ddmarker_drop_zone(3, 'polygon', '0,100;100,100;100,200;0,200') 126 )); 127 $dd->rightchoices = array(1 => 1, 2 => 1, 3 => 1); 128 129 return $dd; 130 } 131 132 /** 133 * @return stdClass date to create a ddmarkers question. 134 */ 135 public function get_ddmarker_question_form_data_mkmap() { 136 global $CFG, $USER; 137 $fromform = new stdClass(); 138 139 $bgdraftitemid = 0; 140 file_prepare_draft_area($bgdraftitemid, null, null, null, null); 141 $fs = get_file_storage(); 142 $filerecord = new stdClass(); 143 $filerecord->contextid = context_user::instance($USER->id)->id; 144 $filerecord->component = 'user'; 145 $filerecord->filearea = 'draft'; 146 $filerecord->itemid = $bgdraftitemid; 147 $filerecord->filepath = '/'; 148 $filerecord->filename = 'mkmap.png'; 149 $fs->create_file_from_pathname($filerecord, $CFG->dirroot . 150 '/question/type/ddmarker/tests/fixtures/mkmap.png'); 151 152 $fromform->name = 'Milton Keynes landmarks'; 153 $fromform->questiontext = array( 154 'text' => 'Please place the markers on the map of Milton Keynes and be aware that '. 155 'there is more than one railway station.', 156 'format' => FORMAT_HTML, 157 ); 158 $fromform->defaultmark = 1; 159 $fromform->generalfeedback = array( 160 'text' => 'The Open University is at the junction of Brickhill Street and Groveway. '. 161 'There are three railway stations, Wolverton, Milton Keynes Central and Bletchley.', 162 'format' => FORMAT_HTML, 163 ); 164 $fromform->bgimage = $bgdraftitemid; 165 $fromform->shuffleanswers = 0; 166 167 $fromform->drags = array( 168 array('label' => 'OU', 'noofdrags' => 1), 169 array('label' => 'Railway station', 'noofdrags' => 3), 170 ); 171 172 $fromform->drops = array( 173 array('shape' => 'circle', 'coords' => '322,213;10', 'choice' => 1), 174 array('shape' => 'circle', 'coords' => '144,84;10', 'choice' => 2), 175 array('shape' => 'circle', 'coords' => '195,180;10', 'choice' => 2), 176 array('shape' => 'circle', 'coords' => '267,302;10', 'choice' => 2), 177 ); 178 179 test_question_maker::set_standard_combined_feedback_form_data($fromform); 180 181 $fromform->penalty = '0.3333333'; 182 $fromform->hint = array( 183 array( 184 'text' => 'You are trying to place four markers on the map.', 185 'format' => FORMAT_HTML, 186 ), 187 array( 188 'text' => 'You are trying to mark three railway stations.', 189 'format' => FORMAT_HTML, 190 ), 191 ); 192 $fromform->hintshownumcorrect = array(1, 1); 193 $fromform->hintclearwrong = array(0, 1); 194 $fromform->hintoptions = array(0, 1); 195 196 $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 197 198 return $fromform; 199 } 200 201 /** 202 * Return the test data needed by the question generator (the data that 203 * would come from saving the editing form). 204 * @return stdClass date to create a ddmarkers question where one of the drag items has text '0'. 205 */ 206 public function get_ddmarker_question_form_data_zerodrag() { 207 global $CFG, $USER; 208 $fromform = new stdClass(); 209 210 $bgdraftitemid = 0; 211 file_prepare_draft_area($bgdraftitemid, null, null, null, null); 212 $fs = get_file_storage(); 213 $filerecord = new stdClass(); 214 $filerecord->contextid = context_user::instance($USER->id)->id; 215 $filerecord->component = 'user'; 216 $filerecord->filearea = 'draft'; 217 $filerecord->itemid = $bgdraftitemid; 218 $filerecord->filepath = '/'; 219 $filerecord->filename = 'mkmap.png'; 220 $fs->create_file_from_pathname($filerecord, $CFG->dirroot . 221 '/question/type/ddmarker/tests/fixtures/mkmap.png'); 222 223 $fromform->name = 'Drag digits'; 224 $fromform->questiontext = array( 225 'text' => 'Put 0 in the left of the image, and 1 in the right.', 226 'format' => FORMAT_HTML, 227 ); 228 $fromform->defaultmark = 2; 229 $fromform->generalfeedback = array( 230 'text' => '', 231 'format' => FORMAT_HTML, 232 ); 233 $fromform->bgimage = $bgdraftitemid; 234 $fromform->shuffleanswers = 0; 235 236 $fromform->drags = array( 237 array('label' => '0', 'noofdrags' => 1), 238 array('label' => '1', 'noofdrags' => 1), 239 ); 240 241 $fromform->drops = array( 242 array('shape' => 'Rectangle', 'coords' => '0,0;272,389', 'choice' => 1), 243 array('shape' => 'Rectangle', 'coords' => '272,0;272,389', 'choice' => 2), 244 ); 245 246 test_question_maker::set_standard_combined_feedback_form_data($fromform); 247 248 $fromform->penalty = '0.3333333'; 249 $fromform->hint = array( 250 array( 251 'text' => 'Hint 1.', 252 'format' => FORMAT_HTML, 253 ), 254 array( 255 'text' => 'Hint 2.', 256 'format' => FORMAT_HTML, 257 ), 258 ); 259 $fromform->hintshownumcorrect = array(1, 1); 260 $fromform->hintclearwrong = array(0, 1); 261 $fromform->hintoptions = array(0, 1); 262 263 $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; 264 265 return $fromform; 266 } 267 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body