Commit | Line | Data |
---|---|---|
c7b2d1fb JP |
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 | * Unit tests for the drag-and-drop onto image question type. | |
19 | * | |
20 | * @package qtype_ddimageortext | |
21 | * @copyright 2010 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 | global $CFG; | |
29 | require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); | |
30 | require_once($CFG->dirroot . '/question/type/ddimageortext/tests/helper.php'); | |
31 | ||
32 | ||
33 | /** | |
34 | * Unit tests for the drag-and-drop onto image question type. | |
35 | * | |
36 | * @copyright 2010 The Open University | |
37 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
38 | * @group qtype_ddimageortext | |
39 | */ | |
40 | class qtype_ddimageortext_walkthrough_test extends qbehaviour_walkthrough_test_base { | |
41 | ||
42 | protected function get_contains_drag_image_home_expectation($dragitemno, $choice, $group) { | |
43 | $class = 'group' . $group; | |
44 | $class .= ' draghome dragitemhomes' . $dragitemno. ' choice'.$choice.' yui3-cssfonts'; | |
45 | ||
46 | $expectedattrs = array(); | |
47 | $expectedattrs['class'] = $class; | |
48 | ||
49 | return new question_contains_tag_with_attributes('div', $expectedattrs); | |
50 | } | |
51 | ||
52 | public function test_interactive_behaviour() { | |
53 | ||
54 | // Create a drag-and-drop question. | |
55 | $dd = test_question_maker::make_question('ddimageortext'); | |
56 | $dd->hints = array( | |
57 | new question_hint_with_parts(13, 'This is the first hint.', FORMAT_HTML, false, false), | |
58 | new question_hint_with_parts(14, 'This is the second hint.', FORMAT_HTML, true, true), | |
59 | ); | |
60 | $dd->shufflechoices = false; | |
61 | $this->start_attempt_at_question($dd, 'interactive', 12); | |
62 | ||
63 | // Check the initial state. | |
64 | $this->check_current_state(question_state::$todo); | |
65 | $this->check_current_mark(null); | |
66 | ||
67 | $this->check_current_output( | |
68 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
69 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
70 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
71 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
72 | $this->get_contains_hidden_expectation( | |
73 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
74 | $this->get_contains_hidden_expectation( | |
75 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
76 | $this->get_contains_hidden_expectation( | |
77 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
78 | $this->get_contains_hidden_expectation( | |
79 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
80 | $this->get_contains_submit_button_expectation(true), | |
81 | $this->get_does_not_contain_feedback_expectation(), | |
82 | $this->get_tries_remaining_expectation(3), | |
83 | $this->get_no_hint_visible_expectation()); | |
84 | ||
85 | // Save the wrong answer. | |
86 | $this->process_submission(array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1')); | |
87 | // Verify. | |
88 | $this->check_current_state(question_state::$todo); | |
89 | $this->check_current_mark(null); | |
90 | ||
91 | $this->check_current_output( | |
92 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
93 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
94 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
95 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
96 | $this->get_contains_hidden_expectation( | |
97 | $this->quba->get_field_prefix($this->slot) . 'p1', 2), | |
98 | $this->get_contains_hidden_expectation( | |
99 | $this->quba->get_field_prefix($this->slot) . 'p2', 1), | |
100 | $this->get_contains_hidden_expectation( | |
101 | $this->quba->get_field_prefix($this->slot) . 'p3', 2), | |
102 | $this->get_contains_hidden_expectation( | |
103 | $this->quba->get_field_prefix($this->slot) . 'p4', 1), | |
104 | $this->get_contains_submit_button_expectation(true), | |
105 | $this->get_does_not_contain_feedback_expectation(), | |
106 | $this->get_tries_remaining_expectation(3), | |
107 | $this->get_no_hint_visible_expectation()); | |
108 | // Submit the wrong answer. | |
109 | $this->process_submission( | |
110 | array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1', '-submit' => 1)); | |
111 | ||
112 | // Verify. | |
113 | $this->check_current_state(question_state::$todo); | |
114 | $this->check_current_mark(null); | |
115 | $this->check_current_output( | |
116 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
117 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
118 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
119 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
120 | $this->get_contains_hidden_expectation( | |
121 | $this->quba->get_field_prefix($this->slot) . 'p1', 2), | |
122 | $this->get_contains_hidden_expectation( | |
123 | $this->quba->get_field_prefix($this->slot) . 'p2', 1), | |
124 | $this->get_contains_hidden_expectation( | |
125 | $this->quba->get_field_prefix($this->slot) . 'p3', 2), | |
126 | $this->get_contains_hidden_expectation( | |
127 | $this->quba->get_field_prefix($this->slot) . 'p4', 1), | |
128 | $this->get_contains_try_again_button_expectation(true), | |
129 | new question_pattern_expectation('/' . | |
130 | preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'), | |
131 | $this->get_contains_hint_expectation('This is the first hint')); | |
132 | ||
133 | // Do try again. | |
134 | $this->process_submission(array('-tryagain' => 1)); | |
135 | ||
136 | // Verify. | |
137 | $this->check_current_state(question_state::$todo); | |
138 | $this->check_current_mark(null); | |
139 | ||
140 | $this->check_current_output( | |
141 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
142 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
143 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
144 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
145 | $this->get_contains_hidden_expectation( | |
146 | $this->quba->get_field_prefix($this->slot) . 'p1', '2'), | |
147 | $this->get_contains_hidden_expectation( | |
148 | $this->quba->get_field_prefix($this->slot) . 'p2', '1'), | |
149 | $this->get_contains_hidden_expectation( | |
150 | $this->quba->get_field_prefix($this->slot) . 'p3', '2'), | |
151 | $this->get_contains_hidden_expectation( | |
152 | $this->quba->get_field_prefix($this->slot) . 'p4', '1'), | |
153 | $this->get_contains_submit_button_expectation(true), | |
154 | $this->get_does_not_contain_correctness_expectation(), | |
155 | $this->get_does_not_contain_feedback_expectation(), | |
156 | $this->get_tries_remaining_expectation(2), | |
157 | $this->get_no_hint_visible_expectation()); | |
158 | ||
159 | // Submit the right answer. | |
160 | $this->process_submission( | |
161 | array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2', '-submit' => 1)); | |
162 | ||
163 | // Verify. | |
164 | $this->check_current_state(question_state::$gradedright); | |
165 | $this->check_current_mark(8); | |
166 | $this->check_current_output( | |
167 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
168 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
169 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
170 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
171 | $this->get_contains_hidden_expectation( | |
172 | $this->quba->get_field_prefix($this->slot) . 'p1', '1'), | |
173 | $this->get_contains_hidden_expectation( | |
174 | $this->quba->get_field_prefix($this->slot) . 'p2', '2'), | |
175 | $this->get_contains_hidden_expectation( | |
176 | $this->quba->get_field_prefix($this->slot) . 'p3', '1'), | |
177 | $this->get_contains_hidden_expectation( | |
178 | $this->quba->get_field_prefix($this->slot) . 'p4', '2'), | |
179 | $this->get_contains_submit_button_expectation(false), | |
180 | $this->get_contains_correct_expectation(), | |
181 | $this->get_no_hint_visible_expectation()); | |
182 | ||
183 | // Check regrading does not mess anything up. | |
184 | $this->quba->regrade_all_questions(); | |
185 | ||
186 | // Verify. | |
187 | $this->check_current_state(question_state::$gradedright); | |
188 | $this->check_current_mark(8); | |
189 | } | |
190 | ||
191 | public function test_deferred_feedback() { | |
192 | ||
193 | // Create a drag-and-drop question. | |
194 | $dd = test_question_maker::make_question('ddimageortext'); | |
195 | $dd->shufflechoices = false; | |
196 | $this->start_attempt_at_question($dd, 'deferredfeedback', 12); | |
197 | ||
198 | // Check the initial state. | |
199 | $this->check_current_state(question_state::$todo); | |
200 | $this->check_current_mark(null); | |
201 | ||
202 | $this->check_current_output( | |
203 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
204 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
205 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
206 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
207 | $this->get_contains_hidden_expectation( | |
208 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
209 | $this->get_contains_hidden_expectation( | |
210 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
211 | $this->get_contains_hidden_expectation( | |
212 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
213 | $this->get_contains_hidden_expectation( | |
214 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
215 | $this->get_does_not_contain_feedback_expectation()); | |
216 | ||
217 | // Save a partial answer. | |
218 | $this->process_submission(array('p1' => '2', 'p2' => '1')); | |
219 | // Verify. | |
220 | $this->check_current_state(question_state::$invalid); | |
221 | $this->check_current_mark(null); | |
222 | ||
223 | $this->check_current_output( | |
224 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
225 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
226 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
227 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
228 | $this->get_contains_hidden_expectation( | |
229 | $this->quba->get_field_prefix($this->slot) . 'p1', 2), | |
230 | $this->get_contains_hidden_expectation( | |
231 | $this->quba->get_field_prefix($this->slot) . 'p2', 1), | |
232 | $this->get_contains_hidden_expectation( | |
233 | $this->quba->get_field_prefix($this->slot) . 'p3', ''), | |
234 | $this->get_contains_hidden_expectation( | |
235 | $this->quba->get_field_prefix($this->slot) . 'p4', ''), | |
236 | $this->get_does_not_contain_correctness_expectation(), | |
237 | $this->get_does_not_contain_feedback_expectation()); | |
238 | // Save the right answer. | |
239 | $this->process_submission( | |
240 | array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')); | |
241 | ||
242 | // Verify. | |
243 | $this->check_current_state(question_state::$complete); | |
244 | $this->check_current_mark(null); | |
245 | $this->check_current_output( | |
246 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
247 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
248 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
249 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
250 | $this->get_contains_hidden_expectation( | |
251 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
252 | $this->get_contains_hidden_expectation( | |
253 | $this->quba->get_field_prefix($this->slot) . 'p2', 2), | |
254 | $this->get_contains_hidden_expectation( | |
255 | $this->quba->get_field_prefix($this->slot) . 'p3', 1), | |
256 | $this->get_contains_hidden_expectation( | |
257 | $this->quba->get_field_prefix($this->slot) . 'p4', 2), | |
258 | $this->get_does_not_contain_correctness_expectation(), | |
259 | $this->get_does_not_contain_feedback_expectation()); | |
260 | ||
261 | // Finish the attempt. | |
262 | $this->quba->finish_all_questions(); | |
263 | ||
264 | // Verify. | |
265 | $this->check_current_state(question_state::$gradedright); | |
266 | $this->check_current_mark(12); | |
267 | ||
268 | $this->check_current_output( | |
269 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
270 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
271 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
272 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
273 | $this->get_contains_hidden_expectation( | |
274 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
275 | $this->get_contains_hidden_expectation( | |
276 | $this->quba->get_field_prefix($this->slot) . 'p2', 2), | |
277 | $this->get_contains_hidden_expectation( | |
278 | $this->quba->get_field_prefix($this->slot) . 'p3', 1), | |
279 | $this->get_contains_hidden_expectation( | |
280 | $this->quba->get_field_prefix($this->slot) . 'p4', 2), | |
281 | $this->get_contains_correct_expectation()); | |
282 | ||
283 | // Change the right answer a bit. | |
284 | $dd->rightchoices[2] = 1; | |
285 | ||
286 | // Check regrading does not mess anything up. | |
287 | $this->quba->regrade_all_questions(); | |
288 | ||
289 | // Verify. | |
290 | $this->check_current_state(question_state::$gradedpartial); | |
291 | $this->check_current_mark(9); | |
292 | } | |
293 | ||
294 | public function test_deferred_feedback_unanswered() { | |
295 | ||
296 | // Create a drag-and-drop question. | |
297 | $dd = test_question_maker::make_question('ddimageortext'); | |
298 | $dd->shufflechoices = false; | |
299 | $this->start_attempt_at_question($dd, 'deferredfeedback', 12); | |
300 | ||
301 | // Check the initial state. | |
302 | $this->check_current_state(question_state::$todo); | |
303 | $this->check_current_mark(null); | |
304 | $this->check_current_output( | |
305 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
306 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
307 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
308 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
309 | $this->get_contains_hidden_expectation( | |
310 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
311 | $this->get_contains_hidden_expectation( | |
312 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
313 | $this->get_contains_hidden_expectation( | |
314 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
315 | $this->get_contains_hidden_expectation( | |
316 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
317 | $this->get_does_not_contain_correctness_expectation(), | |
318 | $this->get_does_not_contain_feedback_expectation()); | |
319 | $this->check_step_count(1); | |
320 | ||
321 | // Save a blank response. | |
322 | $this->process_submission(array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => '')); | |
323 | ||
324 | // Verify. | |
325 | $this->check_current_state(question_state::$todo); | |
326 | $this->check_current_mark(null); | |
327 | $this->check_current_output( | |
328 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
329 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
330 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
331 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
332 | $this->get_contains_hidden_expectation( | |
333 | $this->quba->get_field_prefix($this->slot) . 'p1', ''), | |
334 | $this->get_contains_hidden_expectation( | |
335 | $this->quba->get_field_prefix($this->slot) . 'p2', ''), | |
336 | $this->get_contains_hidden_expectation( | |
337 | $this->quba->get_field_prefix($this->slot) . 'p3', ''), | |
338 | $this->get_contains_hidden_expectation( | |
339 | $this->quba->get_field_prefix($this->slot) . 'p4', ''), | |
340 | $this->get_does_not_contain_correctness_expectation(), | |
341 | $this->get_does_not_contain_feedback_expectation()); | |
342 | $this->check_step_count(1); | |
343 | ||
344 | // Finish the attempt. | |
345 | $this->quba->finish_all_questions(); | |
346 | ||
347 | // Verify. | |
348 | $this->check_current_state(question_state::$gaveup); | |
349 | $this->check_current_mark(null); | |
350 | $this->check_current_output( | |
351 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
352 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
353 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
354 | $this->get_contains_drag_image_home_expectation(2, 2, 2)); | |
355 | } | |
356 | ||
357 | public function test_deferred_feedback_partial_answer() { | |
358 | ||
359 | // Create a drag-and-drop question. | |
360 | $dd = test_question_maker::make_question('ddimageortext'); | |
361 | $dd->shufflechoices = false; | |
362 | $this->start_attempt_at_question($dd, 'deferredfeedback', 3); | |
363 | ||
364 | // Check the initial state. | |
365 | $this->check_current_state(question_state::$todo); | |
366 | $this->check_current_mark(null); | |
367 | $this->check_current_output( | |
368 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
369 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
370 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
371 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
372 | $this->get_contains_hidden_expectation( | |
373 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
374 | $this->get_contains_hidden_expectation( | |
375 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
376 | $this->get_contains_hidden_expectation( | |
377 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
378 | $this->get_contains_hidden_expectation( | |
379 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
380 | $this->get_does_not_contain_correctness_expectation(), | |
381 | $this->get_does_not_contain_feedback_expectation()); | |
382 | ||
383 | // Save a partial response. | |
384 | $this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '', 'p4' => '')); | |
385 | ||
386 | // Verify. | |
387 | $this->check_current_state(question_state::$invalid); | |
388 | $this->check_current_mark(null); | |
389 | $this->check_current_output( | |
390 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
391 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
392 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
393 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
394 | $this->get_contains_hidden_expectation( | |
395 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
396 | $this->get_contains_hidden_expectation( | |
397 | $this->quba->get_field_prefix($this->slot) . 'p2', 2), | |
398 | $this->get_contains_hidden_expectation( | |
399 | $this->quba->get_field_prefix($this->slot) . 'p3', ''), | |
400 | $this->get_contains_hidden_expectation( | |
401 | $this->quba->get_field_prefix($this->slot) . 'p4', ''), | |
402 | $this->get_does_not_contain_correctness_expectation(), | |
403 | $this->get_does_not_contain_feedback_expectation()); | |
404 | ||
405 | // Finish the attempt. | |
406 | $this->quba->finish_all_questions(); | |
407 | ||
408 | // Verify. | |
409 | $this->check_current_state(question_state::$gradedpartial); | |
410 | $this->check_current_mark(1.5); | |
411 | $this->check_current_output( | |
412 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
413 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
414 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
415 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
416 | $this->get_contains_partcorrect_expectation()); | |
417 | } | |
418 | ||
419 | public function test_interactive_grading() { | |
420 | ||
421 | // Create a drag-and-drop question. | |
422 | $dd = test_question_maker::make_question('ddimageortext'); | |
423 | $dd->hints = array( | |
424 | new question_hint_with_parts(1, 'This is the first hint.', | |
425 | FORMAT_MOODLE, true, true), | |
426 | new question_hint_with_parts(2, 'This is the second hint.', | |
427 | FORMAT_MOODLE, true, true), | |
428 | ); | |
429 | $dd->shufflechoices = false; | |
430 | $this->start_attempt_at_question($dd, 'interactive', 12); | |
431 | ||
432 | // Check the initial state. | |
433 | $this->check_current_state(question_state::$todo); | |
434 | $this->check_current_mark(null); | |
435 | $this->assertEquals('interactivecountback', | |
436 | $this->quba->get_question_attempt($this->slot)->get_behaviour_name()); | |
437 | $this->check_current_output( | |
438 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
439 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
440 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
441 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
442 | $this->get_contains_hidden_expectation( | |
443 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
444 | $this->get_contains_hidden_expectation( | |
445 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
446 | $this->get_contains_hidden_expectation( | |
447 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
448 | $this->get_contains_hidden_expectation( | |
449 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
450 | $this->get_contains_submit_button_expectation(true), | |
451 | $this->get_does_not_contain_feedback_expectation(), | |
452 | $this->get_tries_remaining_expectation(3), | |
453 | $this->get_does_not_contain_num_parts_correct(), | |
454 | $this->get_no_hint_visible_expectation()); | |
455 | ||
456 | // Submit an response with the first two parts right. | |
457 | $this->process_submission( | |
458 | array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '1', '-submit' => 1)); | |
459 | ||
460 | // Verify. | |
461 | $this->check_current_state(question_state::$todo); | |
462 | $this->check_current_mark(null); | |
463 | $this->check_current_output( | |
464 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
465 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
466 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
467 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
468 | $this->get_contains_submit_button_expectation(false), | |
469 | $this->get_contains_try_again_button_expectation(true), | |
470 | $this->get_does_not_contain_correctness_expectation(), | |
471 | new question_pattern_expectation('/' . | |
472 | preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'), | |
473 | $this->get_contains_hint_expectation('This is the first hint'), | |
474 | $this->get_contains_num_parts_correct(2), | |
475 | $this->get_contains_standard_partiallycorrect_combined_feedback_expectation(), | |
476 | $this->get_contains_hidden_expectation( | |
477 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
478 | $this->get_contains_hidden_expectation( | |
479 | $this->quba->get_field_prefix($this->slot) . 'p2', 2), | |
480 | $this->get_contains_hidden_expectation( | |
481 | $this->quba->get_field_prefix($this->slot) . 'p3', 2), | |
482 | $this->get_contains_hidden_expectation( | |
483 | $this->quba->get_field_prefix($this->slot) . 'p4', 1)); | |
484 | ||
485 | // Check that extract responses will return the reset data. | |
486 | $prefix = $this->quba->get_field_prefix($this->slot); | |
487 | $this->assertEquals(array('p1' => '1', 'p2' => '2'), | |
488 | $this->quba->extract_responses($this->slot, | |
489 | array($prefix . 'p1' => '1', $prefix . 'p2' => '2', '-tryagain' => 1))); | |
490 | ||
491 | // Do try again. | |
492 | // keys p3 and p4 are extra hidden fields to clear data. | |
493 | $this->process_submission( | |
494 | array('p1' => '1', 'p2' => '2', 'p3' => '', 'p4' => '', '-tryagain' => 1)); | |
495 | ||
496 | // Verify. | |
497 | $this->check_current_state(question_state::$todo); | |
498 | $this->check_current_mark(null); | |
499 | $this->check_current_output( | |
500 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
501 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
502 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
503 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
504 | $this->get_contains_hidden_expectation( | |
505 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
506 | $this->get_contains_hidden_expectation( | |
507 | $this->quba->get_field_prefix($this->slot) . 'p2', 2), | |
508 | $this->get_contains_hidden_expectation( | |
509 | $this->quba->get_field_prefix($this->slot) . 'p3', ''), | |
510 | $this->get_contains_hidden_expectation( | |
511 | $this->quba->get_field_prefix($this->slot) . 'p4', ''), | |
512 | $this->get_contains_submit_button_expectation(true), | |
513 | $this->get_does_not_contain_try_again_button_expectation(), | |
514 | $this->get_does_not_contain_correctness_expectation(), | |
515 | $this->get_does_not_contain_feedback_expectation(), | |
516 | $this->get_tries_remaining_expectation(2), | |
517 | $this->get_no_hint_visible_expectation()); | |
518 | ||
519 | // Submit an response with the first and last parts right. | |
520 | $this->process_submission( | |
521 | array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '2', '-submit' => 1)); | |
522 | ||
523 | // Verify. | |
524 | $this->check_current_state(question_state::$todo); | |
525 | $this->check_current_mark(null); | |
526 | $this->check_current_output( | |
527 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
528 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
529 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
530 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
531 | $this->get_contains_submit_button_expectation(false), | |
532 | $this->get_contains_try_again_button_expectation(true), | |
533 | $this->get_does_not_contain_correctness_expectation(), | |
534 | new question_pattern_expectation('/' . | |
535 | preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'), | |
536 | $this->get_contains_hint_expectation('This is the second hint'), | |
537 | $this->get_contains_num_parts_correct(2), | |
538 | $this->get_contains_standard_partiallycorrect_combined_feedback_expectation(), | |
539 | $this->get_contains_hidden_expectation( | |
540 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
541 | $this->get_contains_hidden_expectation( | |
542 | $this->quba->get_field_prefix($this->slot) . 'p2', 1), | |
543 | $this->get_contains_hidden_expectation( | |
544 | $this->quba->get_field_prefix($this->slot) . 'p3', 2), | |
545 | $this->get_contains_hidden_expectation( | |
546 | $this->quba->get_field_prefix($this->slot) . 'p4', 2)); | |
547 | ||
548 | // Do try again. | |
549 | $this->process_submission( | |
550 | array('p1' => '1', 'p2' => '', 'p3' => '', 'p4' => '2', '-tryagain' => 1)); | |
551 | ||
552 | // Verify. | |
553 | $this->check_current_state(question_state::$todo); | |
554 | $this->check_current_mark(null); | |
555 | $this->check_current_output( | |
556 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
557 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
558 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
559 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
560 | $this->get_contains_hidden_expectation( | |
561 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
562 | $this->get_contains_hidden_expectation( | |
563 | $this->quba->get_field_prefix($this->slot) . 'p2', ''), | |
564 | $this->get_contains_hidden_expectation( | |
565 | $this->quba->get_field_prefix($this->slot) . 'p3', ''), | |
566 | $this->get_contains_hidden_expectation( | |
567 | $this->quba->get_field_prefix($this->slot) . 'p4', 2), | |
568 | $this->get_contains_submit_button_expectation(true), | |
569 | $this->get_does_not_contain_try_again_button_expectation(), | |
570 | $this->get_does_not_contain_correctness_expectation(), | |
571 | $this->get_does_not_contain_feedback_expectation(), | |
572 | $this->get_tries_remaining_expectation(1), | |
573 | $this->get_no_hint_visible_expectation()); | |
574 | ||
575 | // Submit the right answer. | |
576 | $this->process_submission( | |
577 | array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2', '-submit' => 1)); | |
578 | ||
579 | // Verify. | |
580 | $this->check_current_state(question_state::$gradedright); | |
581 | $this->check_current_mark(7); | |
582 | $this->check_current_output( | |
583 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
584 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
585 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
586 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
587 | $this->get_contains_hidden_expectation( | |
588 | $this->quba->get_field_prefix($this->slot) . 'p1', 1), | |
589 | $this->get_contains_hidden_expectation( | |
590 | $this->quba->get_field_prefix($this->slot) . 'p2', 2), | |
591 | $this->get_contains_hidden_expectation( | |
592 | $this->quba->get_field_prefix($this->slot) . 'p3', 1), | |
593 | $this->get_contains_hidden_expectation( | |
594 | $this->quba->get_field_prefix($this->slot) . 'p4', 2), | |
595 | $this->get_contains_submit_button_expectation(false), | |
596 | $this->get_does_not_contain_try_again_button_expectation(), | |
597 | $this->get_contains_correct_expectation(), | |
598 | $this->get_no_hint_visible_expectation(), | |
599 | $this->get_does_not_contain_num_parts_correct(), | |
600 | $this->get_contains_standard_correct_combined_feedback_expectation()); | |
601 | } | |
602 | ||
603 | public function test_interactive_correct_no_submit() { | |
604 | ||
605 | // Create a drag-and-drop question. | |
606 | $dd = test_question_maker::make_question('ddimageortext'); | |
607 | $dd->hints = array( | |
608 | new question_hint_with_parts(23, 'This is the first hint.', | |
609 | FORMAT_MOODLE, false, false), | |
610 | new question_hint_with_parts(24, 'This is the second hint.', | |
611 | FORMAT_MOODLE, true, true), | |
612 | ); | |
613 | $dd->shufflechoices = false; | |
614 | $this->start_attempt_at_question($dd, 'interactive', 3); | |
615 | ||
616 | // Check the initial state. | |
617 | $this->check_current_state(question_state::$todo); | |
618 | $this->check_current_mark(null); | |
619 | $this->check_current_output( | |
620 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
621 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
622 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
623 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
624 | $this->get_contains_hidden_expectation( | |
625 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
626 | $this->get_contains_hidden_expectation( | |
627 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
628 | $this->get_contains_hidden_expectation( | |
629 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
630 | $this->get_contains_hidden_expectation( | |
631 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
632 | $this->get_contains_submit_button_expectation(true), | |
633 | $this->get_does_not_contain_feedback_expectation(), | |
634 | $this->get_tries_remaining_expectation(3), | |
635 | $this->get_no_hint_visible_expectation()); | |
636 | ||
637 | // Save the right answer. | |
638 | $this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')); | |
639 | ||
640 | // Finish the attempt without clicking check. | |
641 | $this->quba->finish_all_questions(); | |
642 | ||
643 | // Verify. | |
644 | $this->check_current_state(question_state::$gradedright); | |
645 | $this->check_current_mark(3); | |
646 | $this->check_current_output( | |
647 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
648 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
649 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
650 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
651 | $this->get_contains_submit_button_expectation(false), | |
652 | $this->get_contains_correct_expectation(), | |
653 | $this->get_no_hint_visible_expectation()); | |
654 | ||
655 | // Check regrading does not mess anything up. | |
656 | $this->quba->regrade_all_questions(); | |
657 | ||
658 | // Verify. | |
659 | $this->check_current_state(question_state::$gradedright); | |
660 | $this->check_current_mark(3); | |
661 | } | |
662 | ||
663 | public function test_interactive_partial_no_submit() { | |
664 | ||
665 | // Create a drag-and-drop question. | |
666 | $dd = test_question_maker::make_question('ddimageortext'); | |
667 | $dd->hints = array( | |
668 | new question_hint_with_parts(23, 'This is the first hint.', | |
669 | FORMAT_MOODLE, false, false), | |
670 | new question_hint_with_parts(24, 'This is the second hint.', | |
671 | FORMAT_MOODLE, true, true), | |
672 | ); | |
673 | $dd->shufflechoices = false; | |
674 | $this->start_attempt_at_question($dd, 'interactive', 4); | |
675 | ||
676 | // Check the initial state. | |
677 | $this->check_current_state(question_state::$todo); | |
678 | $this->check_current_mark(null); | |
679 | ||
680 | $this->check_current_output( | |
681 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
682 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
683 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
684 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
685 | $this->get_contains_hidden_expectation( | |
686 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
687 | $this->get_contains_hidden_expectation( | |
688 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
689 | $this->get_contains_hidden_expectation( | |
690 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
691 | $this->get_contains_hidden_expectation( | |
692 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
693 | $this->get_contains_submit_button_expectation(true), | |
694 | $this->get_does_not_contain_feedback_expectation(), | |
695 | $this->get_tries_remaining_expectation(3), | |
696 | $this->get_no_hint_visible_expectation()); | |
697 | ||
698 | // Save the a partially right answer. | |
699 | $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '1')); | |
700 | ||
701 | // Finish the attempt without clicking check. | |
702 | $this->quba->finish_all_questions(); | |
703 | ||
704 | // Verify. | |
705 | $this->check_current_state(question_state::$gradedpartial); | |
706 | $this->check_current_mark(1); | |
707 | ||
708 | $this->check_current_output( | |
709 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
710 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
711 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
712 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
713 | $this->get_contains_submit_button_expectation(false), | |
714 | $this->get_contains_partcorrect_expectation(), | |
715 | $this->get_no_hint_visible_expectation()); | |
716 | ||
717 | // Check regrading does not mess anything up. | |
718 | $this->quba->regrade_all_questions(); | |
719 | ||
720 | // Verify. | |
721 | $this->check_current_state(question_state::$gradedpartial); | |
722 | $this->check_current_mark(1); | |
723 | } | |
724 | ||
725 | public function test_interactive_no_right_clears() { | |
726 | ||
727 | // Create a drag-and-drop question. | |
728 | $dd = test_question_maker::make_question('ddimageortext'); | |
729 | $dd->hints = array( | |
730 | new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE, false, true), | |
731 | new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE, true, true), | |
732 | ); | |
733 | $dd->shufflechoices = false; | |
734 | $this->start_attempt_at_question($dd, 'interactive', 3); | |
735 | ||
736 | // Check the initial state. | |
737 | $this->check_current_state(question_state::$todo); | |
738 | $this->check_current_mark(null); | |
739 | ||
740 | $this->check_current_output( | |
741 | $this->get_contains_marked_out_of_summary(), | |
742 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
743 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
744 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
745 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
746 | $this->get_contains_hidden_expectation( | |
747 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
748 | $this->get_contains_hidden_expectation( | |
749 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
750 | $this->get_contains_hidden_expectation( | |
751 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
752 | $this->get_contains_hidden_expectation( | |
753 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
754 | $this->get_contains_submit_button_expectation(true), | |
755 | $this->get_does_not_contain_feedback_expectation(), | |
756 | $this->get_tries_remaining_expectation(3), | |
757 | $this->get_no_hint_visible_expectation()); | |
758 | ||
759 | // Save the a completely wrong answer. | |
760 | $this->process_submission( | |
761 | array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1', '-submit' => 1)); | |
762 | ||
763 | // Verify. | |
764 | $this->check_current_state(question_state::$todo); | |
765 | $this->check_current_mark(null); | |
766 | $this->check_current_output( | |
767 | $this->get_contains_marked_out_of_summary(), | |
768 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
769 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
770 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
771 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
772 | $this->get_contains_submit_button_expectation(false), | |
773 | $this->get_contains_hint_expectation('This is the first hint')); | |
774 | ||
775 | // Do try again. | |
776 | $this->process_submission( | |
777 | array('p1' => '', 'p2' => '', 'p3' => '', 'p4' => '', '-tryagain' => 1)); | |
778 | ||
779 | // Check that all the wrong answers have been cleared. | |
780 | $this->check_current_state(question_state::$todo); | |
781 | $this->check_current_mark(null); | |
782 | $this->check_current_output( | |
783 | $this->get_contains_marked_out_of_summary(), | |
784 | $this->get_contains_drag_image_home_expectation(1, 1, 1), | |
785 | $this->get_contains_drag_image_home_expectation(2, 2, 1), | |
786 | $this->get_contains_drag_image_home_expectation(1, 1, 2), | |
787 | $this->get_contains_drag_image_home_expectation(2, 2, 2), | |
788 | $this->get_contains_hidden_expectation( | |
789 | $this->quba->get_field_prefix($this->slot) . 'p1', ''), | |
790 | $this->get_contains_hidden_expectation( | |
791 | $this->quba->get_field_prefix($this->slot) . 'p2', ''), | |
792 | $this->get_contains_hidden_expectation( | |
793 | $this->quba->get_field_prefix($this->slot) . 'p3', ''), | |
794 | $this->get_contains_hidden_expectation( | |
795 | $this->quba->get_field_prefix($this->slot) . 'p4', ''), | |
796 | $this->get_contains_submit_button_expectation(true), | |
797 | $this->get_does_not_contain_feedback_expectation(), | |
798 | $this->get_tries_remaining_expectation(2), | |
799 | $this->get_no_hint_visible_expectation()); | |
800 | } | |
801 | ||
802 | public function test_display_of_right_answer_when_shuffled() { | |
803 | ||
804 | // Create a drag-and-drop question. | |
805 | $dd = test_question_maker::make_question('ddimageortext'); | |
806 | $this->start_attempt_at_question($dd, 'deferredfeedback', 3); | |
807 | ||
808 | // Check the initial state. | |
809 | $this->check_current_state(question_state::$todo); | |
810 | $this->check_current_mark(null); | |
811 | ||
812 | $this->check_current_output( | |
813 | $this->get_contains_hidden_expectation( | |
814 | $this->quba->get_field_prefix($this->slot) . 'p1'), | |
815 | $this->get_contains_hidden_expectation( | |
816 | $this->quba->get_field_prefix($this->slot) . 'p2'), | |
817 | $this->get_contains_hidden_expectation( | |
818 | $this->quba->get_field_prefix($this->slot) . 'p3'), | |
819 | $this->get_contains_hidden_expectation( | |
820 | $this->quba->get_field_prefix($this->slot) . 'p4'), | |
821 | $this->get_does_not_contain_feedback_expectation()); | |
822 | ||
823 | // Save a partial answer. | |
824 | $this->process_submission($dd->get_correct_response()); | |
825 | ||
826 | // Verify. | |
827 | $this->check_current_state(question_state::$complete); | |
828 | $this->check_current_mark(null); | |
829 | $this->check_current_output( | |
830 | $this->get_contains_hidden_expectation( | |
831 | $this->quba->get_field_prefix($this->slot) . 'p1', | |
832 | $dd->get_right_choice_for(1)), | |
833 | $this->get_contains_hidden_expectation( | |
834 | $this->quba->get_field_prefix($this->slot) . 'p2', | |
835 | $dd->get_right_choice_for(2)), | |
836 | $this->get_contains_hidden_expectation( | |
837 | $this->quba->get_field_prefix($this->slot) . 'p3', | |
838 | $dd->get_right_choice_for(3)), | |
839 | $this->get_contains_hidden_expectation( | |
840 | $this->quba->get_field_prefix($this->slot) . 'p4', | |
841 | $dd->get_right_choice_for(4)), | |
842 | $this->get_does_not_contain_correctness_expectation(), | |
843 | $this->get_does_not_contain_feedback_expectation()); | |
844 | ||
845 | // Finish the attempt. | |
846 | $this->quba->finish_all_questions(); | |
847 | ||
848 | // Verify. | |
849 | $this->displayoptions->rightanswer = question_display_options::VISIBLE; | |
850 | $this->assertEquals('Drop zone 1 -> {1. quick} '. | |
851 | 'Drop zone 2 -> {2. fox} '. | |
852 | 'Drop zone 3 -> {1. lazy} '. | |
853 | 'Drop zone 4 -> {2. dog}', | |
854 | $dd->get_right_answer_summary()); | |
855 | $this->check_current_state(question_state::$gradedright); | |
856 | $this->check_current_mark(3); | |
857 | } | |
858 | } |