MDL-32323 convert question tests
[moodle.git] / question / type / calculatedsimple / tests / upgradelibnewqe_test.php
CommitLineData
603bd001
PS
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 * Tests of the upgrade to the new Moodle question engine for attempts at
19 * simple calculated questions.
20 *
21 * @package qtype
22 * @subpackage calculatedsimple
23 * @copyright 2011 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27
28defined('MOODLE_INTERNAL') || die();
29
30global $CFG;
31require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php');
32
33
34/**
35 * Testing the upgrade of simple calculated question attempts.
36 *
37 * @copyright 2011 The Open University
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgrader_test_base {
41 public function test_calculatedsimple_adaptive_qsession95() {
42 $quiz = (object) array(
43 'id' => '4',
44 'course' => '2',
45 'name' => 'Calculated quiz',
46 'intro' => '',
47 'introformat' => '1',
48 'timeopen' => '0',
49 'timeclose' => '0',
50 'attempts' => '0',
51 'attemptonlast' => '0',
52 'grademethod' => '1',
53 'decimalpoints' => '2',
54 'questiondecimalpoints' => '-1',
55 'questionsperpage' => '1',
56 'shufflequestions' => '0',
57 'shuffleanswers' => '1',
58 'questions' => '16,0,17,0,18,0',
59 'sumgrades' => '3.00000',
60 'grade' => '10.00000',
61 'timecreated' => '0',
62 'timemodified' => '1305648351',
63 'timelimit' => '0',
64 'password' => '',
65 'subnet' => '',
66 'popup' => '0',
67 'delay1' => '0',
68 'delay2' => '0',
69 'showuserpicture' => '0',
70 'showblocks' => '0',
71 'preferredbehaviour' => 'adaptive',
72 'reviewattempt' => '69888',
73 'reviewcorrectness' => '69888',
74 'reviewmarks' => '69888',
75 'reviewspecificfeedback' => '69888',
76 'reviewgeneralfeedback' => '69888',
77 'reviewrightanswer' => '69888',
78 'reviewoverallfeedback' => '4352',
79 );
80 $attempt = (object) array(
81 'id' => '13',
82 'uniqueid' => '13',
83 'quiz' => '4',
84 'userid' => '4',
85 'attempt' => '1',
86 'sumgrades' => '0.00000',
87 'timestart' => '1305830650',
88 'timefinish' => '1305830656',
89 'timemodified' => '1305830656',
90 'layout' => '16,0,17,0,18,0',
91 'preview' => '0',
92 'needsupgradetonewqe' => 1,
93 );
94 $question = (object) array(
95 'id' => '16',
96 'category' => '2',
97 'parent' => '0',
98 'name' => 'Calculated simple',
99 'questiontext' => '<p>What is {={a}} + {={b}} ?</p>',
100 'questiontextformat' => '1',
101 'generalfeedback' => '',
102 'generalfeedbackformat' => '1',
103 'defaultmark' => '1.0000000',
104 'penalty' => '0.1',
105 'qtype' => 'calculatedsimple',
106 'length' => '1',
107 'stamp' => 'tjh238.vledev2.open.ac.uk+110517161007+2Barhu',
108 'version' => 'tjh238.vledev2.open.ac.uk+110517161008+Mu6OQu',
109 'hidden' => '0',
110 'timecreated' => '1305648607',
111 'timemodified' => '1305648607',
112 'createdby' => '2',
113 'modifiedby' => '2',
114 'maxmark' => '1.0000000',
115 'options' => (object) array(
116 'synchronize' => 0,
117 'single' => 0,
118 'answernumbering' => 'abc',
119 'shuffleanswers' => 0,
120 'correctfeedback' => '',
121 'partiallycorrectfeedback' => '',
122 'incorrectfeedback' => '',
123 'correctfeedbackformat' => 0,
124 'partiallycorrectfeedbackformat' => 0,
125 'incorrectfeedbackformat' => 0,
126 'answers' => array(
127 23 => (object) array(
128 'id' => '23',
129 'question' => '16',
130 'answer' => '{a} + {b}',
131 'answerformat' => '0',
132 'fraction' => '1.0000000',
133 'feedback' => '<p>Well done!</p>',
134 'feedbackformat' => '1',
135 'tolerance' => '0.01',
136 'tolerancetype' => '1',
137 'correctanswerlength' => '2',
138 'correctanswerformat' => '1',
139 ),
140 ),
141 'units' => array(
142 ),
143 'unitgradingtype' => '0',
144 'unitpenalty' => '0.1000000',
145 'showunits' => '3',
146 'unitsleft' => '0',
147 ),
148 'hints' => array(
149 ),
150 );
151 $qsession = (object) array(
152 'id' => '95',
153 'attemptid' => '13',
154 'questionid' => '16',
155 'newest' => '256',
156 'newgraded' => '256',
157 'sumpenalty' => '0.1000000',
158 'manualcomment' => '',
159 'manualcommentformat' => '1',
160 'flagged' => '0',
161 );
162 $qstates = array(
163 253 => (object) array(
164 'id' => '253',
165 'attempt' => '13',
166 'question' => '16',
167 'seq_number' => '0',
168 'answer' => 'dataset7-|||||',
169 'timestamp' => '1305830650',
170 'event' => '0',
171 'grade' => '0.0000000',
172 'raw_grade' => '0.0000000',
173 'penalty' => '0.0000000',
174 ),
175 256 => (object) array(
176 'id' => '256',
177 'attempt' => '13',
178 'question' => '16',
179 'seq_number' => '1',
180 'answer' => 'dataset7-|||||',
181 'timestamp' => '1305830650',
182 'event' => '6',
183 'grade' => '0.0000000',
184 'raw_grade' => '0.0000000',
185 'penalty' => '0.1000000',
186 ),
187 );
188 $this->loader->put_dataset_in_cache($question->id, 7, array('a' => '3', 'b' => '6'));
189
190 $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
191
192 $expectedqa = (object) array(
193 'behaviour' => 'adaptive',
194 'questionid' => 16,
195 'variant' => 7,
196 'maxmark' => 1.0000000,
197 'minfraction' => 0,
198 'flagged' => 0,
199 'questionsummary' => 'What is 3 + 6 ?',
200 'rightanswer' => '9',
201 'responsesummary' => '',
202 'timemodified' => 1305830650,
203 'steps' => array(
204 0 => (object) array(
205 'sequencenumber' => 0,
206 'state' => 'todo',
207 'fraction' => null,
208 'timecreated' => 1305830650,
209 'userid' => 4,
210 'data' => array('_separators' => '.$,',
211 '_var_a' => '3', '_var_b' => '6'),
212 ),
213 1 => (object) array(
214 'sequencenumber' => 1,
215 'state' => 'gradedwrong',
216 'fraction' => 0,
217 'timecreated' => 1305830650,
218 'userid' => 4,
219 'data' => array('answer' => '', '-finish' => 1, '-_try' => 1, '-_rawfraction' => 0),
220 ),
221 ),
222 );
223
224 $this->compare_qas($expectedqa, $qa);
225 }
226
227 public function test_calculatedsimple_adaptive_qsession98() {
228 $quiz = (object) array(
229 'id' => '4',
230 'course' => '2',
231 'name' => 'Calculated quiz',
232 'intro' => '',
233 'introformat' => '1',
234 'timeopen' => '0',
235 'timeclose' => '0',
236 'attempts' => '0',
237 'attemptonlast' => '0',
238 'grademethod' => '1',
239 'decimalpoints' => '2',
240 'questiondecimalpoints' => '-1',
241 'questionsperpage' => '1',
242 'shufflequestions' => '0',
243 'shuffleanswers' => '1',
244 'questions' => '16,0,17,0,18,0',
245 'sumgrades' => '3.00000',
246 'grade' => '10.00000',
247 'timecreated' => '0',
248 'timemodified' => '1305648351',
249 'timelimit' => '0',
250 'password' => '',
251 'subnet' => '',
252 'popup' => '0',
253 'delay1' => '0',
254 'delay2' => '0',
255 'showuserpicture' => '0',
256 'showblocks' => '0',
257 'preferredbehaviour' => 'adaptive',
258 'reviewattempt' => '69888',
259 'reviewcorrectness' => '69888',
260 'reviewmarks' => '69888',
261 'reviewspecificfeedback' => '69888',
262 'reviewgeneralfeedback' => '69888',
263 'reviewrightanswer' => '69888',
264 'reviewoverallfeedback' => '4352',
265 );
266 $attempt = (object) array(
267 'id' => '14',
268 'uniqueid' => '14',
269 'quiz' => '4',
270 'userid' => '4',
271 'attempt' => '2',
272 'sumgrades' => '2.80000',
273 'timestart' => '1305830661',
274 'timefinish' => '1305830729',
275 'timemodified' => '1305830729',
276 'layout' => '16,0,17,0,18,0',
277 'preview' => '0',
278 'needsupgradetonewqe' => 1,
279 );
280 $question = (object) array(
281 'id' => '16',
282 'category' => '2',
283 'parent' => '0',
284 'name' => 'Calculated simple',
285 'questiontext' => '<p>What is {={a}} + {={b}} ?</p>',
286 'questiontextformat' => '1',
287 'generalfeedback' => '',
288 'generalfeedbackformat' => '1',
289 'defaultmark' => '1.0000000',
290 'penalty' => '0.1',
291 'qtype' => 'calculatedsimple',
292 'length' => '1',
293 'stamp' => 'tjh238.vledev2.open.ac.uk+110517161007+2Barhu',
294 'version' => 'tjh238.vledev2.open.ac.uk+110517161008+Mu6OQu',
295 'hidden' => '0',
296 'timecreated' => '1305648607',
297 'timemodified' => '1305648607',
298 'createdby' => '2',
299 'modifiedby' => '2',
300 'maxmark' => '1.0000000',
301 'options' => (object) array(
302 'synchronize' => 0,
303 'single' => 0,
304 'answernumbering' => 'abc',
305 'shuffleanswers' => 0,
306 'correctfeedback' => '',
307 'partiallycorrectfeedback' => '',
308 'incorrectfeedback' => '',
309 'correctfeedbackformat' => 0,
310 'partiallycorrectfeedbackformat' => 0,
311 'incorrectfeedbackformat' => 0,
312 'answers' => array(
313 23 => (object) array(
314 'id' => '23',
315 'question' => '16',
316 'answer' => '{a} + {b}',
317 'answerformat' => '0',
318 'fraction' => '1.0000000',
319 'feedback' => '<p>Well done!</p>',
320 'feedbackformat' => '1',
321 'tolerance' => '0.01',
322 'tolerancetype' => '1',
323 'correctanswerlength' => '2',
324 'correctanswerformat' => '1',
325 ),
326 ),
327 'units' => array(
328 ),
329 'unitgradingtype' => '0',
330 'unitpenalty' => '0.1000000',
331 'showunits' => '3',
332 'unitsleft' => '0',
333 ),
334 'hints' => array(
335 ),
336 );
337 $qsession = (object) array(
338 'id' => '98',
339 'attemptid' => '14',
340 'questionid' => '16',
341 'newest' => '267',
342 'newgraded' => '267',
343 'sumpenalty' => '0.3000000',
344 'manualcomment' => '',
345 'manualcommentformat' => '1',
346 'flagged' => '0',
347 );
348 $qstates = array(
349 259 => (object) array(
350 'id' => '259',
351 'attempt' => '14',
352 'question' => '16',
353 'seq_number' => '0',
354 'answer' => 'dataset4-|||||',
355 'timestamp' => '1305830661',
356 'event' => '0',
357 'grade' => '0.0000000',
358 'raw_grade' => '0.0000000',
359 'penalty' => '0.0000000',
360 ),
361 262 => (object) array(
362 'id' => '262',
363 'attempt' => '14',
364 'question' => '16',
365 'seq_number' => '1',
366 'answer' => 'dataset4-9.00|||||',
367 'timestamp' => '1305830668',
368 'event' => '3',
369 'grade' => '0.0000000',
370 'raw_grade' => '0.0000000',
371 'penalty' => '0.1000000',
372 ),
373 263 => (object) array(
374 'id' => '263',
375 'attempt' => '14',
376 'question' => '16',
377 'seq_number' => '2',
378 'answer' => 'dataset4-15.40|||||',
379 'timestamp' => '1305830679',
380 'event' => '3',
381 'grade' => '0.9000000',
382 'raw_grade' => '1.0000000',
383 'penalty' => '0.1000000',
384 ),
385 267 => (object) array(
386 'id' => '267',
387 'attempt' => '14',
388 'question' => '16',
389 'seq_number' => '3',
390 'answer' => 'dataset4-15.40|||||',
391 'timestamp' => '1305830679',
392 'event' => '6',
393 'grade' => '0.9000000',
394 'raw_grade' => '1.0000000',
395 'penalty' => '0.1000000',
396 ),
397 );
398 $this->loader->put_dataset_in_cache($question->id, 4, array('a' => '6.4', 'b' => '9'));
399
400 $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
401
402 $expectedqa = (object) array(
403 'behaviour' => 'adaptive',
404 'questionid' => 16,
405 'variant' => 4,
406 'maxmark' => 1.0000000,
407 'minfraction' => 0,
408 'flagged' => 0,
409 'questionsummary' => 'What is 6.4 + 9 ?',
410 'rightanswer' => '15.4',
411 'responsesummary' => '15.40',
412 'timemodified' => 1305830679,
413 'steps' => array(
414 0 => (object) array(
415 'sequencenumber' => 0,
416 'state' => 'todo',
417 'fraction' => null,
418 'timecreated' => 1305830661,
419 'userid' => 4,
420 'data' => array('_separators' => '.$,',
421 '_var_a' => '6.4', '_var_b' => '9'),
422 ),
423 1 => (object) array(
424 'sequencenumber' => 1,
425 'state' => 'todo',
426 'fraction' => 0,
427 'timecreated' => 1305830668,
428 'userid' => 4,
429 'data' => array('answer' => '9.00', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 0),
430 ),
431 2 => (object) array(
432 'sequencenumber' => 2,
433 'state' => 'todo',
434 'fraction' => 0.9,
435 'timecreated' => 1305830679,
436 'userid' => 4,
437 'data' => array('answer' => '15.40', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 1),
438 ),
439 3 => (object) array(
440 'sequencenumber' => 3,
441 'state' => 'gradedright',
442 'fraction' => 0.9,
443 'timecreated' => 1305830679,
444 'userid' => 4,
445 'data' => array('answer' => '15.40', '-finish' => 1, '-_try' => 2, '-_rawfraction' => 1),
446 ),
447 ),
448 );
449
450 $this->compare_qas($expectedqa, $qa);
451 }
452
453 public function test_calculatedsimple_adaptive_qsession101() {
454 $quiz = (object) array(
455 'id' => '4',
456 'course' => '2',
457 'name' => 'Calculated quiz',
458 'intro' => '',
459 'introformat' => '1',
460 'timeopen' => '0',
461 'timeclose' => '0',
462 'attempts' => '0',
463 'attemptonlast' => '0',
464 'grademethod' => '1',
465 'decimalpoints' => '2',
466 'questiondecimalpoints' => '-1',
467 'questionsperpage' => '1',
468 'shufflequestions' => '0',
469 'shuffleanswers' => '1',
470 'questions' => '16,0,17,0,18,0',
471 'sumgrades' => '3.00000',
472 'grade' => '10.00000',
473 'timecreated' => '0',
474 'timemodified' => '1305648351',
475 'timelimit' => '0',
476 'password' => '',
477 'subnet' => '',
478 'popup' => '0',
479 'delay1' => '0',
480 'delay2' => '0',
481 'showuserpicture' => '0',
482 'showblocks' => '0',
483 'preferredbehaviour' => 'adaptive',
484 'reviewattempt' => '69888',
485 'reviewcorrectness' => '69888',
486 'reviewmarks' => '69888',
487 'reviewspecificfeedback' => '69888',
488 'reviewgeneralfeedback' => '69888',
489 'reviewrightanswer' => '69888',
490 'reviewoverallfeedback' => '4352',
491 );
492 $attempt = (object) array(
493 'id' => '15',
494 'uniqueid' => '15',
495 'quiz' => '4',
496 'userid' => '3',
497 'attempt' => '1',
498 'sumgrades' => '0.70000',
499 'timestart' => '1305830744',
500 'timefinish' => '0',
501 'timemodified' => '1305830792',
502 'layout' => '16,0,17,0,18,0',
503 'preview' => '0',
504 'needsupgradetonewqe' => 1,
505 );
506 $question = (object) array(
507 'id' => '16',
508 'category' => '2',
509 'parent' => '0',
510 'name' => 'Calculated simple',
511 'questiontext' => '<p>What is {={a}} + {={b}} ?</p>',
512 'questiontextformat' => '1',
513 'generalfeedback' => '',
514 'generalfeedbackformat' => '1',
515 'defaultmark' => '1.0000000',
516 'penalty' => '0.1',
517 'qtype' => 'calculatedsimple',
518 'length' => '1',
519 'stamp' => 'tjh238.vledev2.open.ac.uk+110517161007+2Barhu',
520 'version' => 'tjh238.vledev2.open.ac.uk+110517161008+Mu6OQu',
521 'hidden' => '0',
522 'timecreated' => '1305648607',
523 'timemodified' => '1305648607',
524 'createdby' => '2',
525 'modifiedby' => '2',
526 'maxmark' => '1.0000000',
527 'options' => (object) array(
528 'synchronize' => 0,
529 'single' => 0,
530 'answernumbering' => 'abc',
531 'shuffleanswers' => 0,
532 'correctfeedback' => '',
533 'partiallycorrectfeedback' => '',
534 'incorrectfeedback' => '',
535 'correctfeedbackformat' => 0,
536 'partiallycorrectfeedbackformat' => 0,
537 'incorrectfeedbackformat' => 0,
538 'answers' => array(
539 23 => (object) array(
540 'id' => '23',
541 'question' => '16',
542 'answer' => '{a} + {b}',
543 'answerformat' => '0',
544 'fraction' => '1.0000000',
545 'feedback' => '<p>Well done!</p>',
546 'feedbackformat' => '1',
547 'tolerance' => '0.01',
548 'tolerancetype' => '1',
549 'correctanswerlength' => '2',
550 'correctanswerformat' => '1',
551 ),
552 ),
553 'units' => array(
554 ),
555 'unitgradingtype' => '0',
556 'unitpenalty' => '0.1000000',
557 'showunits' => '3',
558 'unitsleft' => '0',
559 ),
560 'hints' => array(
561 ),
562 );
563 $qsession = (object) array(
564 'id' => '101',
565 'attemptid' => '15',
566 'questionid' => '16',
567 'newest' => '273',
568 'newgraded' => '270',
569 'sumpenalty' => '0.0000000',
570 'manualcomment' => '',
571 'manualcommentformat' => '1',
572 'flagged' => '0',
573 );
574 $qstates = array(
575 270 => (object) array(
576 'id' => '270',
577 'attempt' => '15',
578 'question' => '16',
579 'seq_number' => '0',
580 'answer' => 'dataset6-|||||',
581 'timestamp' => '1305830744',
582 'event' => '0',
583 'grade' => '0.0000000',
584 'raw_grade' => '0.0000000',
585 'penalty' => '0.0000000',
586 ),
587 273 => (object) array(
588 'id' => '273',
589 'attempt' => '15',
590 'question' => '16',
591 'seq_number' => '1',
592 'answer' => 'dataset6-13.1|||||',
593 'timestamp' => '1305830755',
594 'event' => '2',
595 'grade' => '0.0000000',
596 'raw_grade' => '1.0000000',
597 'penalty' => '0.1000000',
598 ),
599 );
600 $this->loader->put_dataset_in_cache($question->id, 6, array('a' => '6.1', 'b' => '7'));
601
602 $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
603
604 $expectedqa = (object) array(
605 'behaviour' => 'adaptive',
606 'questionid' => 16,
607 'variant' => 6,
608 'maxmark' => 1.0000000,
609 'minfraction' => 0,
610 'flagged' => 0,
611 'questionsummary' => 'What is 6.1 + 7 ?',
612 'rightanswer' => '13.1',
613 'responsesummary' => '13.1',
614 'timemodified' => 1305830755,
615 'steps' => array(
616 0 => (object) array(
617 'sequencenumber' => 0,
618 'state' => 'todo',
619 'fraction' => null,
620 'timecreated' => 1305830744,
621 'userid' => 3,
622 'data' => array('_separators' => '.$,',
623 '_var_a' => '6.1', '_var_b' => '7'),
624 ),
625 1 => (object) array(
626 'sequencenumber' => 1,
627 'state' => 'complete',
628 'fraction' => null,
629 'timecreated' => 1305830755,
630 'userid' => 3,
631 'data' => array('answer' => 13.1),
632 ),
633 ),
634 );
635
636 $this->compare_qas($expectedqa, $qa);
637 }
638}