MDL-70153 qtype_essay: Add behat test for attachments max size
[moodle.git] / question / type / ddimageortext / tests / helper.php
CommitLineData
a2bb148a 1<?php
a2bb148a
TH
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
5b4602d2 17/**
c109c901 18 * Test helpers for the drag-and-drop onto image question type.
5b4602d2 19 *
c109c901 20 * @package qtype_ddimageortext
5b4602d2
TH
21 * @copyright 2010 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
a2bb148a 25
42536280
TH
26defined('MOODLE_INTERNAL') || die();
27
28
a2bb148a 29/**
c109c901 30 * Test helper class for the drag-and-drop onto image question type.
a2bb148a 31 *
5b4602d2
TH
32 * @copyright 2010 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a2bb148a 34 */
31077627 35class qtype_ddimageortext_test_helper extends question_test_helper {
46b0a973 36 public function get_test_questions() {
096a5b99 37 return array('fox', 'maths', 'xsection', 'mixedlang');
46b0a973
TH
38 }
39
a2bb148a 40 /**
31077627 41 * @return qtype_ddimageortext_question
a2bb148a 42 */
31077627
JP
43 public function make_ddimageortext_question_fox() {
44 question_bank::load_question_definition_classes('ddimageortext');
45 $dd = new qtype_ddimageortext_question();
a2bb148a
TH
46
47 test_question_maker::initialise_a_question($dd);
48
c109c901 49 $dd->name = 'Drag-and-drop onto image question';
bfe79134 50 $dd->questiontext = 'The quick brown fox jumped over the lazy dog.';
a2bb148a 51 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
31077627 52 $dd->qtype = question_bank::get_qtype('ddimageortext');
a2bb148a
TH
53
54 $dd->shufflechoices = true;
55
56 test_question_maker::set_standard_combined_feedback_fields($dd);
57
bfe79134 58 $dd->choices = $this->make_choice_structure(array(
31077627
JP
59 new qtype_ddimageortext_drag_item('quick', 1, 1),
60 new qtype_ddimageortext_drag_item('fox', 2, 1),
2bf2e46c
TH
61 new qtype_ddimageortext_drag_item('lazy', 3, 2),
62 new qtype_ddimageortext_drag_item('dog', 4, 2)
bfe79134
JP
63
64 ));
65
66 $dd->places = $this->make_place_structure(array(
31077627
JP
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)
bfe79134 71 ));
2bf2e46c 72 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 4);
a2bb148a
TH
73
74 return $dd;
75 }
76
bfe79134
JP
77 protected function make_choice_structure($choices) {
78 $choicestructure = array();
79 foreach ($choices as $choice) {
80 if (!isset($choicestructure[$choice->group])) {
2bf2e46c
TH
81 $choicestructure[$choice->group][1] = $choice;
82 } else {
83 $choicestructure[$choice->group][$choice->no] = $choice;
bfe79134 84 }
bfe79134
JP
85 }
86 return $choicestructure;
87 }
88
89 protected function make_place_structure($places) {
90 $placestructure = array();
91 foreach ($places as $place) {
92 $placestructure[$place->no] = $place;
93 }
94 return $placestructure;
95 }
96
a2bb148a 97 /**
8bc1d28b
EM
98 * Make a mathematical ddimageortext question.
99 *
31077627 100 * @return qtype_ddimageortext_question
a2bb148a 101 */
31077627
JP
102 public function make_ddimageortext_question_maths() {
103 question_bank::load_question_definition_classes('ddimageortext');
104 $dd = new qtype_ddimageortext_question();
a2bb148a
TH
105
106 test_question_maker::initialise_a_question($dd);
107
c109c901 108 $dd->name = 'Drag-and-drop onto image question';
a2bb148a
TH
109 $dd->questiontext = 'Fill in the operators to make this equation work: ' .
110 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
111 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
31077627 112 $dd->qtype = question_bank::get_qtype('ddimageortext');
a2bb148a
TH
113
114 $dd->shufflechoices = true;
115
116 test_question_maker::set_standard_combined_feedback_fields($dd);
117
bfe79134 118 $dd->choices = $this->make_choice_structure(array(
31077627
JP
119 new qtype_ddimageortext_drag_item('+', 1, 1),
120 new qtype_ddimageortext_drag_item('-', 2, 1)
bfe79134
JP
121 ));
122
123 $dd->places = $this->make_place_structure(array(
31077627
JP
124 new qtype_ddimageortext_drop_zone('', 1, 1),
125 new qtype_ddimageortext_drop_zone('', 2, 1),
126 new qtype_ddimageortext_drop_zone('', 3, 1),
127 new qtype_ddimageortext_drop_zone('', 4, 1)
bfe79134 128 ));
a2bb148a 129 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
a2bb148a
TH
130
131 return $dd;
132 }
42865c84
TH
133
134 /**
135 * @return stdClass date to create a ddimageortext question.
136 */
137 public function get_ddimageortext_question_form_data_xsection() {
138 global $CFG, $USER;
139 $fromform = new stdClass();
140
141 $bgdraftitemid = 0;
142 file_prepare_draft_area($bgdraftitemid, null, null, null, null);
143 $fs = get_file_storage();
144 $filerecord = new stdClass();
145 $filerecord->contextid = context_user::instance($USER->id)->id;
146 $filerecord->component = 'user';
147 $filerecord->filearea = 'draft';
148 $filerecord->itemid = $bgdraftitemid;
149 $filerecord->filepath = '/';
150 $filerecord->filename = 'oceanfloorbase.jpg';
151 $fs->create_file_from_pathname($filerecord, $CFG->dirroot .
152 '/question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg');
153
154 $fromform->name = 'Geography cross-section';
155 $fromform->questiontext = array(
156 'text' => '<p>Identify the features in this cross-section by dragging the labels into the boxes.</p>
8bc1d28b
EM
157 <p><em>Use the mouse to drag the boxed words into the empty boxes. '.
158 'Alternatively, use the tab key to select an empty box, '.
159 'then use the space key to cycle through the options.</em></p>',
42865c84
TH
160 'format' => FORMAT_HTML,
161 );
162 $fromform->defaultmark = 1;
163 $fromform->generalfeedback = array(
8bc1d28b
EM
164 'text' => '<p>More information about the major features of the Earth\'s surface '.
165 'can be found in Block 3, Section 6.2.</p>',
42865c84
TH
166 'format' => FORMAT_HTML,
167 );
168 $fromform->bgimage = $bgdraftitemid;
169 $fromform->shuffleanswers = 0;
170 $fromform->drags = array(
171 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
172 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
173 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
174 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
175 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
176 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
177 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
178 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
179 );
180 $fromform->dragitem = array(0, 0, 0, 0, 0, 0, 0, 0);
181 $fromform->draglabel =
182 array(
183 'island<br/>arc',
184 'mid-ocean<br/>ridge',
185 'abyssal<br/>plain',
186 'continental<br/>rise',
187 'ocean<br/>trench',
188 'continental<br/>slope',
189 'mountain<br/>belt',
190 'continental<br/>shelf',
191 );
192 $fromform->drops = array(
193 array('xleft' => '53', 'ytop' => '17', 'choice' => '7', 'droplabel' => ''),
194 array('xleft' => '172', 'ytop' => '2', 'choice' => '8', 'droplabel' => ''),
195 array('xleft' => '363', 'ytop' => '31', 'choice' => '5', 'droplabel' => ''),
196 array('xleft' => '440', 'ytop' => '13', 'choice' => '3', 'droplabel' => ''),
197 array('xleft' => '115', 'ytop' => '74', 'choice' => '6', 'droplabel' => ''),
198 array('xleft' => '210', 'ytop' => '94', 'choice' => '4', 'droplabel' => ''),
199 array('xleft' => '310', 'ytop' => '87', 'choice' => '1', 'droplabel' => ''),
200 array('xleft' => '479', 'ytop' => '84', 'choice' => '2', 'droplabel' => ''),
201 );
202
203 test_question_maker::set_standard_combined_feedback_form_data($fromform);
204
8bc1d28b 205 $fromform->penalty = '0.3333333';
42865c84
TH
206 $fromform->hint = array(
207 array(
208 'text' => '<p>Incorrect placements will be removed.</p>',
209 'format' => FORMAT_HTML,
210 ),
211 array(
212 'text' => '<ul>
8bc1d28b
EM
213 <li>The abyssal plain is a flat almost featureless expanse of ocean '.
214 'floor 4km to 6km below sea-level.</li>
42865c84
TH
215 <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
216 <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
8bc1d28b
EM
217 <li>The continental slope is the relatively steep part of the ocean floor '.
218 'beyond the continental shelf.</li>
42865c84
TH
219 <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
220 <li>A mountain belt is a long range of mountains.</li>
221 <li>An island arc is a chain of volcanic islands.</li>
222 <li>An oceanic trench is a deep trough in the ocean floor.</li>
223 </ul>',
224 'format' => FORMAT_HTML,
225 ),
226 array(
227 'text' => '<p>Incorrect placements will be removed.</p>',
228 'format' => FORMAT_HTML,
229 ),
230 array(
231 'text' => '<ul>
8bc1d28b
EM
232 <li>The abyssal plain is a flat almost featureless expanse of ocean '.
233 'floor 4km to 6km below sea-level.</li>
42865c84
TH
234 <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
235 <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
8bc1d28b
EM
236 <li>The continental slope is the relatively steep part of the ocean floor '.
237 'beyond the continental shelf.</li>
42865c84
TH
238 <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
239 <li>A mountain belt is a long range of mountains.</li>
240 <li>An island arc is a chain of volcanic islands.</li>
241 <li>An oceanic trench is a deep trough in the ocean floor.</li>
242 </ul>',
243 'format' => FORMAT_HTML,
244 ),
245 );
246 $fromform->hintclearwrong = array(1, 0, 1, 0);
247 $fromform->hintshownumcorrect = array(1, 1, 1, 1);
248
249 return $fromform;
250 }
096a5b99
TH
251
252 /**
253 * Make a test question where the drag items are a different language than the main question text.
254 *
255 * @return qtype_ddimageortext_question
256 */
257 public function make_ddimageortext_question_mixedlang() {
258 question_bank::load_question_definition_classes('ddimageortext');
259 $dd = new qtype_ddimageortext_question();
260
261 test_question_maker::initialise_a_question($dd);
262
263 $dd->name = 'Question about French in English.';
264 $dd->questiontext = '<p>Complete the blanks in this sentence.</p>' .
265 '<p lang="fr">J\'ai perdu [[1]] plume de [[2]] tante - l\'avez-vous vue?</p>';
266 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
267 $dd->qtype = question_bank::get_qtype('ddimageortext');
268
269 $dd->shufflechoices = true;
270
271 test_question_maker::set_standard_combined_feedback_fields($dd);
272
273 $dd->choices = $this->make_choice_structure(array(
274 new qtype_ddimageortext_drag_item('<span lang="fr">la</span>', 1, 1),
275 new qtype_ddimageortext_drag_item('<span lang="fr">ma</span>', 2, 1),
276 ));
277
278 $dd->places = $this->make_place_structure(array(
279 new qtype_ddimageortext_drop_zone('', 1, 1),
280 new qtype_ddimageortext_drop_zone('', 2, 1)
281 ));
282 $dd->rightchoices = array(1 => 1, 2 => 2);
283
284 return $dd;
285 }
a2bb148a 286}