2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Test helpers for the drag-and-drop onto image question type.
20 * @package qtype_ddimageortext
21 * @copyright 2010 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
30 * Test helper class for the drag-and-drop onto image question type.
32 * @copyright 2010 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class qtype_ddimageortext_test_helper extends question_test_helper {
36 public function get_test_questions() {
37 return array('fox', 'maths', 'xsection');
41 * @return qtype_ddimageortext_question
43 public function make_ddimageortext_question_fox() {
44 question_bank::load_question_definition_classes('ddimageortext');
45 $dd = new qtype_ddimageortext_question();
47 test_question_maker::initialise_a_question($dd);
49 $dd->name = 'Drag-and-drop onto image question';
50 $dd->questiontext = 'The quick brown fox jumped over the lazy dog.';
51 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
52 $dd->qtype = question_bank::get_qtype('ddimageortext');
54 $dd->shufflechoices = true;
56 test_question_maker::set_standard_combined_feedback_fields($dd);
58 $dd->choices = $this->make_choice_structure(array(
59 new qtype_ddimageortext_drag_item('quick', 1, 1),
60 new qtype_ddimageortext_drag_item('fox', 2, 1),
61 new qtype_ddimageortext_drag_item('lazy', 1, 2),
62 new qtype_ddimageortext_drag_item('dog', 2, 2)
66 $dd->places = $this->make_place_structure(array(
67 new qtype_ddimageortext_drop_zone('', 1, 1),
68 new qtype_ddimageortext_drop_zone('', 2, 1),
69 new qtype_ddimageortext_drop_zone('', 3, 2),
70 new qtype_ddimageortext_drop_zone('', 4, 2)
72 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
77 protected function make_choice_structure($choices) {
78 $choicestructure = array();
79 foreach ($choices as $choice) {
80 if (!isset($choicestructure[$choice->group])) {
81 $choicestructure[$choice->group] = array();
83 $choicestructure[$choice->group][$choice->no] = $choice;
85 return $choicestructure;
88 protected function make_place_structure($places) {
89 $placestructure = array();
90 foreach ($places as $place) {
91 $placestructure[$place->no] = $place;
93 return $placestructure;
97 * @return qtype_ddimageortext_question
99 public function make_ddimageortext_question_maths() {
100 question_bank::load_question_definition_classes('ddimageortext');
101 $dd = new qtype_ddimageortext_question();
103 test_question_maker::initialise_a_question($dd);
105 $dd->name = 'Drag-and-drop onto image question';
106 $dd->questiontext = 'Fill in the operators to make this equation work: ' .
107 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
108 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
109 $dd->qtype = question_bank::get_qtype('ddimageortext');
111 $dd->shufflechoices = true;
113 test_question_maker::set_standard_combined_feedback_fields($dd);
115 $dd->choices = $this->make_choice_structure(array(
116 new qtype_ddimageortext_drag_item('+', 1, 1),
117 new qtype_ddimageortext_drag_item('-', 2, 1)
120 $dd->places = $this->make_place_structure(array(
121 new qtype_ddimageortext_drop_zone('', 1, 1),
122 new qtype_ddimageortext_drop_zone('', 2, 1),
123 new qtype_ddimageortext_drop_zone('', 3, 1),
124 new qtype_ddimageortext_drop_zone('', 4, 1)
126 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
132 * @return stdClass date to create a ddimageortext question.
134 public function get_ddimageortext_question_form_data_xsection() {
136 $fromform = new stdClass();
139 file_prepare_draft_area($bgdraftitemid, null, null, null, null);
140 $fs = get_file_storage();
141 $filerecord = new stdClass();
142 $filerecord->contextid = context_user::instance($USER->id)->id;
143 $filerecord->component = 'user';
144 $filerecord->filearea = 'draft';
145 $filerecord->itemid = $bgdraftitemid;
146 $filerecord->filepath = '/';
147 $filerecord->filename = 'oceanfloorbase.jpg';
148 $fs->create_file_from_pathname($filerecord, $CFG->dirroot .
149 '/question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg');
151 $fromform->name = 'Geography cross-section';
152 $fromform->questiontext = array(
153 'text' => '<p>Identify the features in this cross-section by dragging the labels into the boxes.</p>
154 <p><em>Use the mouse to drag the boxed words into the empty boxes. Alternatively, use the tab key to select an empty box, then use the space key to cycle through the options.</em></p>',
155 'format' => FORMAT_HTML,
157 $fromform->defaultmark = 1;
158 $fromform->generalfeedback = array(
159 'text' => '<p>More information about the major features of the Earth\'s surface can be found in Block 3, Section 6.2.</p>',
160 'format' => FORMAT_HTML,
162 $fromform->bgimage = $bgdraftitemid;
163 $fromform->shuffleanswers = 0;
164 $fromform->drags = array(
165 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
166 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
167 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
168 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
169 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
170 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
171 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
172 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
174 $fromform->dragitem = array(0, 0, 0, 0, 0, 0, 0, 0);
175 $fromform->draglabel =
178 'mid-ocean<br/>ridge',
180 'continental<br/>rise',
182 'continental<br/>slope',
184 'continental<br/>shelf',
186 $fromform->drops = array(
187 array('xleft' => '53', 'ytop' => '17', 'choice' => '7', 'droplabel' => ''),
188 array('xleft' => '172', 'ytop' => '2', 'choice' => '8', 'droplabel' => ''),
189 array('xleft' => '363', 'ytop' => '31', 'choice' => '5', 'droplabel' => ''),
190 array('xleft' => '440', 'ytop' => '13', 'choice' => '3', 'droplabel' => ''),
191 array('xleft' => '115', 'ytop' => '74', 'choice' => '6', 'droplabel' => ''),
192 array('xleft' => '210', 'ytop' => '94', 'choice' => '4', 'droplabel' => ''),
193 array('xleft' => '310', 'ytop' => '87', 'choice' => '1', 'droplabel' => ''),
194 array('xleft' => '479', 'ytop' => '84', 'choice' => '2', 'droplabel' => ''),
197 test_question_maker::set_standard_combined_feedback_form_data($fromform);
199 $fromform->penalty ='0.3333333';
200 $fromform->hint = array(
202 'text' => '<p>Incorrect placements will be removed.</p>',
203 'format' => FORMAT_HTML,
207 <li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
208 <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
209 <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
210 <li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
211 <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
212 <li>A mountain belt is a long range of mountains.</li>
213 <li>An island arc is a chain of volcanic islands.</li>
214 <li>An oceanic trench is a deep trough in the ocean floor.</li>
216 'format' => FORMAT_HTML,
219 'text' => '<p>Incorrect placements will be removed.</p>',
220 'format' => FORMAT_HTML,
224 <li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
225 <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
226 <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
227 <li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
228 <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
229 <li>A mountain belt is a long range of mountains.</li>
230 <li>An island arc is a chain of volcanic islands.</li>
231 <li>An oceanic trench is a deep trough in the ocean floor.</li>
233 'format' => FORMAT_HTML,
236 $fromform->hintclearwrong = array(1, 0, 1, 0);
237 $fromform->hintshownumcorrect = array(1, 1, 1, 1);