3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Unit tests for the drag-and-drop words into sentences question type.
23 * @copyright 2010 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
30 require_once($CFG->dirroot
. '/question/engine/simpletest/helpers.php');
31 require_once($CFG->dirroot
. '/question/type/ddwtos/simpletest/helper.php');
35 * Unit tests for the drag-and-drop words into sentences question type.
37 * @copyright 2010 The Open University
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class qtype_ddwtos_walkthrough_test
extends qbehaviour_walkthrough_test_base
{
42 protected function get_contains_drop_box_expectation($place, $group, $readonly,
44 $qa = $this->quba
->get_question_attempt($this->slot
);
46 $expectedattrs = array(
47 'id' => $qa->get_qt_field_name($place . '_' . $group),
49 $class = 'slot group' . $group;
51 $class .= ' readonly';
53 $expectedattrs['tabindex'] = 0;
56 $class .= ' ' . $stateclass;
58 $expectedattrs['class'] = $class;
60 return new ContainsTagWithAttributes('span', $expectedattrs);
63 public function test_interactive_behaviour() {
65 // Create a drag-and-drop question.
66 $dd = test_question_maker
::make_question('ddwtos');
68 new question_hint_with_parts(13, 'This is the first hint.', FORMAT_HTML
, false, false),
69 new question_hint_with_parts(14, 'This is the second hint.', FORMAT_HTML
, true, true),
71 $dd->shufflechoices
= false;
72 $this->start_attempt_at_question($dd, 'interactive', 3);
74 // Check the initial state.
75 $this->check_current_state(question_state
::$todo);
76 $this->check_current_mark(null);
77 $this->check_current_output(
78 $this->get_contains_drop_box_expectation('p1', 1, false),
79 $this->get_contains_drop_box_expectation('p2', 2, false),
80 $this->get_contains_drop_box_expectation('p3', 3, false),
81 $this->get_contains_hidden_expectation(
82 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
83 $this->get_contains_hidden_expectation(
84 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
85 $this->get_contains_hidden_expectation(
86 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
87 $this->get_contains_submit_button_expectation(true),
88 $this->get_does_not_contain_feedback_expectation(),
89 $this->get_tries_remaining_expectation(3),
90 $this->get_no_hint_visible_expectation());
92 // Save the wrong answer.
93 $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2'));
96 $this->check_current_state(question_state
::$todo);
97 $this->check_current_mark(null);
98 $this->check_current_output(
99 $this->get_contains_drop_box_expectation('p1', 1, false),
100 $this->get_contains_drop_box_expectation('p2', 2, false),
101 $this->get_contains_drop_box_expectation('p3', 3, false),
102 $this->get_contains_hidden_expectation(
103 $this->quba
->get_field_prefix($this->slot
) . 'p1', '2'),
104 $this->get_contains_hidden_expectation(
105 $this->quba
->get_field_prefix($this->slot
) . 'p2', '2'),
106 $this->get_contains_hidden_expectation(
107 $this->quba
->get_field_prefix($this->slot
) . 'p3', '2'),
108 $this->get_contains_submit_button_expectation(true),
109 $this->get_does_not_contain_correctness_expectation(),
110 $this->get_does_not_contain_feedback_expectation(),
111 $this->get_tries_remaining_expectation(3),
112 $this->get_no_hint_visible_expectation());
114 // Submit the wrong answer.
115 $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));
118 $this->check_current_state(question_state
::$todo);
119 $this->check_current_mark(null);
120 $this->check_current_output(
121 $this->get_contains_drop_box_expectation('p1', 1, true),
122 $this->get_contains_drop_box_expectation('p2', 2, true),
123 $this->get_contains_drop_box_expectation('p3', 3, true),
124 $this->get_contains_submit_button_expectation(false),
125 $this->get_contains_try_again_button_expectation(true),
126 $this->get_does_not_contain_correctness_expectation(),
127 new PatternExpectation('/' .
128 preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
129 $this->get_contains_hint_expectation('This is the first hint'));
132 $this->process_submission(array('-tryagain' => 1));
135 $this->check_current_state(question_state
::$todo);
136 $this->check_current_mark(null);
137 $this->check_current_output(
138 $this->get_contains_drop_box_expectation('p1', 1, false),
139 $this->get_contains_drop_box_expectation('p2', 2, false),
140 $this->get_contains_drop_box_expectation('p3', 3, false),
141 $this->get_contains_hidden_expectation(
142 $this->quba
->get_field_prefix($this->slot
) . 'p1', '2'),
143 $this->get_contains_hidden_expectation(
144 $this->quba
->get_field_prefix($this->slot
) . 'p2', '2'),
145 $this->get_contains_hidden_expectation(
146 $this->quba
->get_field_prefix($this->slot
) . 'p3', '2'),
147 $this->get_contains_submit_button_expectation(true),
148 $this->get_does_not_contain_correctness_expectation(),
149 $this->get_does_not_contain_feedback_expectation(),
150 $this->get_tries_remaining_expectation(2),
151 $this->get_no_hint_visible_expectation());
153 // Submit the right answer.
154 $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));
157 $this->check_current_state(question_state
::$gradedright);
158 $this->check_current_mark(2);
159 $this->check_current_output(
160 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
161 $this->get_contains_drop_box_expectation('p2', 2, true, 'correct'),
162 $this->get_contains_drop_box_expectation('p3', 3, true, 'correct'),
163 $this->get_contains_submit_button_expectation(false),
164 $this->get_contains_correct_expectation(),
165 $this->get_no_hint_visible_expectation());
167 // Check regrading does not mess anything up.
168 $this->quba
->regrade_all_questions();
171 $this->check_current_state(question_state
::$gradedright);
172 $this->check_current_mark(2);
175 public function test_deferred_feedback() {
177 // Create a drag-and-drop question.
178 $dd = test_question_maker
::make_question('ddwtos');
179 $dd->shufflechoices
= false;
180 $this->start_attempt_at_question($dd, 'deferredfeedback', 3);
182 // Check the initial state.
183 $this->check_current_state(question_state
::$todo);
184 $this->check_current_mark(null);
185 $this->check_current_output(
186 $this->get_contains_drop_box_expectation('p1', 1, false),
187 $this->get_contains_drop_box_expectation('p2', 2, false),
188 $this->get_contains_drop_box_expectation('p3', 3, false),
189 $this->get_contains_hidden_expectation(
190 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
191 $this->get_contains_hidden_expectation(
192 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
193 $this->get_contains_hidden_expectation(
194 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
195 $this->get_does_not_contain_feedback_expectation());
197 // Save a partial answer.
198 $this->process_submission(array('p1' => '1', 'p2' => '2'));
201 $this->check_current_state(question_state
::$invalid);
202 $this->check_current_mark(null);
203 $this->check_current_output(
204 $this->get_contains_drop_box_expectation('p1', 1, false),
205 $this->get_contains_drop_box_expectation('p2', 2, false),
206 $this->get_contains_drop_box_expectation('p3', 3, false),
207 $this->get_contains_hidden_expectation(
208 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
209 $this->get_contains_hidden_expectation(
210 $this->quba
->get_field_prefix($this->slot
) . 'p2', '2'),
211 $this->get_contains_hidden_expectation(
212 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
213 $this->get_does_not_contain_correctness_expectation(),
214 $this->get_does_not_contain_feedback_expectation());
216 // Save the right answer.
217 $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1'));
220 $this->check_current_state(question_state
::$complete);
221 $this->check_current_mark(null);
222 $this->check_current_output(
223 $this->get_contains_drop_box_expectation('p1', 1, false),
224 $this->get_contains_drop_box_expectation('p2', 2, false),
225 $this->get_contains_drop_box_expectation('p3', 3, false),
226 $this->get_contains_hidden_expectation(
227 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
228 $this->get_contains_hidden_expectation(
229 $this->quba
->get_field_prefix($this->slot
) . 'p2', '1'),
230 $this->get_contains_hidden_expectation(
231 $this->quba
->get_field_prefix($this->slot
) . 'p3', '1'),
232 $this->get_does_not_contain_correctness_expectation(),
233 $this->get_does_not_contain_feedback_expectation());
235 // Finish the attempt.
236 $this->quba
->finish_all_questions();
239 $this->check_current_state(question_state
::$gradedright);
240 $this->check_current_mark(3);
241 $this->check_current_output(
242 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
243 $this->get_contains_drop_box_expectation('p2', 2, true, 'correct'),
244 $this->get_contains_drop_box_expectation('p3', 3, true, 'correct'),
245 $this->get_contains_correct_expectation());
247 // Change the right answer a bit.
248 $dd->rightchoices
[2] = 2;
250 // Check regrading does not mess anything up.
251 $this->quba
->regrade_all_questions();
254 $this->check_current_state(question_state
::$gradedpartial);
255 $this->check_current_mark(2);
258 public function test_deferred_feedback_unanswered() {
260 // Create a drag-and-drop question.
261 $dd = test_question_maker
::make_question('ddwtos');
262 $dd->shufflechoices
= false;
263 $this->start_attempt_at_question($dd, 'deferredfeedback', 3);
265 // Check the initial state.
266 $this->check_current_state(question_state
::$todo);
267 $this->check_current_mark(null);
268 $this->check_current_output(
269 $this->get_contains_drop_box_expectation('p1', 1, false),
270 $this->get_contains_drop_box_expectation('p2', 2, false),
271 $this->get_contains_drop_box_expectation('p3', 3, false),
272 $this->get_contains_hidden_expectation(
273 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
274 $this->get_contains_hidden_expectation(
275 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
276 $this->get_contains_hidden_expectation(
277 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
278 $this->get_does_not_contain_correctness_expectation(),
279 $this->get_does_not_contain_feedback_expectation());
280 $this->check_step_count(1);
282 // Save a blank response.
283 $this->process_submission(array('p1' => '0', 'p2' => '0', 'p3' => '0'));
286 $this->check_current_state(question_state
::$todo);
287 $this->check_current_mark(null);
288 $this->check_current_output(
289 $this->get_contains_drop_box_expectation('p1', 1, false),
290 $this->get_contains_drop_box_expectation('p2', 2, false),
291 $this->get_contains_drop_box_expectation('p3', 3, false),
292 $this->get_contains_hidden_expectation(
293 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
294 $this->get_contains_hidden_expectation(
295 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
296 $this->get_contains_hidden_expectation(
297 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
298 $this->get_does_not_contain_correctness_expectation(),
299 $this->get_does_not_contain_feedback_expectation());
300 $this->check_step_count(1);
302 // Finish the attempt.
303 $this->quba
->finish_all_questions();
306 $this->check_current_state(question_state
::$gaveup);
307 $this->check_current_mark(null);
308 $this->check_current_output(
309 $this->get_contains_drop_box_expectation('p1', 1, true),
310 $this->get_contains_drop_box_expectation('p2', 2, true),
311 $this->get_contains_drop_box_expectation('p3', 3, true));
314 public function test_deferred_feedback_partial_answer() {
316 // Create a drag-and-drop question.
317 $dd = test_question_maker
::make_question('ddwtos');
318 $dd->shufflechoices
= false;
319 $this->start_attempt_at_question($dd, 'deferredfeedback', 3);
321 // Check the initial state.
322 $this->check_current_state(question_state
::$todo);
323 $this->check_current_mark(null);
324 $this->check_current_output(
325 $this->get_contains_drop_box_expectation('p1', 1, false),
326 $this->get_contains_drop_box_expectation('p2', 2, false),
327 $this->get_contains_drop_box_expectation('p3', 3, false),
328 $this->get_contains_hidden_expectation(
329 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
330 $this->get_contains_hidden_expectation(
331 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
332 $this->get_contains_hidden_expectation(
333 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
334 $this->get_does_not_contain_correctness_expectation(),
335 $this->get_does_not_contain_feedback_expectation());
337 // Save a partial response.
338 $this->process_submission(array('p1' => '1', 'p2' => '0', 'p3' => '0'));
341 $this->check_current_state(question_state
::$invalid);
342 $this->check_current_mark(null);
343 $this->check_current_output(
344 $this->get_contains_drop_box_expectation('p1', 1, false),
345 $this->get_contains_drop_box_expectation('p2', 2, false),
346 $this->get_contains_drop_box_expectation('p3', 3, false),
347 $this->get_contains_hidden_expectation(
348 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
349 $this->get_contains_hidden_expectation(
350 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
351 $this->get_contains_hidden_expectation(
352 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
353 $this->get_does_not_contain_correctness_expectation(),
354 $this->get_does_not_contain_feedback_expectation());
356 // Finish the attempt.
357 $this->quba
->finish_all_questions();
360 $this->check_current_state(question_state
::$gradedpartial);
361 $this->check_current_mark(1);
362 $this->check_current_output(
363 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
364 $this->get_contains_drop_box_expectation('p2', 2, true, 'incorrect'),
365 $this->get_contains_drop_box_expectation('p3', 3, true, 'incorrect'),
366 $this->get_contains_partcorrect_expectation());
369 public function test_interactive_grading() {
371 // Create a drag-and-drop question.
372 $dd = test_question_maker
::make_question('ddwtos');
374 new question_hint_with_parts(1, 'This is the first hint.',
375 FORMAT_MOODLE
, true, true),
376 new question_hint_with_parts(2, 'This is the second hint.',
377 FORMAT_MOODLE
, true, true),
379 $dd->shufflechoices
= false;
380 $this->start_attempt_at_question($dd, 'interactive', 9);
382 // Check the initial state.
383 $this->check_current_state(question_state
::$todo);
384 $this->check_current_mark(null);
385 $this->assertEqual('interactivecountback',
386 $this->quba
->get_question_attempt($this->slot
)->get_behaviour_name());
387 $this->check_current_output(
388 $this->get_contains_drop_box_expectation('p1', 1, false),
389 $this->get_contains_drop_box_expectation('p2', 2, false),
390 $this->get_contains_drop_box_expectation('p3', 3, false),
391 $this->get_contains_hidden_expectation(
392 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
393 $this->get_contains_hidden_expectation(
394 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
395 $this->get_contains_hidden_expectation(
396 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
397 $this->get_contains_submit_button_expectation(true),
398 $this->get_does_not_contain_feedback_expectation(),
399 $this->get_tries_remaining_expectation(3),
400 $this->get_does_not_contain_num_parts_correct(),
401 $this->get_no_hint_visible_expectation());
403 // Submit an response with the first two parts right.
404 $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '2', '-submit' => 1));
407 $this->check_current_state(question_state
::$todo);
408 $this->check_current_mark(null);
409 $this->check_current_output(
410 $this->get_contains_drop_box_expectation('p1', 1, true),
411 $this->get_contains_drop_box_expectation('p2', 2, true),
412 $this->get_contains_drop_box_expectation('p3', 3, true),
413 $this->get_contains_submit_button_expectation(false),
414 $this->get_contains_try_again_button_expectation(true),
415 $this->get_does_not_contain_correctness_expectation(),
416 new PatternExpectation('/' .
417 preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
418 $this->get_contains_hint_expectation('This is the first hint'),
419 $this->get_contains_num_parts_correct(2),
420 $this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
421 $this->get_contains_hidden_expectation(
422 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
423 $this->get_contains_hidden_expectation(
424 $this->quba
->get_field_prefix($this->slot
) . 'p2', '1'),
425 $this->get_contains_hidden_expectation(
426 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'));
428 // Check that extract responses will return the reset data.
429 $prefix = $this->quba
->get_field_prefix($this->slot
);
430 $this->assertEqual(array('p1' => '1', 'p2' => '1'),
431 $this->quba
->extract_responses($this->slot
,
432 array($prefix . 'p1' => '1', $prefix . 'p2' => '1', '-tryagain' => 1)));
435 $this->process_submission(array('p1' => '1', 'p2' => '1', '-tryagain' => 1));
438 $this->check_current_state(question_state
::$todo);
439 $this->check_current_mark(null);
440 $this->check_current_output(
441 $this->get_contains_drop_box_expectation('p1', 1, false),
442 $this->get_contains_drop_box_expectation('p2', 2, false),
443 $this->get_contains_drop_box_expectation('p3', 3, false),
444 $this->get_contains_hidden_expectation(
445 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
446 $this->get_contains_hidden_expectation(
447 $this->quba
->get_field_prefix($this->slot
) . 'p2', '1'),
448 $this->get_contains_hidden_expectation(
449 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
450 $this->get_contains_submit_button_expectation(true),
451 $this->get_does_not_contain_try_again_button_expectation(),
452 $this->get_does_not_contain_correctness_expectation(),
453 $this->get_does_not_contain_feedback_expectation(),
454 $this->get_tries_remaining_expectation(2),
455 $this->get_no_hint_visible_expectation());
457 // Submit an response with the first and last parts right.
458 $this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '1', '-submit' => 1));
461 $this->check_current_state(question_state
::$todo);
462 $this->check_current_mark(null);
463 $this->check_current_output(
464 $this->get_contains_drop_box_expectation('p1', 1, true),
465 $this->get_contains_drop_box_expectation('p2', 2, true),
466 $this->get_contains_drop_box_expectation('p3', 3, true),
467 $this->get_contains_submit_button_expectation(false),
468 $this->get_contains_try_again_button_expectation(true),
469 $this->get_does_not_contain_correctness_expectation(),
470 new PatternExpectation('/' .
471 preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
472 $this->get_contains_hint_expectation('This is the second hint'),
473 $this->get_contains_num_parts_correct(2),
474 $this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
475 $this->get_contains_hidden_expectation(
476 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
477 $this->get_contains_hidden_expectation(
478 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
479 $this->get_contains_hidden_expectation(
480 $this->quba
->get_field_prefix($this->slot
) . 'p3', '1'));
483 $this->process_submission(array('p1' => '1', 'p3' => '1', '-tryagain' => 1));
486 $this->check_current_state(question_state
::$todo);
487 $this->check_current_mark(null);
488 $this->check_current_output(
489 $this->get_contains_drop_box_expectation('p1', 1, false),
490 $this->get_contains_drop_box_expectation('p2', 2, false),
491 $this->get_contains_drop_box_expectation('p3', 3, false),
492 $this->get_contains_hidden_expectation(
493 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
494 $this->get_contains_hidden_expectation(
495 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
496 $this->get_contains_hidden_expectation(
497 $this->quba
->get_field_prefix($this->slot
) . 'p3', '1'),
498 $this->get_contains_submit_button_expectation(true),
499 $this->get_does_not_contain_try_again_button_expectation(),
500 $this->get_does_not_contain_correctness_expectation(),
501 $this->get_does_not_contain_feedback_expectation(),
502 $this->get_tries_remaining_expectation(1),
503 $this->get_no_hint_visible_expectation());
505 // Submit the right answer.
506 $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));
509 $this->check_current_state(question_state
::$gradedright);
510 $this->check_current_mark(6);
511 $this->check_current_output(
512 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
513 $this->get_contains_drop_box_expectation('p2', 2, true, 'correct'),
514 $this->get_contains_drop_box_expectation('p3', 3, true, 'correct'),
515 $this->get_contains_submit_button_expectation(false),
516 $this->get_does_not_contain_try_again_button_expectation(),
517 $this->get_contains_correct_expectation(),
518 $this->get_no_hint_visible_expectation(),
519 $this->get_does_not_contain_num_parts_correct(),
520 $this->get_contains_standard_correct_combined_feedback_expectation(),
521 $this->get_contains_hidden_expectation(
522 $this->quba
->get_field_prefix($this->slot
) . 'p1', '1'),
523 $this->get_contains_hidden_expectation(
524 $this->quba
->get_field_prefix($this->slot
) . 'p2', '1'),
525 $this->get_contains_hidden_expectation(
526 $this->quba
->get_field_prefix($this->slot
) . 'p3', '1'));
529 public function test_interactive_correct_no_submit() {
531 // Create a drag-and-drop question.
532 $dd = test_question_maker
::make_question('ddwtos');
534 new question_hint_with_parts(23, 'This is the first hint.',
535 FORMAT_MOODLE
, false, false),
536 new question_hint_with_parts(24, 'This is the second hint.',
537 FORMAT_MOODLE
, true, true),
539 $dd->shufflechoices
= false;
540 $this->start_attempt_at_question($dd, 'interactive', 3);
542 // Check the initial state.
543 $this->check_current_state(question_state
::$todo);
544 $this->check_current_mark(null);
545 $this->check_current_output(
546 $this->get_contains_drop_box_expectation('p1', 1, false),
547 $this->get_contains_drop_box_expectation('p2', 2, false),
548 $this->get_contains_drop_box_expectation('p3', 3, false),
549 $this->get_contains_hidden_expectation(
550 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
551 $this->get_contains_hidden_expectation(
552 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
553 $this->get_contains_hidden_expectation(
554 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
555 $this->get_contains_submit_button_expectation(true),
556 $this->get_does_not_contain_feedback_expectation(),
557 $this->get_tries_remaining_expectation(3),
558 $this->get_no_hint_visible_expectation());
560 // Save the right answer.
561 $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1'));
563 // Finish the attempt without clicking check.
564 $this->quba
->finish_all_questions();
567 $this->check_current_state(question_state
::$gradedright);
568 $this->check_current_mark(3);
569 $this->check_current_output(
570 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
571 $this->get_contains_drop_box_expectation('p2', 2, true, 'correct'),
572 $this->get_contains_drop_box_expectation('p3', 3, true, 'correct'),
573 $this->get_contains_submit_button_expectation(false),
574 $this->get_contains_correct_expectation(),
575 $this->get_no_hint_visible_expectation());
577 // Check regrading does not mess anything up.
578 $this->quba
->regrade_all_questions();
581 $this->check_current_state(question_state
::$gradedright);
582 $this->check_current_mark(3);
585 public function test_interactive_partial_no_submit() {
587 // Create a drag-and-drop question.
588 $dd = test_question_maker
::make_question('ddwtos');
590 new question_hint_with_parts(23, 'This is the first hint.',
591 FORMAT_MOODLE
, false, false),
592 new question_hint_with_parts(24, 'This is the second hint.',
593 FORMAT_MOODLE
, true, true),
595 $dd->shufflechoices
= false;
596 $this->start_attempt_at_question($dd, 'interactive', 3);
598 // Check the initial state.
599 $this->check_current_state(question_state
::$todo);
600 $this->check_current_mark(null);
601 $this->check_current_output(
602 $this->get_contains_drop_box_expectation('p1', 1, false),
603 $this->get_contains_drop_box_expectation('p2', 2, false),
604 $this->get_contains_drop_box_expectation('p3', 3, false),
605 $this->get_contains_hidden_expectation(
606 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
607 $this->get_contains_hidden_expectation(
608 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
609 $this->get_contains_hidden_expectation(
610 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
611 $this->get_contains_submit_button_expectation(true),
612 $this->get_does_not_contain_feedback_expectation(),
613 $this->get_tries_remaining_expectation(3),
614 $this->get_no_hint_visible_expectation());
616 // Save the a partially right answer.
617 $this->process_submission(array('p1' => '1', 'p2' => '2', 'p3' => '2'));
619 // Finish the attempt without clicking check.
620 $this->quba
->finish_all_questions();
623 $this->check_current_state(question_state
::$gradedpartial);
624 $this->check_current_mark(1);
625 $this->check_current_output(
626 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
627 $this->get_contains_drop_box_expectation('p2', 2, true, 'incorrect'),
628 $this->get_contains_drop_box_expectation('p3', 3, true, 'incorrect'),
629 $this->get_contains_submit_button_expectation(false),
630 $this->get_contains_partcorrect_expectation(),
631 $this->get_no_hint_visible_expectation());
633 // Check regrading does not mess anything up.
634 $this->quba
->regrade_all_questions();
637 $this->check_current_state(question_state
::$gradedpartial);
638 $this->check_current_mark(1);
641 public function test_interactive_no_right_clears() {
643 // Create a drag-and-drop question.
644 $dd = test_question_maker
::make_question('ddwtos');
646 new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE
, false, true),
647 new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE
, true, true),
649 $dd->shufflechoices
= false;
650 $this->start_attempt_at_question($dd, 'interactive', 3);
652 // Check the initial state.
653 $this->check_current_state(question_state
::$todo);
654 $this->check_current_mark(null);
655 $this->check_current_output(
656 $this->get_contains_marked_out_of_summary(),
657 $this->get_contains_drop_box_expectation('p1', 1, false),
658 $this->get_contains_drop_box_expectation('p2', 2, false),
659 $this->get_contains_drop_box_expectation('p3', 3, false),
660 $this->get_contains_hidden_expectation(
661 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
662 $this->get_contains_hidden_expectation(
663 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
664 $this->get_contains_hidden_expectation(
665 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
666 $this->get_contains_submit_button_expectation(true),
667 $this->get_does_not_contain_feedback_expectation(),
668 $this->get_tries_remaining_expectation(3),
669 $this->get_no_hint_visible_expectation());
671 // Save the a completely wrong answer.
672 $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));
675 $this->check_current_state(question_state
::$todo);
676 $this->check_current_mark(null);
677 $this->check_current_output(
678 $this->get_contains_marked_out_of_summary(),
679 $this->get_contains_drop_box_expectation('p1', 1, true),
680 $this->get_contains_drop_box_expectation('p2', 2, true),
681 $this->get_contains_drop_box_expectation('p3', 3, true),
682 $this->get_contains_submit_button_expectation(false),
683 $this->get_contains_hint_expectation('This is the first hint'));
686 $this->process_submission(array('p1' => '0', 'p2' => '0', 'p3' => '0', '-tryagain' => 1));
688 // Check that all the wrong answers have been cleared.
689 $this->check_current_state(question_state
::$todo);
690 $this->check_current_mark(null);
691 $this->check_current_output(
692 $this->get_contains_marked_out_of_summary(),
693 $this->get_contains_drop_box_expectation('p1', 1, false),
694 $this->get_contains_drop_box_expectation('p2', 2, false),
695 $this->get_contains_drop_box_expectation('p3', 3, false),
696 $this->get_contains_hidden_expectation(
697 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
698 $this->get_contains_hidden_expectation(
699 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
700 $this->get_contains_hidden_expectation(
701 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
702 $this->get_contains_submit_button_expectation(true),
703 $this->get_does_not_contain_feedback_expectation(),
704 $this->get_tries_remaining_expectation(2),
705 $this->get_no_hint_visible_expectation());
708 public function test_display_of_right_answer_when_shuffled() {
710 // Create a drag-and-drop question.
711 $dd = test_question_maker
::make_question('ddwtos');
712 $this->start_attempt_at_question($dd, 'deferredfeedback', 3);
714 // Check the initial state.
715 $this->check_current_state(question_state
::$todo);
716 $this->check_current_mark(null);
717 $this->check_current_output(
718 $this->get_contains_drop_box_expectation('p1', 1, false),
719 $this->get_contains_drop_box_expectation('p2', 2, false),
720 $this->get_contains_drop_box_expectation('p3', 3, false),
721 $this->get_contains_hidden_expectation(
722 $this->quba
->get_field_prefix($this->slot
) . 'p1', '0'),
723 $this->get_contains_hidden_expectation(
724 $this->quba
->get_field_prefix($this->slot
) . 'p2', '0'),
725 $this->get_contains_hidden_expectation(
726 $this->quba
->get_field_prefix($this->slot
) . 'p3', '0'),
727 $this->get_does_not_contain_feedback_expectation());
729 // Save a partial answer.
730 $this->process_submission($dd->get_correct_response());
733 $this->check_current_state(question_state
::$complete);
734 $this->check_current_mark(null);
735 $this->check_current_output(
736 $this->get_contains_drop_box_expectation('p1', 1, false),
737 $this->get_contains_drop_box_expectation('p2', 2, false),
738 $this->get_contains_drop_box_expectation('p3', 3, false),
739 $this->get_contains_hidden_expectation(
740 $this->quba
->get_field_prefix($this->slot
) . 'p1',
741 $dd->get_right_choice_for(1)),
742 $this->get_contains_hidden_expectation(
743 $this->quba
->get_field_prefix($this->slot
) . 'p2',
744 $dd->get_right_choice_for(2)),
745 $this->get_contains_hidden_expectation(
746 $this->quba
->get_field_prefix($this->slot
) . 'p3',
747 $dd->get_right_choice_for(3)),
748 $this->get_does_not_contain_correctness_expectation(),
749 $this->get_does_not_contain_feedback_expectation());
751 // Finish the attempt.
752 $this->quba
->finish_all_questions();
755 $this->displayoptions
->rightanswer
= question_display_options
::VISIBLE
;
756 $this->assertEqual('{quick} {fox} {lazy}', $dd->get_right_answer_summary());
757 $this->check_current_state(question_state
::$gradedright);
758 $this->check_current_mark(3);
759 $this->check_current_output(
760 $this->get_contains_drop_box_expectation('p1', 1, true, 'correct'),
761 $this->get_contains_drop_box_expectation('p2', 2, true, 'correct'),
762 $this->get_contains_drop_box_expectation('p3', 3, true, 'correct'),
763 $this->get_contains_correct_expectation(),
764 new PatternExpectation('/' .
765 preg_quote('The [quick] brown [fox] jumped over the [lazy] dog.') . '/'));