Merge branch 'MDL-70119-310' of git://github.com/ferranrecio/moodle into MOODLE_310_S...
[moodle.git] / question / type / multianswer / tests / upgradelibnewqe_test.php
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/>.
17 /**
18  * Tests of the upgrade to the new Moodle question engine for attempts at
19  * multianswer questions.
20  *
21  * @package    qtype
22  * @subpackage multianswer
23  * @copyright  2011 The Open University
24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
28 defined('MOODLE_INTERNAL') || die();
30 global $CFG;
31 require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php');
34 /**
35  * Testing the upgrade of multianswer question attempts.
36  *
37  * @copyright  2011 The Open University
38  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39  */
40 class qtype_multianswer_attempt_upgrader_test extends question_attempt_upgrader_test_base {
41     public function test_multianswer_adaptivenopenalty_qsession104() {
42         $quiz = (object) array(
43             'id' => '5',
44             'course' => '2',
45             'name' => 'Multianswer 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             'review' => '4459503',
56             'questionsperpage' => '1',
57             'shufflequestions' => '0',
58             'shuffleanswers' => '1',
59             'sumgrades' => '14.00000',
60             'grade' => '10.00000',
61             'timecreated' => '0',
62             'timemodified' => '1306424728',
63             'timelimit' => '0',
64             'password' => '',
65             'subnet' => '',
66             'popup' => '0',
67             'delay1' => '0',
68             'delay2' => '0',
69             'showuserpicture' => '0',
70             'showblocks' => '0',
71             'preferredbehaviour' => 'adaptivenopenalty',
72         );
73         $attempt = (object) array(
74             'id' => '16',
75             'uniqueid' => '16',
76             'quiz' => '5',
77             'userid' => '4',
78             'attempt' => '1',
79             'sumgrades' => '6.00000',
80             'timestart' => '1306425691',
81             'timefinish' => '1306425746',
82             'timemodified' => '1306425746',
83             'layout' => '28,19,0',
84             'preview' => '0',
85         );
86         $question = (object) array(
87             'id' => '28',
88             'category' => '2',
89             'parent' => '0',
90             'name' => 'Very simple cloze',
91             'questiontext' => '<p>An answer {#1}.</p>',
92             'questiontextformat' => '1',
93             'generalfeedback' => '',
94             'generalfeedbackformat' => '1',
95             'penalty' => '0.1000000',
96             'qtype' => 'multianswer',
97             'length' => '1',
98             'stamp' => 'tjh238.vledev2.open.ac.uk+110526154631+XQLcXi',
99             'version' => 'tjh238.vledev2.open.ac.uk+110526154631+T8hPiI',
100             'hidden' => '0',
101             'timecreated' => '1306424791',
102             'timemodified' => '1306424791',
103             'createdby' => '2',
104             'modifiedby' => '2',
105             'maxmark' => '1.0000000',
106             'options' => (object) array(
107                 'questions' => array(
108                     1 => (object) array(
109                         'id' => '29',
110                         'category' => '2',
111                         'parent' => '28',
112                         'name' => 'Very simple cloze',
113                         'questiontext' => '{1:SHORTANSWER:=frog#Yay!}',
114                         'questiontextformat' => '0',
115                         'generalfeedback' => '',
116                         'generalfeedbackformat' => '1',
117                         'defaultgrade' => '1.0000000',
118                         'penalty' => '0.0000000',
119                         'qtype' => 'shortanswer',
120                         'length' => '1',
121                         'stamp' => 'tjh238.vledev2.open.ac.uk+110526154631+j3BYTL',
122                         'version' => 'tjh238.vledev2.open.ac.uk+110526154631+lxNwQv',
123                         'hidden' => '0',
124                         'timecreated' => '1306424791',
125                         'timemodified' => '1306424791',
126                         'createdby' => '2',
127                         'modifiedby' => '2',
128                         'options' => (object) array(
129                             'answers' => array(
130                                 52 => (object) array(
131                                     'id' => '52',
132                                     'question' => '29',
133                                     'answer' => 'frog',
134                                     'answerformat' => '0',
135                                     'fraction' => '1.0000000',
136                                     'feedback' => 'Yay!',
137                                     'feedbackformat' => '1',
138                                 ),
139                             ),
140                             'usecase' => '0',
141                         ),
142                         'maxgrade' => '1.0000000',
143                     ),
144                 ),
145             ),
146             'defaultmark' => '1.0000000',
147         );
148         $qsession = (object) array(
149             'id' => '104',
150             'attemptid' => '16',
151             'questionid' => '28',
152             'newest' => '285',
153             'newgraded' => '285',
154             'sumpenalty' => '0.1000000',
155             'manualcomment' => '',
156             'manualcommentformat' => '1',
157             'flagged' => '0',
158         );
159         $qstates = array(
160             281 => (object) array(
161                 'id' => '281',
162                 'attempt' => '16',
163                 'question' => '28',
164                 'seq_number' => '0',
165                 'answer' => '1-',
166                 'timestamp' => '1306425691',
167                 'event' => '0',
168                 'grade' => '0.0000000',
169                 'raw_grade' => '0.0000000',
170                 'penalty' => '0.0000000',
171             ),
172             283 => (object) array(
173                 'id' => '283',
174                 'attempt' => '16',
175                 'question' => '28',
176                 'seq_number' => '1',
177                 'answer' => '1-frog',
178                 'timestamp' => '1306425739',
179                 'event' => '2',
180                 'grade' => '0.0000000',
181                 'raw_grade' => '1.0000000',
182                 'penalty' => '0.1000000',
183             ),
184             285 => (object) array(
185                 'id' => '285',
186                 'attempt' => '16',
187                 'question' => '28',
188                 'seq_number' => '2',
189                 'answer' => '1-frog',
190                 'timestamp' => '1306425739',
191                 'event' => '6',
192                 'grade' => '1.0000000',
193                 'raw_grade' => '1.0000000',
194                 'penalty' => '0.1000000',
195             ),
196         );
198         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
200         $expectedqa = (object) array(
201             'behaviour' => 'adaptivenopenalty',
202             'questionid' => 28,
203             'variant' => 1,
204             'maxmark' => 1.0000000,
205             'minfraction' => 0,
206             'maxfraction' => 1,
207             'flagged' => 0,
208             'questionsummary' => 'An answer _____.',
209             'rightanswer' => 'part 1: frog',
210             'responsesummary' => 'part 1: frog',
211             'timemodified' => 1306425739,
212             'steps' => array(
213                 0 => (object) array(
214                     'sequencenumber' => 0,
215                     'state' => 'todo',
216                     'fraction' => null,
217                     'timecreated' => 1306425691,
218                     'userid' => 4,
219                     'data' => array(),
220                 ),
221                 1 => (object) array(
222                     'sequencenumber' => 1,
223                     'state' => 'complete',
224                     'fraction' => null,
225                     'timecreated' => 1306425739,
226                     'userid' => 4,
227                     'data' => array('sub1_answer' => 'frog'),
228                 ),
229                 2 => (object) array(
230                     'sequencenumber' => 2,
231                     'state' => 'gradedright',
232                     'fraction' => 1.0,
233                     'timecreated' => 1306425739,
234                     'userid' => 4,
235                     'data' => array('sub1_answer' => 'frog', '-finish' => '1',
236                             '-_try' => '1', '-_rawfraction' => 1.0),
237                 ),
238             ),
239         );
241         $this->compare_qas($expectedqa, $qa);
242     }
244     public function test_multianswer_adaptivenopenalty_qsession106() {
245         $quiz = (object) array(
246             'id' => '5',
247             'course' => '2',
248             'name' => 'Multianswer quiz',
249             'intro' => '',
250             'introformat' => '1',
251             'timeopen' => '0',
252             'timeclose' => '0',
253             'attempts' => '0',
254             'attemptonlast' => '0',
255             'grademethod' => '1',
256             'decimalpoints' => '2',
257             'questiondecimalpoints' => '-1',
258             'review' => '4459503',
259             'questionsperpage' => '1',
260             'shufflequestions' => '0',
261             'shuffleanswers' => '1',
262             'sumgrades' => '14.00000',
263             'grade' => '10.00000',
264             'timecreated' => '0',
265             'timemodified' => '1306424728',
266             'timelimit' => '0',
267             'password' => '',
268             'subnet' => '',
269             'popup' => '0',
270             'delay1' => '0',
271             'delay2' => '0',
272             'showuserpicture' => '0',
273             'showblocks' => '0',
274             'preferredbehaviour' => 'adaptivenopenalty',
275         );
276         $attempt = (object) array(
277             'id' => '17',
278             'uniqueid' => '17',
279             'quiz' => '5',
280             'userid' => '4',
281             'attempt' => '2',
282             'sumgrades' => '0.00000',
283             'timestart' => '1306425757',
284             'timefinish' => '1306425762',
285             'timemodified' => '1306425762',
286             'layout' => '28,19,0',
287             'preview' => '0',
288         );
289         $question = (object) array(
290             'id' => '28',
291             'category' => '2',
292             'parent' => '0',
293             'name' => 'Very simple cloze',
294             'questiontext' => '<p>An answer {#1}.</p>',
295             'questiontextformat' => '1',
296             'generalfeedback' => '',
297             'generalfeedbackformat' => '1',
298             'penalty' => '0.1000000',
299             'qtype' => 'multianswer',
300             'length' => '1',
301             'stamp' => 'tjh238.vledev2.open.ac.uk+110526154631+XQLcXi',
302             'version' => 'tjh238.vledev2.open.ac.uk+110526154631+T8hPiI',
303             'hidden' => '0',
304             'timecreated' => '1306424791',
305             'timemodified' => '1306424791',
306             'createdby' => '2',
307             'modifiedby' => '2',
308             'maxmark' => '1.0000000',
309             'options' => (object) array(
310                 'questions' => array(
311                     1 => (object) array(
312                         'id' => '29',
313                         'category' => '2',
314                         'parent' => '28',
315                         'name' => 'Very simple cloze',
316                         'questiontext' => '{1:SHORTANSWER:=frog#Yay!}',
317                         'questiontextformat' => '0',
318                         'generalfeedback' => '',
319                         'generalfeedbackformat' => '1',
320                         'defaultgrade' => '1.0000000',
321                         'penalty' => '0.0000000',
322                         'qtype' => 'shortanswer',
323                         'length' => '1',
324                         'stamp' => 'tjh238.vledev2.open.ac.uk+110526154631+j3BYTL',
325                         'version' => 'tjh238.vledev2.open.ac.uk+110526154631+lxNwQv',
326                         'hidden' => '0',
327                         'timecreated' => '1306424791',
328                         'timemodified' => '1306424791',
329                         'createdby' => '2',
330                         'modifiedby' => '2',
331                         'options' => (object) array(
332                             'answers' => array(
333                                 52 => (object) array(
334                                     'id' => '52',
335                                     'question' => '29',
336                                     'answer' => 'frog',
337                                     'answerformat' => '0',
338                                     'fraction' => '1.0000000',
339                                     'feedback' => 'Yay!',
340                                     'feedbackformat' => '1',
341                                 ),
342                             ),
343                             'usecase' => '0',
344                         ),
345                         'maxgrade' => '1.0000000',
346                     ),
347                 ),
348             ),
349             'defaultmark' => '1.0000000',
350         );
351         $qsession = (object) array(
352             'id' => '106',
353             'attemptid' => '17',
354             'questionid' => '28',
355             'newest' => '289',
356             'newgraded' => '289',
357             'sumpenalty' => '0.1000000',
358             'manualcomment' => '',
359             'manualcommentformat' => '1',
360             'flagged' => '0',
361         );
362         $qstates = array(
363             287 => (object) array(
364                 'id' => '287',
365                 'attempt' => '17',
366                 'question' => '28',
367                 'seq_number' => '0',
368                 'answer' => '1-',
369                 'timestamp' => '1306425757',
370                 'event' => '0',
371                 'grade' => '0.0000000',
372                 'raw_grade' => '0.0000000',
373                 'penalty' => '0.0000000',
374             ),
375             289 => (object) array(
376                 'id' => '289',
377                 'attempt' => '17',
378                 'question' => '28',
379                 'seq_number' => '1',
380                 'answer' => '1-',
381                 'timestamp' => '1306425757',
382                 'event' => '6',
383                 'grade' => '0.0000000',
384                 'raw_grade' => '0.0000000',
385                 'penalty' => '0.1000000',
386             ),
387         );
389         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
391         $expectedqa = (object) array(
392             'behaviour' => 'adaptivenopenalty',
393             'questionid' => 28,
394             'variant' => 1,
395             'maxmark' => 1.0000000,
396             'minfraction' => 0,
397             'maxfraction' => 1,
398             'flagged' => 0,
399             'questionsummary' => 'An answer _____.',
400             'rightanswer' => 'part 1: frog',
401             'responsesummary' => 'part 1: ',
402             'timemodified' => 1306425757,
403             'steps' => array(
404                 0 => (object) array(
405                     'sequencenumber' => 0,
406                     'state' => 'todo',
407                     'fraction' => null,
408                     'timecreated' => 1306425757,
409                     'userid' => 4,
410                     'data' => array(),
411                 ),
412                 1 => (object) array(
413                     'sequencenumber' => 1,
414                     'state' => 'gradedwrong',
415                     'fraction' => 0.0,
416                     'timecreated' => 1306425757,
417                     'userid' => 4,
418                     'data' => array('-finish' => '1', '-_try' => '1', '-_rawfraction' => 0.0),
419                 ),
420             ),
421         );
423         $this->compare_qas($expectedqa, $qa);
424     }
426     public function test_multianswer_adaptivenopenalty_qsession108() {
427         $quiz = (object) array(
428             'id' => '5',
429             'course' => '2',
430             'name' => 'Multianswer quiz',
431             'intro' => '',
432             'introformat' => '1',
433             'timeopen' => '0',
434             'timeclose' => '0',
435             'attempts' => '0',
436             'attemptonlast' => '0',
437             'grademethod' => '1',
438             'decimalpoints' => '2',
439             'questiondecimalpoints' => '-1',
440             'review' => '4459503',
441             'questionsperpage' => '1',
442             'shufflequestions' => '0',
443             'shuffleanswers' => '1',
444             'sumgrades' => '14.00000',
445             'grade' => '10.00000',
446             'timecreated' => '0',
447             'timemodified' => '1306424728',
448             'timelimit' => '0',
449             'password' => '',
450             'subnet' => '',
451             'popup' => '0',
452             'delay1' => '0',
453             'delay2' => '0',
454             'showuserpicture' => '0',
455             'showblocks' => '0',
456             'preferredbehaviour' => 'adaptivenopenalty',
457         );
458         $attempt = (object) array(
459             'id' => '18',
460             'uniqueid' => '18',
461             'quiz' => '5',
462             'userid' => '3',
463             'attempt' => '1',
464             'sumgrades' => '10.40000',
465             'timestart' => '1306425784',
466             'timefinish' => '1306425931',
467             'timemodified' => '1306425931',
468             'layout' => '28,19,0',
469             'preview' => '0',
470         );
471         $question = (object) array(
472             'id' => '28',
473             'category' => '2',
474             'parent' => '0',
475             'name' => 'Very simple cloze',
476             'questiontext' => '<p>An answer {#1}.</p>',
477             'questiontextformat' => '1',
478             'generalfeedback' => '',
479             'generalfeedbackformat' => '1',
480             'penalty' => '0.1000000',
481             'qtype' => 'multianswer',
482             'length' => '1',
483             'stamp' => 'tjh238.vledev2.open.ac.uk+110526154631+XQLcXi',
484             'version' => 'tjh238.vledev2.open.ac.uk+110526154631+T8hPiI',
485             'hidden' => '0',
486             'timecreated' => '1306424791',
487             'timemodified' => '1306424791',
488             'createdby' => '2',
489             'modifiedby' => '2',
490             'maxmark' => '1.0000000',
491             'options' => (object) array(
492                 'questions' => array(
493                     1 => (object) array(
494                         'id' => '29',
495                         'category' => '2',
496                         'parent' => '28',
497                         'name' => 'Very simple cloze',
498                         'questiontext' => '{1:SHORTANSWER:=frog#Yay!}',
499                         'questiontextformat' => '0',
500                         'generalfeedback' => '',
501                         'generalfeedbackformat' => '1',
502                         'defaultgrade' => '1.0000000',
503                         'penalty' => '0.0000000',
504                         'qtype' => 'shortanswer',
505                         'length' => '1',
506                         'stamp' => 'tjh238.vledev2.open.ac.uk+110526154631+j3BYTL',
507                         'version' => 'tjh238.vledev2.open.ac.uk+110526154631+lxNwQv',
508                         'hidden' => '0',
509                         'timecreated' => '1306424791',
510                         'timemodified' => '1306424791',
511                         'createdby' => '2',
512                         'modifiedby' => '2',
513                         'options' => (object) array(
514                             'answers' => array(
515                                 52 => (object) array(
516                                     'id' => '52',
517                                     'question' => '29',
518                                     'answer' => 'frog',
519                                     'answerformat' => '0',
520                                     'fraction' => '1.0000000',
521                                     'feedback' => 'Yay!',
522                                     'feedbackformat' => '1',
523                                 ),
524                             ),
525                             'usecase' => '0',
526                         ),
527                         'maxgrade' => '1.0000000',
528                     ),
529                 ),
530             ),
531             'defaultmark' => '1.0000000',
532         );
533         $qsession = (object) array(
534             'id' => '108',
535             'attemptid' => '18',
536             'questionid' => '28',
537             'newest' => '298',
538             'newgraded' => '298',
539             'sumpenalty' => '0.2000000',
540             'manualcomment' => '',
541             'manualcommentformat' => '1',
542             'flagged' => '0',
543         );
544         $qstates = array(
545             291 => (object) array(
546                 'id' => '291',
547                 'attempt' => '18',
548                 'question' => '28',
549                 'seq_number' => '0',
550                 'answer' => '1-',
551                 'timestamp' => '1306425784',
552                 'event' => '0',
553                 'grade' => '0.0000000',
554                 'raw_grade' => '0.0000000',
555                 'penalty' => '0.0000000',
556             ),
557             293 => (object) array(
558                 'id' => '293',
559                 'attempt' => '18',
560                 'question' => '28',
561                 'seq_number' => '1',
562                 'answer' => '1-ds&#0044;&#0045;afg',
563                 'timestamp' => '1306425801',
564                 'event' => '2',
565                 'grade' => '0.0000000',
566                 'raw_grade' => '0.0000000',
567                 'penalty' => '0.1000000',
568             ),
569             297 => (object) array(
570                 'id' => '297',
571                 'attempt' => '18',
572                 'question' => '28',
573                 'seq_number' => '2',
574                 'answer' => '1-frog',
575                 'timestamp' => '1306425917',
576                 'event' => '3',
577                 'grade' => '1.0000000',
578                 'raw_grade' => '1.0000000',
579                 'penalty' => '0.1000000',
580             ),
581             298 => (object) array(
582                 'id' => '298',
583                 'attempt' => '18',
584                 'question' => '28',
585                 'seq_number' => '3',
586                 'answer' => '1-frog',
587                 'timestamp' => '1306425917',
588                 'event' => '6',
589                 'grade' => '1.0000000',
590                 'raw_grade' => '1.0000000',
591                 'penalty' => '0.1000000',
592             ),
593         );
595         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
597         $expectedqa = (object) array(
598             'behaviour' => 'adaptivenopenalty',
599             'questionid' => 28,
600             'variant' => 1,
601             'maxmark' => 1.0000000,
602             'minfraction' => 0,
603             'maxfraction' => 1,
604             'flagged' => 0,
605             'questionsummary' => 'An answer _____.',
606             'rightanswer' => 'part 1: frog',
607             'responsesummary' => 'part 1: frog',
608             'timemodified' => 1306425917,
609             'steps' => array(
610                 0 => (object) array(
611                     'sequencenumber' => 0,
612                     'state' => 'todo',
613                     'fraction' => null,
614                     'timecreated' => 1306425784,
615                     'userid' => 3,
616                     'data' => array(),
617                 ),
618                 1 => (object) array(
619                     'sequencenumber' => 1,
620                     'state' => 'complete',
621                     'fraction' => null,
622                     'timecreated' => 1306425801,
623                     'userid' => 3,
624                     'data' => array('sub1_answer' => 'ds,-afg'),
625                 ),
626                 2 => (object) array(
627                     'sequencenumber' => 2,
628                     'state' => 'complete',
629                     'fraction' => 1,
630                     'timecreated' => 1306425917,
631                     'userid' => 3,
632                     'data' => array('sub1_answer' => 'frog', '-_try' => 1,
633                             '-_rawfraction' => 1.0, '-submit' => 1),
634                 ),
635                 3 => (object) array(
636                     'sequencenumber' => 3,
637                     'state' => 'gradedright',
638                     'fraction' => 1,
639                     'timecreated' => 1306425917,
640                     'userid' => 3,
641                     'data' => array('sub1_answer' => 'frog', '-_try' => 1,
642                             '-_rawfraction' => 1.0, '-finish' => 1),
643                 ),
644             ),
645         );
647         $this->compare_qas($expectedqa, $qa);
648     }
650     public function test_multianswer_adaptivenopenalty_qsession105() {
651         $quiz = (object) array(
652             'id' => '5',
653             'course' => '2',
654             'name' => 'Multianswer quiz',
655             'intro' => '',
656             'introformat' => '1',
657             'timeopen' => '0',
658             'timeclose' => '0',
659             'attempts' => '0',
660             'attemptonlast' => '0',
661             'grademethod' => '1',
662             'decimalpoints' => '2',
663             'questiondecimalpoints' => '-1',
664             'review' => '4459503',
665             'questionsperpage' => '1',
666             'shufflequestions' => '0',
667             'shuffleanswers' => '1',
668             'sumgrades' => '14.00000',
669             'grade' => '10.00000',
670             'timecreated' => '0',
671             'timemodified' => '1306424728',
672             'timelimit' => '0',
673             'password' => '',
674             'subnet' => '',
675             'popup' => '0',
676             'delay1' => '0',
677             'delay2' => '0',
678             'showuserpicture' => '0',
679             'showblocks' => '0',
680             'preferredbehaviour' => 'adaptivenopenalty',
681         );
682         $attempt = (object) array(
683             'id' => '16',
684             'uniqueid' => '16',
685             'quiz' => '5',
686             'userid' => '4',
687             'attempt' => '1',
688             'sumgrades' => '6.00000',
689             'timestart' => '1306425691',
690             'timefinish' => '1306425746',
691             'timemodified' => '1306425746',
692             'layout' => '28,19,0',
693             'preview' => '0',
694         );
695         $question = (object) array(
696             'id' => '19',
697             'category' => '2',
698             'parent' => '0',
699             'name' => 'Cloze',
700             'questiontext' => '<p>This question consists of some text with an answer embedded right  here {#1}</p>
701         <p>and right after that you will have to deal with this short answer  {#2}</p>
702         <p>and finally we have a floating point number  {#3}.</p>
703         <p>The  multichoice question can also be shown in the vertical  display of the standard moodle multiple choice. {#4}</p>
704         <p>Or in an horizontal display that is included here in a table {#5}</p>
705         <p>A shortanswer question where case must match. Write moodle in  upper case letters {#6}</p>
706         <p>Note that addresses like www.moodle.org and smileys :-) all work as normal:</p>
707         <p>a) How good is this? {#7}</p>
708         <p>b) What grade would you give it? {#8}</p>',
709             'questiontextformat' => '1',
710             'generalfeedback' => '',
711             'generalfeedbackformat' => '1',
712             'penalty' => '0.1000000',
713             'qtype' => 'multianswer',
714             'length' => '1',
715             'stamp' => 'tjh238.vledev2.open.ac.uk+110525164438+iwiint',
716             'version' => 'tjh238.vledev2.open.ac.uk+110525164441+AAjnIy',
717             'hidden' => '0',
718             'timecreated' => '1306341878',
719             'timemodified' => '1306341879',
720             'createdby' => '2',
721             'modifiedby' => '2',
722             'maxmark' => '13.0000000',
723             'options' => (object) array(
724                 'questions' => array(
725                     1 => (object) array(
726                         'id' => '20',
727                         'category' => '2',
728                         'parent' => '19',
729                         'name' => 'Cloze',
730                         'questiontext' => '{1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another  wrong answer#Feedback for the other wrong answer~=Correct  answer#Feedback for correct answer~%50%Answer that gives half the  credit#Feedback for half credit answer}',
731                         'questiontextformat' => '0',
732                         'generalfeedback' => '',
733                         'generalfeedbackformat' => '1',
734                         'defaultgrade' => '1.0000000',
735                         'penalty' => '0.0000000',
736                         'qtype' => 'multichoice',
737                         'length' => '1',
738                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164439+cAuJ4r',
739                         'version' => 'tjh238.vledev2.open.ac.uk+110525164439+5bnnys',
740                         'hidden' => '0',
741                         'timecreated' => '1306341879',
742                         'timemodified' => '1306341879',
743                         'createdby' => '2',
744                         'modifiedby' => '2',
745                         'options' => (object) array(
746                             'id' => '3',
747                             'question' => '20',
748                             'layout' => '0',
749                             'answers' => array(
750                                 29 => (object) array(
751                                     'id' => '29',
752                                     'question' => '20',
753                                     'answer' => 'Wrong answer',
754                                     'answerformat' => '1',
755                                     'fraction' => '0.0000000',
756                                     'feedback' => 'Feedback for this wrong answer',
757                                     'feedbackformat' => '1',
758                                 ),
759                                 30 => (object) array(
760                                     'id' => '30',
761                                     'question' => '20',
762                                     'answer' => 'Another  wrong answer',
763                                     'answerformat' => '1',
764                                     'fraction' => '0.0000000',
765                                     'feedback' => 'Feedback for the other wrong answer',
766                                     'feedbackformat' => '1',
767                                 ),
768                                 31 => (object) array(
769                                     'id' => '31',
770                                     'question' => '20',
771                                     'answer' => 'Correct  answer',
772                                     'answerformat' => '1',
773                                     'fraction' => '1.0000000',
774                                     'feedback' => 'Feedback for correct answer',
775                                     'feedbackformat' => '1',
776                                 ),
777                                 32 => (object) array(
778                                     'id' => '32',
779                                     'question' => '20',
780                                     'answer' => 'Answer that gives half the  credit',
781                                     'answerformat' => '1',
782                                     'fraction' => '0.5000000',
783                                     'feedback' => 'Feedback for half credit answer',
784                                     'feedbackformat' => '1',
785                                 ),
786                             ),
787                             'single' => '1',
788                             'shuffleanswers' => '1',
789                             'correctfeedback' => '',
790                             'correctfeedbackformat' => '1',
791                             'partiallycorrectfeedback' => '',
792                             'partiallycorrectfeedbackformat' => '1',
793                             'incorrectfeedback' => '',
794                             'incorrectfeedbackformat' => '1',
795                             'answernumbering' => '0',
796                         ),
797                         'maxgrade' => '1.0000000',
798                     ),
799                     2 => (object) array(
800                         'id' => '21',
801                         'category' => '2',
802                         'parent' => '19',
803                         'name' => 'Cloze',
804                         'questiontext' => '{1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct  answer#Feedback for correct answer~%50%Answer that gives half the  credit#Feedback for half credit answer}',
805                         'questiontextformat' => '0',
806                         'generalfeedback' => '',
807                         'generalfeedbackformat' => '1',
808                         'defaultgrade' => '1.0000000',
809                         'penalty' => '0.0000000',
810                         'qtype' => 'shortanswer',
811                         'length' => '1',
812                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164440+EN6wCk',
813                         'version' => 'tjh238.vledev2.open.ac.uk+110525164440+bQzatI',
814                         'hidden' => '0',
815                         'timecreated' => '1306341880',
816                         'timemodified' => '1306341880',
817                         'createdby' => '2',
818                         'modifiedby' => '2',
819                         'options' => (object) array(
820                             'answers' => array(
821                                 33 => (object) array(
822                                     'id' => '33',
823                                     'question' => '21',
824                                     'answer' => 'Wrong answer',
825                                     'answerformat' => '0',
826                                     'fraction' => '0.0000000',
827                                     'feedback' => 'Feedback for this wrong answer',
828                                     'feedbackformat' => '1',
829                                 ),
830                                 34 => (object) array(
831                                     'id' => '34',
832                                     'question' => '21',
833                                     'answer' => 'Correct  answer',
834                                     'answerformat' => '0',
835                                     'fraction' => '1.0000000',
836                                     'feedback' => 'Feedback for correct answer',
837                                     'feedbackformat' => '1',
838                                 ),
839                                 35 => (object) array(
840                                     'id' => '35',
841                                     'question' => '21',
842                                     'answer' => 'Answer that gives half the  credit',
843                                     'answerformat' => '0',
844                                     'fraction' => '0.5000000',
845                                     'feedback' => 'Feedback for half credit answer',
846                                     'feedbackformat' => '1',
847                                 ),
848                             ),
849                             'usecase' => '0',
850                         ),
851                         'maxgrade' => '1.0000000',
852                     ),
853                     3 => (object) array(
854                         'id' => '22',
855                         'category' => '2',
856                         'parent' => '19',
857                         'name' => 'Cloze',
858                         'questiontext' => '{2:NUMERICAL:=23.8:0.1#Feedback for correct answer  23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of  the correct answer}',
859                         'questiontextformat' => '0',
860                         'generalfeedback' => '',
861                         'generalfeedbackformat' => '1',
862                         'defaultgrade' => '2.0000000',
863                         'penalty' => '0.0000000',
864                         'qtype' => 'numerical',
865                         'length' => '1',
866                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164440+Xr29c2',
867                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+QTwsGM',
868                         'hidden' => '0',
869                         'timecreated' => '1306341880',
870                         'timemodified' => '1306341880',
871                         'createdby' => '2',
872                         'modifiedby' => '2',
873                         'options' => (object) array(
874                             'answers' => array(
875                                 36 => (object) array(
876                                     'id' => '36',
877                                     'question' => '22',
878                                     'answer' => '23.8',
879                                     'answerformat' => '0',
880                                     'fraction' => '1.0000000',
881                                     'feedback' => 'Feedback for correct answer  23.8',
882                                     'feedbackformat' => '1',
883                                     'tolerance' => '0.1',
884                                 ),
885                                 37 => (object) array(
886                                     'id' => '37',
887                                     'question' => '22',
888                                     'answer' => '23.8',
889                                     'answerformat' => '0',
890                                     'fraction' => '0.5000000',
891                                     'feedback' => 'Feedback for half credit answer in the nearby region of  the correct answer',
892                                     'feedbackformat' => '1',
893                                     'tolerance' => '2',
894                                 ),
895                             ),
896                             'units' => array(
897                             ),
898                             'unitgradingtype' => '0',
899                             'unitpenalty' => '1.0000000',
900                             'showunits' => '3',
901                             'unitsleft' => '0',
902                             'instructions' => '',
903                             'instructionsformat' => '1',
904                         ),
905                         'maxgrade' => '2.0000000',
906                     ),
907                     4 => (object) array(
908                         'id' => '23',
909                         'category' => '2',
910                         'parent' => '19',
911                         'name' => 'Cloze',
912                         'questiontext' => '{2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong  answer#Feedback for the other wrong answer~=3. Correct answer#Feedback  for correct answer~%50%4. Answer that gives half the credit#Feedback for  half credit answer}',
913                         'questiontextformat' => '0',
914                         'generalfeedback' => '',
915                         'generalfeedbackformat' => '1',
916                         'defaultgrade' => '2.0000000',
917                         'penalty' => '0.0000000',
918                         'qtype' => 'multichoice',
919                         'length' => '1',
920                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+7R55HA',
921                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+uCMoQc',
922                         'hidden' => '0',
923                         'timecreated' => '1306341881',
924                         'timemodified' => '1306341881',
925                         'createdby' => '2',
926                         'modifiedby' => '2',
927                         'options' => (object) array(
928                             'id' => '4',
929                             'question' => '23',
930                             'layout' => '1',
931                             'answers' => array(
932                                 38 => (object) array(
933                                     'id' => '38',
934                                     'question' => '23',
935                                     'answer' => '1. Wrong answer',
936                                     'answerformat' => '1',
937                                     'fraction' => '0.0000000',
938                                     'feedback' => 'Feedback for this wrong answer',
939                                     'feedbackformat' => '1',
940                                 ),
941                                 39 => (object) array(
942                                     'id' => '39',
943                                     'question' => '23',
944                                     'answer' => '2. Another wrong  answer',
945                                     'answerformat' => '1',
946                                     'fraction' => '0.0000000',
947                                     'feedback' => 'Feedback for the other wrong answer',
948                                     'feedbackformat' => '1',
949                                 ),
950                                 40 => (object) array(
951                                     'id' => '40',
952                                     'question' => '23',
953                                     'answer' => '3. Correct answer',
954                                     'answerformat' => '1',
955                                     'fraction' => '1.0000000',
956                                     'feedback' => 'Feedback  for correct answer',
957                                     'feedbackformat' => '1',
958                                 ),
959                                 41 => (object) array(
960                                     'id' => '41',
961                                     'question' => '23',
962                                     'answer' => '4. Answer that gives half the credit',
963                                     'answerformat' => '1',
964                                     'fraction' => '0.5000000',
965                                     'feedback' => 'Feedback for  half credit answer',
966                                     'feedbackformat' => '1',
967                                 ),
968                             ),
969                             'single' => '1',
970                             'shuffleanswers' => '1',
971                             'correctfeedback' => '',
972                             'correctfeedbackformat' => '1',
973                             'partiallycorrectfeedback' => '',
974                             'partiallycorrectfeedbackformat' => '1',
975                             'incorrectfeedback' => '',
976                             'incorrectfeedbackformat' => '1',
977                             'answernumbering' => '0',
978                         ),
979                         'maxgrade' => '2.0000000',
980                     ),
981                     5 => (object) array(
982                         'id' => '24',
983                         'category' => '2',
984                         'parent' => '19',
985                         'name' => 'Cloze',
986                         'questiontext' => '{2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong  answer#Feedback for the other wrong answer~=c. Correct answer#Feedback  for correct answer~%50%d. Answer that gives half the credit#Feedback for  half credit answer}',
987                         'questiontextformat' => '0',
988                         'generalfeedback' => '',
989                         'generalfeedbackformat' => '1',
990                         'defaultgrade' => '2.0000000',
991                         'penalty' => '0.0000000',
992                         'qtype' => 'multichoice',
993                         'length' => '1',
994                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+QGvRpd',
995                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+03GsSs',
996                         'hidden' => '0',
997                         'timecreated' => '1306341881',
998                         'timemodified' => '1306341881',
999                         'createdby' => '2',
1000                         'modifiedby' => '2',
1001                         'options' => (object) array(
1002                             'id' => '5',
1003                             'question' => '24',
1004                             'layout' => '2',
1005                             'answers' => array(
1006                                 42 => (object) array(
1007                                     'id' => '42',
1008                                     'question' => '24',
1009                                     'answer' => 'a. Wrong answer',
1010                                     'answerformat' => '1',
1011                                     'fraction' => '0.0000000',
1012                                     'feedback' => 'Feedback for this wrong answer',
1013                                     'feedbackformat' => '1',
1014                                 ),
1015                                 43 => (object) array(
1016                                     'id' => '43',
1017                                     'question' => '24',
1018                                     'answer' => 'b. Another wrong  answer',
1019                                     'answerformat' => '1',
1020                                     'fraction' => '0.0000000',
1021                                     'feedback' => 'Feedback for the other wrong answer',
1022                                     'feedbackformat' => '1',
1023                                 ),
1024                                 44 => (object) array(
1025                                     'id' => '44',
1026                                     'question' => '24',
1027                                     'answer' => 'c. Correct answer',
1028                                     'answerformat' => '1',
1029                                     'fraction' => '1.0000000',
1030                                     'feedback' => 'Feedback  for correct answer',
1031                                     'feedbackformat' => '1',
1032                                 ),
1033                                 45 => (object) array(
1034                                     'id' => '45',
1035                                     'question' => '24',
1036                                     'answer' => 'd. Answer that gives half the credit',
1037                                     'answerformat' => '1',
1038                                     'fraction' => '0.5000000',
1039                                     'feedback' => 'Feedback for  half credit answer',
1040                                     'feedbackformat' => '1',
1041                                 ),
1042                             ),
1043                             'single' => '1',
1044                             'shuffleanswers' => '1',
1045                             'correctfeedback' => '',
1046                             'correctfeedbackformat' => '1',
1047                             'partiallycorrectfeedback' => '',
1048                             'partiallycorrectfeedbackformat' => '1',
1049                             'incorrectfeedback' => '',
1050                             'incorrectfeedbackformat' => '1',
1051                             'answernumbering' => '0',
1052                         ),
1053                         'maxgrade' => '2.0000000',
1054                     ),
1055                     6 => (object) array(
1056                         'id' => '25',
1057                         'category' => '2',
1058                         'parent' => '19',
1059                         'name' => 'Cloze',
1060                         'questiontext' => '{1:SHORTANSWER_C:moodle#Feedback for moodle in lower  case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for  only first letter in upper case}',
1061                         'questiontextformat' => '0',
1062                         'generalfeedback' => '',
1063                         'generalfeedbackformat' => '1',
1064                         'defaultgrade' => '1.0000000',
1065                         'penalty' => '0.0000000',
1066                         'qtype' => 'shortanswer',
1067                         'length' => '1',
1068                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+n9ETJC',
1069                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+Bvqo6c',
1070                         'hidden' => '0',
1071                         'timecreated' => '1306341881',
1072                         'timemodified' => '1306341881',
1073                         'createdby' => '2',
1074                         'modifiedby' => '2',
1075                         'options' => (object) array(
1076                             'answers' => array(
1077                                 46 => (object) array(
1078                                     'id' => '46',
1079                                     'question' => '25',
1080                                     'answer' => 'moodle',
1081                                     'answerformat' => '0',
1082                                     'fraction' => '0.0000000',
1083                                     'feedback' => 'Feedback for moodle in lower  case',
1084                                     'feedbackformat' => '1',
1085                                 ),
1086                                 47 => (object) array(
1087                                     'id' => '47',
1088                                     'question' => '25',
1089                                     'answer' => 'MOODLE',
1090                                     'answerformat' => '0',
1091                                     'fraction' => '1.0000000',
1092                                     'feedback' => 'Feedback for MOODLE in upper case',
1093                                     'feedbackformat' => '1',
1094                                 ),
1095                                 48 => (object) array(
1096                                     'id' => '48',
1097                                     'question' => '25',
1098                                     'answer' => 'Moodle',
1099                                     'answerformat' => '0',
1100                                     'fraction' => '0.5000000',
1101                                     'feedback' => 'Feedback for  only first letter in upper case',
1102                                     'feedbackformat' => '1',
1103                                 ),
1104                             ),
1105                             'usecase' => '1',
1106                         ),
1107                         'maxgrade' => '1.0000000',
1108                     ),
1109                     7 => (object) array(
1110                         'id' => '26',
1111                         'category' => '2',
1112                         'parent' => '19',
1113                         'name' => 'Cloze',
1114                         'questiontext' => '{:MULTICHOICE:=Yes#Correct~No#We have a different opinion}',
1115                         'questiontextformat' => '0',
1116                         'generalfeedback' => '',
1117                         'generalfeedbackformat' => '1',
1118                         'defaultgrade' => '1.0000000',
1119                         'penalty' => '0.0000000',
1120                         'qtype' => 'multichoice',
1121                         'length' => '1',
1122                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+0YjnZ7',
1123                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+1giLRX',
1124                         'hidden' => '0',
1125                         'timecreated' => '1306341881',
1126                         'timemodified' => '1306341881',
1127                         'createdby' => '2',
1128                         'modifiedby' => '2',
1129                         'options' => (object) array(
1130                             'id' => '6',
1131                             'question' => '26',
1132                             'layout' => '0',
1133                             'answers' => array(
1134                                 49 => (object) array(
1135                                     'id' => '49',
1136                                     'question' => '26',
1137                                     'answer' => 'Yes',
1138                                     'answerformat' => '1',
1139                                     'fraction' => '1.0000000',
1140                                     'feedback' => 'Correct',
1141                                     'feedbackformat' => '1',
1142                                 ),
1143                                 50 => (object) array(
1144                                     'id' => '50',
1145                                     'question' => '26',
1146                                     'answer' => 'No',
1147                                     'answerformat' => '1',
1148                                     'fraction' => '0.0000000',
1149                                     'feedback' => 'We have a different opinion',
1150                                     'feedbackformat' => '1',
1151                                 ),
1152                             ),
1153                             'single' => '1',
1154                             'shuffleanswers' => '1',
1155                             'correctfeedback' => '',
1156                             'correctfeedbackformat' => '1',
1157                             'partiallycorrectfeedback' => '',
1158                             'partiallycorrectfeedbackformat' => '1',
1159                             'incorrectfeedback' => '',
1160                             'incorrectfeedbackformat' => '1',
1161                             'answernumbering' => '0',
1162                         ),
1163                         'maxgrade' => '1.0000000',
1164                     ),
1165                     8 => (object) array(
1166                         'id' => '27',
1167                         'category' => '2',
1168                         'parent' => '19',
1169                         'name' => 'Cloze',
1170                         'questiontext' => '{3:NUMERICAL:=3:2}',
1171                         'questiontextformat' => '0',
1172                         'generalfeedback' => '',
1173                         'generalfeedbackformat' => '1',
1174                         'defaultgrade' => '3.0000000',
1175                         'penalty' => '0.0000000',
1176                         'qtype' => 'numerical',
1177                         'length' => '1',
1178                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+glbCBN',
1179                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+xWusxR',
1180                         'hidden' => '0',
1181                         'timecreated' => '1306341881',
1182                         'timemodified' => '1306341881',
1183                         'createdby' => '2',
1184                         'modifiedby' => '2',
1185                         'options' => (object) array(
1186                             'answers' => array(
1187                                 51 => (object) array(
1188                                     'id' => '51',
1189                                     'question' => '27',
1190                                     'answer' => '3',
1191                                     'answerformat' => '0',
1192                                     'fraction' => '1.0000000',
1193                                     'feedback' => '',
1194                                     'feedbackformat' => '1',
1195                                     'tolerance' => '2',
1196                                 ),
1197                             ),
1198                             'units' => array(
1199                             ),
1200                             'unitgradingtype' => '0',
1201                             'unitpenalty' => '1.0000000',
1202                             'showunits' => '3',
1203                             'unitsleft' => '0',
1204                             'instructions' => '',
1205                             'instructionsformat' => '1',
1206                         ),
1207                         'maxgrade' => '3.0000000',
1208                     ),
1209                 ),
1210             ),
1211             'defaultmark' => '13.0000000',
1212         );
1213         $qsession = (object) array(
1214             'id' => '105',
1215             'attemptid' => '16',
1216             'questionid' => '19',
1217             'newest' => '286',
1218             'newgraded' => '286',
1219             'sumpenalty' => '2.6000000',
1220             'manualcomment' => '',
1221             'manualcommentformat' => '1',
1222             'flagged' => '0',
1223         );
1224         $qstates = array(
1225             282 => (object) array(
1226                 'id' => '282',
1227                 'attempt' => '16',
1228                 'question' => '19',
1229                 'seq_number' => '0',
1230                 'answer' => '1-,2-,3-,4-,5-,6-,7-,8-',
1231                 'timestamp' => '1306425691',
1232                 'event' => '0',
1233                 'grade' => '0.0000000',
1234                 'raw_grade' => '0.0000000',
1235                 'penalty' => '0.0000000',
1236             ),
1237             284 => (object) array(
1238                 'id' => '284',
1239                 'attempt' => '16',
1240                 'question' => '19',
1241                 'seq_number' => '1',
1242                 'answer' => '1-31,2-dsf,3-sadf,4-39,5-44,6-MOODLE,7-49,8-100%',
1243                 'timestamp' => '1306425739',
1244                 'event' => '3',
1245                 'grade' => '5.0000000',
1246                 'raw_grade' => '5.0000000',
1247                 'penalty' => '1.3000000',
1248             ),
1249             286 => (object) array(
1250                 'id' => '286',
1251                 'attempt' => '16',
1252                 'question' => '19',
1253                 'seq_number' => '2',
1254                 'answer' => '1-31,2-dsf,3-sadf,4-39,5-44,6-MOODLE,7-49,8-100%',
1255                 'timestamp' => '1306425739',
1256                 'event' => '6',
1257                 'grade' => '5.0000000',
1258                 'raw_grade' => '5.0000000',
1259                 'penalty' => '1.3000000',
1260             ),
1261         );
1263         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
1265         $expectedqa = (object) array(
1266             'behaviour' => 'adaptivenopenalty',
1267             'questionid' => '19',
1268             'variant' => 1,
1269             'maxmark' => '13.0000000',
1270             'minfraction' => 0,
1271             'maxfraction' => 1,
1272             'flagged' => 0,
1273             'questionsummary' => 'This question consists of some text with an answer embedded right here {Wrong answer; Another wrong answer; Correct answer; Answer that gives half the credit}
1275 and right after that you will have to deal with this short answer _____
1277 and finally we have a floating point number _____.
1279 The multichoice question can also be shown in the vertical display of the standard moodle multiple choice. {1. Wrong answer; 2. Another wrong answer; 3. Correct answer; 4. Answer that gives half the credit}
1281 Or in an horizontal display that is included here in a table {a. Wrong answer; b. Another wrong answer; c. Correct answer; d. Answer that gives half the credit}
1283 A shortanswer question where case must match. Write moodle in upper case letters _____
1285 Note that addresses like www.moodle.org and smileys :-) all work as normal:
1287 a) How good is this? {Yes; No}
1289 b) What grade would you give it? _____',
1290             'rightanswer' => 'part 1: Correct answer; part 2: Correct answer; part 3: 23.8; part 4: 3. Correct answer; part 5: c. Correct answer; part 6: MOODLE; part 7: Yes; part 8: 3',
1291             'responsesummary' => 'part 1: Correct answer; part 2: dsf; part 3: sadf; part 4: 2. Another wrong answer; part 5: c. Correct answer; part 6: MOODLE; part 7: Yes; part 8: 100%',
1292             'timemodified' => '1306425739',
1293             'steps' => array(
1294                 0 => (object) array(
1295                     'data' => array('_sub1_order' => '29,30,31,32',
1296                         '_sub3_separators' => '.$,', '_sub4_order' => '38,39,40,41',
1297                         '_sub5_order' => '42,43,44,45', '_sub7_order' => '49,50',
1298                         '_sub8_separators' => '.$,'),
1299                     'fraction' => null,
1300                     'timecreated' => 1306425691,
1301                     'userid' => 4,
1302                     'state' => 'todo',
1303                     'sequencenumber' => 0,
1304                 ),
1305                 1 => (object) array(
1306                     'data' => array('sub1_answer' => 2, 'sub2_answer' => 'dsf',
1307                         'sub3_answer' => 'sadf', 'sub4_answer' => 1,
1308                         'sub5_answer' => 2, 'sub6_answer' => 'MOODLE',
1309                         'sub7_answer' => 0, 'sub8_answer' => '100%', '-_try' => 1,
1310                         '-_rawfraction' => 0.38461538461538466, '-submit' => 1),
1311                     'fraction' => 0.38461538461538466,
1312                     'timecreated' => '1306425739',
1313                     'userid' => '4',
1314                     'state' => 'todo',
1315                     'sequencenumber' => 1,
1316                 ),
1317                 2 => (object) array(
1318                     'data' => array('sub1_answer' => 2, 'sub2_answer' => 'dsf',
1319                         'sub3_answer' => 'sadf', 'sub4_answer' => 1,
1320                         'sub5_answer' => 2, 'sub6_answer' => 'MOODLE',
1321                         'sub7_answer' => 0, 'sub8_answer' => '100%', '-finish' => 1,
1322                         '-_try' => 1, '-_rawfraction' => 0.38461538461538466),
1323                     'fraction' => 0.38461538461538466,
1324                     'timecreated' => '1306425739',
1325                     'userid' => '4',
1326                     'state' => 'gradedpartial',
1327                     'sequencenumber' => 2,
1328                 ),
1329             ),
1330         );
1332         $this->compare_qas($expectedqa, $qa);
1333     }
1335     public function test_multianswer_adaptivenopenalty_qsession107() {
1336         $quiz = (object) array(
1337             'id' => '5',
1338             'course' => '2',
1339             'name' => 'Multianswer quiz',
1340             'intro' => '',
1341             'introformat' => '1',
1342             'timeopen' => '0',
1343             'timeclose' => '0',
1344             'attempts' => '0',
1345             'attemptonlast' => '0',
1346             'grademethod' => '1',
1347             'decimalpoints' => '2',
1348             'questiondecimalpoints' => '-1',
1349             'review' => '4459503',
1350             'questionsperpage' => '1',
1351             'shufflequestions' => '0',
1352             'shuffleanswers' => '1',
1353             'sumgrades' => '14.00000',
1354             'grade' => '10.00000',
1355             'timecreated' => '0',
1356             'timemodified' => '1306424728',
1357             'timelimit' => '0',
1358             'password' => '',
1359             'subnet' => '',
1360             'popup' => '0',
1361             'delay1' => '0',
1362             'delay2' => '0',
1363             'showuserpicture' => '0',
1364             'showblocks' => '0',
1365             'preferredbehaviour' => 'adaptivenopenalty',
1366         );
1367         $attempt = (object) array(
1368             'id' => '17',
1369             'uniqueid' => '17',
1370             'quiz' => '5',
1371             'userid' => '4',
1372             'attempt' => '2',
1373             'sumgrades' => '0.00000',
1374             'timestart' => '1306425757',
1375             'timefinish' => '1306425762',
1376             'timemodified' => '1306425762',
1377             'layout' => '28,19,0',
1378             'preview' => '0',
1379         );
1380         $question = (object) array(
1381             'id' => '19',
1382             'category' => '2',
1383             'parent' => '0',
1384             'name' => 'Cloze',
1385             'questiontext' => '<p>This question consists of some text with an answer embedded right  here {#1}</p>
1386         <p>and right after that you will have to deal with this short answer  {#2}</p>
1387         <p>and finally we have a floating point number  {#3}.</p>
1388         <p>The  multichoice question can also be shown in the vertical  display of the standard moodle multiple choice. {#4}</p>
1389         <p>Or in an horizontal display that is included here in a table {#5}</p>
1390         <p>A shortanswer question where case must match. Write moodle in  upper case letters {#6}</p>
1391         <p>Note that addresses like www.moodle.org and smileys :-) all work as normal:</p>
1392         <p>a) How good is this? {#7}</p>
1393         <p>b) What grade would you give it? {#8}</p>',
1394             'questiontextformat' => '1',
1395             'generalfeedback' => '',
1396             'generalfeedbackformat' => '1',
1397             'penalty' => '0.1000000',
1398             'qtype' => 'multianswer',
1399             'length' => '1',
1400             'stamp' => 'tjh238.vledev2.open.ac.uk+110525164438+iwiint',
1401             'version' => 'tjh238.vledev2.open.ac.uk+110525164441+AAjnIy',
1402             'hidden' => '0',
1403             'timecreated' => '1306341878',
1404             'timemodified' => '1306341879',
1405             'createdby' => '2',
1406             'modifiedby' => '2',
1407             'maxmark' => '13.0000000',
1408             'options' => (object) array(
1409                 'questions' => array(
1410                     1 => (object) array(
1411                         'id' => '20',
1412                         'category' => '2',
1413                         'parent' => '19',
1414                         'name' => 'Cloze',
1415                         'questiontext' => '{1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another  wrong answer#Feedback for the other wrong answer~=Correct  answer#Feedback for correct answer~%50%Answer that gives half the  credit#Feedback for half credit answer}',
1416                         'questiontextformat' => '0',
1417                         'generalfeedback' => '',
1418                         'generalfeedbackformat' => '1',
1419                         'defaultgrade' => '1.0000000',
1420                         'penalty' => '0.0000000',
1421                         'qtype' => 'multichoice',
1422                         'length' => '1',
1423                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164439+cAuJ4r',
1424                         'version' => 'tjh238.vledev2.open.ac.uk+110525164439+5bnnys',
1425                         'hidden' => '0',
1426                         'timecreated' => '1306341879',
1427                         'timemodified' => '1306341879',
1428                         'createdby' => '2',
1429                         'modifiedby' => '2',
1430                         'options' => (object) array(
1431                             'id' => '3',
1432                             'question' => '20',
1433                             'layout' => '0',
1434                             'answers' => array(
1435                                 29 => (object) array(
1436                                     'id' => '29',
1437                                     'question' => '20',
1438                                     'answer' => 'Wrong answer',
1439                                     'answerformat' => '1',
1440                                     'fraction' => '0.0000000',
1441                                     'feedback' => 'Feedback for this wrong answer',
1442                                     'feedbackformat' => '1',
1443                                 ),
1444                                 30 => (object) array(
1445                                     'id' => '30',
1446                                     'question' => '20',
1447                                     'answer' => 'Another  wrong answer',
1448                                     'answerformat' => '1',
1449                                     'fraction' => '0.0000000',
1450                                     'feedback' => 'Feedback for the other wrong answer',
1451                                     'feedbackformat' => '1',
1452                                 ),
1453                                 31 => (object) array(
1454                                     'id' => '31',
1455                                     'question' => '20',
1456                                     'answer' => 'Correct  answer',
1457                                     'answerformat' => '1',
1458                                     'fraction' => '1.0000000',
1459                                     'feedback' => 'Feedback for correct answer',
1460                                     'feedbackformat' => '1',
1461                                 ),
1462                                 32 => (object) array(
1463                                     'id' => '32',
1464                                     'question' => '20',
1465                                     'answer' => 'Answer that gives half the  credit',
1466                                     'answerformat' => '1',
1467                                     'fraction' => '0.5000000',
1468                                     'feedback' => 'Feedback for half credit answer',
1469                                     'feedbackformat' => '1',
1470                                 ),
1471                             ),
1472                             'single' => '1',
1473                             'shuffleanswers' => '1',
1474                             'correctfeedback' => '',
1475                             'correctfeedbackformat' => '1',
1476                             'partiallycorrectfeedback' => '',
1477                             'partiallycorrectfeedbackformat' => '1',
1478                             'incorrectfeedback' => '',
1479                             'incorrectfeedbackformat' => '1',
1480                             'answernumbering' => '0',
1481                         ),
1482                         'maxgrade' => '1.0000000',
1483                     ),
1484                     2 => (object) array(
1485                         'id' => '21',
1486                         'category' => '2',
1487                         'parent' => '19',
1488                         'name' => 'Cloze',
1489                         'questiontext' => '{1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct  answer#Feedback for correct answer~%50%Answer that gives half the  credit#Feedback for half credit answer}',
1490                         'questiontextformat' => '0',
1491                         'generalfeedback' => '',
1492                         'generalfeedbackformat' => '1',
1493                         'defaultgrade' => '1.0000000',
1494                         'penalty' => '0.0000000',
1495                         'qtype' => 'shortanswer',
1496                         'length' => '1',
1497                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164440+EN6wCk',
1498                         'version' => 'tjh238.vledev2.open.ac.uk+110525164440+bQzatI',
1499                         'hidden' => '0',
1500                         'timecreated' => '1306341880',
1501                         'timemodified' => '1306341880',
1502                         'createdby' => '2',
1503                         'modifiedby' => '2',
1504                         'options' => (object) array(
1505                             'answers' => array(
1506                                 33 => (object) array(
1507                                     'id' => '33',
1508                                     'question' => '21',
1509                                     'answer' => 'Wrong answer',
1510                                     'answerformat' => '0',
1511                                     'fraction' => '0.0000000',
1512                                     'feedback' => 'Feedback for this wrong answer',
1513                                     'feedbackformat' => '1',
1514                                 ),
1515                                 34 => (object) array(
1516                                     'id' => '34',
1517                                     'question' => '21',
1518                                     'answer' => 'Correct  answer',
1519                                     'answerformat' => '0',
1520                                     'fraction' => '1.0000000',
1521                                     'feedback' => 'Feedback for correct answer',
1522                                     'feedbackformat' => '1',
1523                                 ),
1524                                 35 => (object) array(
1525                                     'id' => '35',
1526                                     'question' => '21',
1527                                     'answer' => 'Answer that gives half the  credit',
1528                                     'answerformat' => '0',
1529                                     'fraction' => '0.5000000',
1530                                     'feedback' => 'Feedback for half credit answer',
1531                                     'feedbackformat' => '1',
1532                                 ),
1533                             ),
1534                             'usecase' => '0',
1535                         ),
1536                         'maxgrade' => '1.0000000',
1537                     ),
1538                     3 => (object) array(
1539                         'id' => '22',
1540                         'category' => '2',
1541                         'parent' => '19',
1542                         'name' => 'Cloze',
1543                         'questiontext' => '{2:NUMERICAL:=23.8:0.1#Feedback for correct answer  23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of  the correct answer}',
1544                         'questiontextformat' => '0',
1545                         'generalfeedback' => '',
1546                         'generalfeedbackformat' => '1',
1547                         'defaultgrade' => '2.0000000',
1548                         'penalty' => '0.0000000',
1549                         'qtype' => 'numerical',
1550                         'length' => '1',
1551                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164440+Xr29c2',
1552                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+QTwsGM',
1553                         'hidden' => '0',
1554                         'timecreated' => '1306341880',
1555                         'timemodified' => '1306341880',
1556                         'createdby' => '2',
1557                         'modifiedby' => '2',
1558                         'options' => (object) array(
1559                             'answers' => array(
1560                                 36 => (object) array(
1561                                     'id' => '36',
1562                                     'question' => '22',
1563                                     'answer' => '23.8',
1564                                     'answerformat' => '0',
1565                                     'fraction' => '1.0000000',
1566                                     'feedback' => 'Feedback for correct answer  23.8',
1567                                     'feedbackformat' => '1',
1568                                     'tolerance' => '0.1',
1569                                 ),
1570                                 37 => (object) array(
1571                                     'id' => '37',
1572                                     'question' => '22',
1573                                     'answer' => '23.8',
1574                                     'answerformat' => '0',
1575                                     'fraction' => '0.5000000',
1576                                     'feedback' => 'Feedback for half credit answer in the nearby region of  the correct answer',
1577                                     'feedbackformat' => '1',
1578                                     'tolerance' => '2',
1579                                 ),
1580                             ),
1581                             'units' => array(
1582                             ),
1583                             'unitgradingtype' => '0',
1584                             'unitpenalty' => '1.0000000',
1585                             'showunits' => '3',
1586                             'unitsleft' => '0',
1587                             'instructions' => '',
1588                             'instructionsformat' => '1',
1589                         ),
1590                         'maxgrade' => '2.0000000',
1591                     ),
1592                     4 => (object) array(
1593                         'id' => '23',
1594                         'category' => '2',
1595                         'parent' => '19',
1596                         'name' => 'Cloze',
1597                         'questiontext' => '{2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong  answer#Feedback for the other wrong answer~=3. Correct answer#Feedback  for correct answer~%50%4. Answer that gives half the credit#Feedback for  half credit answer}',
1598                         'questiontextformat' => '0',
1599                         'generalfeedback' => '',
1600                         'generalfeedbackformat' => '1',
1601                         'defaultgrade' => '2.0000000',
1602                         'penalty' => '0.0000000',
1603                         'qtype' => 'multichoice',
1604                         'length' => '1',
1605                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+7R55HA',
1606                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+uCMoQc',
1607                         'hidden' => '0',
1608                         'timecreated' => '1306341881',
1609                         'timemodified' => '1306341881',
1610                         'createdby' => '2',
1611                         'modifiedby' => '2',
1612                         'options' => (object) array(
1613                             'id' => '4',
1614                             'question' => '23',
1615                             'layout' => '1',
1616                             'answers' => array(
1617                                 38 => (object) array(
1618                                     'id' => '38',
1619                                     'question' => '23',
1620                                     'answer' => '1. Wrong answer',
1621                                     'answerformat' => '1',
1622                                     'fraction' => '0.0000000',
1623                                     'feedback' => 'Feedback for this wrong answer',
1624                                     'feedbackformat' => '1',
1625                                 ),
1626                                 39 => (object) array(
1627                                     'id' => '39',
1628                                     'question' => '23',
1629                                     'answer' => '2. Another wrong  answer',
1630                                     'answerformat' => '1',
1631                                     'fraction' => '0.0000000',
1632                                     'feedback' => 'Feedback for the other wrong answer',
1633                                     'feedbackformat' => '1',
1634                                 ),
1635                                 40 => (object) array(
1636                                     'id' => '40',
1637                                     'question' => '23',
1638                                     'answer' => '3. Correct answer',
1639                                     'answerformat' => '1',
1640                                     'fraction' => '1.0000000',
1641                                     'feedback' => 'Feedback  for correct answer',
1642                                     'feedbackformat' => '1',
1643                                 ),
1644                                 41 => (object) array(
1645                                     'id' => '41',
1646                                     'question' => '23',
1647                                     'answer' => '4. Answer that gives half the credit',
1648                                     'answerformat' => '1',
1649                                     'fraction' => '0.5000000',
1650                                     'feedback' => 'Feedback for  half credit answer',
1651                                     'feedbackformat' => '1',
1652                                 ),
1653                             ),
1654                             'single' => '1',
1655                             'shuffleanswers' => '1',
1656                             'correctfeedback' => '',
1657                             'correctfeedbackformat' => '1',
1658                             'partiallycorrectfeedback' => '',
1659                             'partiallycorrectfeedbackformat' => '1',
1660                             'incorrectfeedback' => '',
1661                             'incorrectfeedbackformat' => '1',
1662                             'answernumbering' => '0',
1663                         ),
1664                         'maxgrade' => '2.0000000',
1665                     ),
1666                     5 => (object) array(
1667                         'id' => '24',
1668                         'category' => '2',
1669                         'parent' => '19',
1670                         'name' => 'Cloze',
1671                         'questiontext' => '{2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong  answer#Feedback for the other wrong answer~=c. Correct answer#Feedback  for correct answer~%50%d. Answer that gives half the credit#Feedback for  half credit answer}',
1672                         'questiontextformat' => '0',
1673                         'generalfeedback' => '',
1674                         'generalfeedbackformat' => '1',
1675                         'defaultgrade' => '2.0000000',
1676                         'penalty' => '0.0000000',
1677                         'qtype' => 'multichoice',
1678                         'length' => '1',
1679                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+QGvRpd',
1680                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+03GsSs',
1681                         'hidden' => '0',
1682                         'timecreated' => '1306341881',
1683                         'timemodified' => '1306341881',
1684                         'createdby' => '2',
1685                         'modifiedby' => '2',
1686                         'options' => (object) array(
1687                             'id' => '5',
1688                             'question' => '24',
1689                             'layout' => '2',
1690                             'answers' => array(
1691                                 42 => (object) array(
1692                                     'id' => '42',
1693                                     'question' => '24',
1694                                     'answer' => 'a. Wrong answer',
1695                                     'answerformat' => '1',
1696                                     'fraction' => '0.0000000',
1697                                     'feedback' => 'Feedback for this wrong answer',
1698                                     'feedbackformat' => '1',
1699                                 ),
1700                                 43 => (object) array(
1701                                     'id' => '43',
1702                                     'question' => '24',
1703                                     'answer' => 'b. Another wrong  answer',
1704                                     'answerformat' => '1',
1705                                     'fraction' => '0.0000000',
1706                                     'feedback' => 'Feedback for the other wrong answer',
1707                                     'feedbackformat' => '1',
1708                                 ),
1709                                 44 => (object) array(
1710                                     'id' => '44',
1711                                     'question' => '24',
1712                                     'answer' => 'c. Correct answer',
1713                                     'answerformat' => '1',
1714                                     'fraction' => '1.0000000',
1715                                     'feedback' => 'Feedback  for correct answer',
1716                                     'feedbackformat' => '1',
1717                                 ),
1718                                 45 => (object) array(
1719                                     'id' => '45',
1720                                     'question' => '24',
1721                                     'answer' => 'd. Answer that gives half the credit',
1722                                     'answerformat' => '1',
1723                                     'fraction' => '0.5000000',
1724                                     'feedback' => 'Feedback for  half credit answer',
1725                                     'feedbackformat' => '1',
1726                                 ),
1727                             ),
1728                             'single' => '1',
1729                             'shuffleanswers' => '1',
1730                             'correctfeedback' => '',
1731                             'correctfeedbackformat' => '1',
1732                             'partiallycorrectfeedback' => '',
1733                             'partiallycorrectfeedbackformat' => '1',
1734                             'incorrectfeedback' => '',
1735                             'incorrectfeedbackformat' => '1',
1736                             'answernumbering' => '0',
1737                         ),
1738                         'maxgrade' => '2.0000000',
1739                     ),
1740                     6 => (object) array(
1741                         'id' => '25',
1742                         'category' => '2',
1743                         'parent' => '19',
1744                         'name' => 'Cloze',
1745                         'questiontext' => '{1:SHORTANSWER_C:moodle#Feedback for moodle in lower  case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for  only first letter in upper case}',
1746                         'questiontextformat' => '0',
1747                         'generalfeedback' => '',
1748                         'generalfeedbackformat' => '1',
1749                         'defaultgrade' => '1.0000000',
1750                         'penalty' => '0.0000000',
1751                         'qtype' => 'shortanswer',
1752                         'length' => '1',
1753                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+n9ETJC',
1754                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+Bvqo6c',
1755                         'hidden' => '0',
1756                         'timecreated' => '1306341881',
1757                         'timemodified' => '1306341881',
1758                         'createdby' => '2',
1759                         'modifiedby' => '2',
1760                         'options' => (object) array(
1761                             'answers' => array(
1762                                 46 => (object) array(
1763                                     'id' => '46',
1764                                     'question' => '25',
1765                                     'answer' => 'moodle',
1766                                     'answerformat' => '0',
1767                                     'fraction' => '0.0000000',
1768                                     'feedback' => 'Feedback for moodle in lower  case',
1769                                     'feedbackformat' => '1',
1770                                 ),
1771                                 47 => (object) array(
1772                                     'id' => '47',
1773                                     'question' => '25',
1774                                     'answer' => 'MOODLE',
1775                                     'answerformat' => '0',
1776                                     'fraction' => '1.0000000',
1777                                     'feedback' => 'Feedback for MOODLE in upper case',
1778                                     'feedbackformat' => '1',
1779                                 ),
1780                                 48 => (object) array(
1781                                     'id' => '48',
1782                                     'question' => '25',
1783                                     'answer' => 'Moodle',
1784                                     'answerformat' => '0',
1785                                     'fraction' => '0.5000000',
1786                                     'feedback' => 'Feedback for  only first letter in upper case',
1787                                     'feedbackformat' => '1',
1788                                 ),
1789                             ),
1790                             'usecase' => '1',
1791                         ),
1792                         'maxgrade' => '1.0000000',
1793                     ),
1794                     7 => (object) array(
1795                         'id' => '26',
1796                         'category' => '2',
1797                         'parent' => '19',
1798                         'name' => 'Cloze',
1799                         'questiontext' => '{:MULTICHOICE:=Yes#Correct~No#We have a different opinion}',
1800                         'questiontextformat' => '0',
1801                         'generalfeedback' => '',
1802                         'generalfeedbackformat' => '1',
1803                         'defaultgrade' => '1.0000000',
1804                         'penalty' => '0.0000000',
1805                         'qtype' => 'multichoice',
1806                         'length' => '1',
1807                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+0YjnZ7',
1808                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+1giLRX',
1809                         'hidden' => '0',
1810                         'timecreated' => '1306341881',
1811                         'timemodified' => '1306341881',
1812                         'createdby' => '2',
1813                         'modifiedby' => '2',
1814                         'options' => (object) array(
1815                             'id' => '6',
1816                             'question' => '26',
1817                             'layout' => '0',
1818                             'answers' => array(
1819                                 49 => (object) array(
1820                                     'id' => '49',
1821                                     'question' => '26',
1822                                     'answer' => 'Yes',
1823                                     'answerformat' => '1',
1824                                     'fraction' => '1.0000000',
1825                                     'feedback' => 'Correct',
1826                                     'feedbackformat' => '1',
1827                                 ),
1828                                 50 => (object) array(
1829                                     'id' => '50',
1830                                     'question' => '26',
1831                                     'answer' => 'No',
1832                                     'answerformat' => '1',
1833                                     'fraction' => '0.0000000',
1834                                     'feedback' => 'We have a different opinion',
1835                                     'feedbackformat' => '1',
1836                                 ),
1837                             ),
1838                             'single' => '1',
1839                             'shuffleanswers' => '1',
1840                             'correctfeedback' => '',
1841                             'correctfeedbackformat' => '1',
1842                             'partiallycorrectfeedback' => '',
1843                             'partiallycorrectfeedbackformat' => '1',
1844                             'incorrectfeedback' => '',
1845                             'incorrectfeedbackformat' => '1',
1846                             'answernumbering' => '0',
1847                         ),
1848                         'maxgrade' => '1.0000000',
1849                     ),
1850                     8 => (object) array(
1851                         'id' => '27',
1852                         'category' => '2',
1853                         'parent' => '19',
1854                         'name' => 'Cloze',
1855                         'questiontext' => '{3:NUMERICAL:=3:2}',
1856                         'questiontextformat' => '0',
1857                         'generalfeedback' => '',
1858                         'generalfeedbackformat' => '1',
1859                         'defaultgrade' => '3.0000000',
1860                         'penalty' => '0.0000000',
1861                         'qtype' => 'numerical',
1862                         'length' => '1',
1863                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+glbCBN',
1864                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+xWusxR',
1865                         'hidden' => '0',
1866                         'timecreated' => '1306341881',
1867                         'timemodified' => '1306341881',
1868                         'createdby' => '2',
1869                         'modifiedby' => '2',
1870                         'options' => (object) array(
1871                             'answers' => array(
1872                                 51 => (object) array(
1873                                     'id' => '51',
1874                                     'question' => '27',
1875                                     'answer' => '3',
1876                                     'answerformat' => '0',
1877                                     'fraction' => '1.0000000',
1878                                     'feedback' => '',
1879                                     'feedbackformat' => '1',
1880                                     'tolerance' => '2',
1881                                 ),
1882                             ),
1883                             'units' => array(
1884                             ),
1885                             'unitgradingtype' => '0',
1886                             'unitpenalty' => '1.0000000',
1887                             'showunits' => '3',
1888                             'unitsleft' => '0',
1889                             'instructions' => '',
1890                             'instructionsformat' => '1',
1891                         ),
1892                         'maxgrade' => '3.0000000',
1893                     ),
1894                 ),
1895             ),
1896             'defaultmark' => '13.0000000',
1897         );
1898         $qsession = (object) array(
1899             'id' => '107',
1900             'attemptid' => '17',
1901             'questionid' => '19',
1902             'newest' => '290',
1903             'newgraded' => '290',
1904             'sumpenalty' => '1.3000000',
1905             'manualcomment' => '',
1906             'manualcommentformat' => '1',
1907             'flagged' => '0',
1908         );
1909         $qstates = array(
1910             288 => (object) array(
1911                 'id' => '288',
1912                 'attempt' => '17',
1913                 'question' => '19',
1914                 'seq_number' => '0',
1915                 'answer' => '1-,2-,3-,4-,5-,6-,7-,8-',
1916                 'timestamp' => '1306425757',
1917                 'event' => '0',
1918                 'grade' => '0.0000000',
1919                 'raw_grade' => '0.0000000',
1920                 'penalty' => '0.0000000',
1921             ),
1922             290 => (object) array(
1923                 'id' => '290',
1924                 'attempt' => '17',
1925                 'question' => '19',
1926                 'seq_number' => '1',
1927                 'answer' => '1-,2-,3-,4-,5-,6-,7-,8-',
1928                 'timestamp' => '1306425757',
1929                 'event' => '6',
1930                 'grade' => '0.0000000',
1931                 'raw_grade' => '0.0000000',
1932                 'penalty' => '1.3000000',
1933             ),
1934         );
1936         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
1938         $expectedqa = (object) array(
1939             'behaviour' => 'adaptivenopenalty',
1940             'questionid' => 19,
1941             'variant' => 1,
1942             'maxmark' => 13.0000000,
1943             'minfraction' => 0,
1944             'maxfraction' => 1,
1945             'flagged' => 0,
1946             'questionsummary' => 'This question consists of some text with an answer embedded right here {Wrong answer; Another wrong answer; Correct answer; Answer that gives half the credit}
1948 and right after that you will have to deal with this short answer _____
1950 and finally we have a floating point number _____.
1952 The multichoice question can also be shown in the vertical display of the standard moodle multiple choice. {1. Wrong answer; 2. Another wrong answer; 3. Correct answer; 4. Answer that gives half the credit}
1954 Or in an horizontal display that is included here in a table {a. Wrong answer; b. Another wrong answer; c. Correct answer; d. Answer that gives half the credit}
1956 A shortanswer question where case must match. Write moodle in upper case letters _____
1958 Note that addresses like www.moodle.org and smileys :-) all work as normal:
1960 a) How good is this? {Yes; No}
1962 b) What grade would you give it? _____',
1963             'rightanswer' => 'part 1: Correct answer; part 2: Correct answer; part 3: 23.8; part 4: 3. Correct answer; part 5: c. Correct answer; part 6: MOODLE; part 7: Yes; part 8: 3',
1964             'responsesummary' => 'part 1: ; part 2: ; part 3: ; part 4: ; part 5: ; part 6: ; part 7: ; part 8: ',
1965             'timemodified' => 1306425757,
1966             'steps' => array(
1967                 0 => (object) array(
1968                     'sequencenumber' => 0,
1969                     'state' => 'todo',
1970                     'fraction' => null,
1971                     'timecreated' => 1306425757,
1972                     'userid' => 4,
1973                     'data' => array('_sub1_order' => '29,30,31,32',
1974                             '_sub3_separators' => '.$,', '_sub4_order' => '38,39,40,41',
1975                             '_sub5_order' => '42,43,44,45', '_sub7_order' => '49,50',
1976                             '_sub8_separators' => '.$,'),
1977                 ),
1978                 1 => (object) array(
1979                     'sequencenumber' => 1,
1980                     'state' => 'gradedwrong',
1981                     'fraction' => 0.0,
1982                     'timecreated' => 1306425757,
1983                     'userid' => 4,
1984                     'data' => array('-finish' => '1', '-_try' => '1', '-_rawfraction' => 0.0),
1985                 ),
1986             ),
1987         );
1989         $this->compare_qas($expectedqa, $qa);
1990     }
1992     public function test_multianswer_adaptivenopenalty_qsession109() {
1993         $quiz = (object) array(
1994             'id' => '5',
1995             'course' => '2',
1996             'name' => 'Multianswer quiz',
1997             'intro' => '',
1998             'introformat' => '1',
1999             'timeopen' => '0',
2000             'timeclose' => '0',
2001             'attempts' => '0',
2002             'attemptonlast' => '0',
2003             'grademethod' => '1',
2004             'decimalpoints' => '2',
2005             'questiondecimalpoints' => '-1',
2006             'review' => '4459503',
2007             'questionsperpage' => '1',
2008             'shufflequestions' => '0',
2009             'shuffleanswers' => '1',
2010             'sumgrades' => '14.00000',
2011             'grade' => '10.00000',
2012             'timecreated' => '0',
2013             'timemodified' => '1306424728',
2014             'timelimit' => '0',
2015             'password' => '',
2016             'subnet' => '',
2017             'popup' => '0',
2018             'delay1' => '0',
2019             'delay2' => '0',
2020             'showuserpicture' => '0',
2021             'showblocks' => '0',
2022             'preferredbehaviour' => 'adaptivenopenalty',
2023         );
2024         $attempt = (object) array(
2025             'id' => '18',
2026             'uniqueid' => '18',
2027             'quiz' => '5',
2028             'userid' => '3',
2029             'attempt' => '1',
2030             'sumgrades' => '10.40000',
2031             'timestart' => '1306425784',
2032             'timefinish' => '1306425931',
2033             'timemodified' => '1306425931',
2034             'layout' => '28,19,0',
2035             'preview' => '0',
2036         );
2037         $question = (object) array(
2038             'id' => '19',
2039             'category' => '2',
2040             'parent' => '0',
2041             'name' => 'Cloze',
2042             'questiontext' => '<p>This question consists of some text with an answer embedded right  here {#1}</p>
2043         <p>and right after that you will have to deal with this short answer  {#2}</p>
2044         <p>and finally we have a floating point number  {#3}.</p>
2045         <p>The  multichoice question can also be shown in the vertical  display of the standard moodle multiple choice. {#4}</p>
2046         <p>Or in an horizontal display that is included here in a table {#5}</p>
2047         <p>A shortanswer question where case must match. Write moodle in  upper case letters {#6}</p>
2048         <p>Note that addresses like www.moodle.org and smileys :-) all work as normal:</p>
2049         <p>a) How good is this? {#7}</p>
2050         <p>b) What grade would you give it? {#8}</p>',
2051             'questiontextformat' => '1',
2052             'generalfeedback' => '',
2053             'generalfeedbackformat' => '1',
2054             'penalty' => '0.1000000',
2055             'qtype' => 'multianswer',
2056             'length' => '1',
2057             'stamp' => 'tjh238.vledev2.open.ac.uk+110525164438+iwiint',
2058             'version' => 'tjh238.vledev2.open.ac.uk+110525164441+AAjnIy',
2059             'hidden' => '0',
2060             'timecreated' => '1306341878',
2061             'timemodified' => '1306341879',
2062             'createdby' => '2',
2063             'modifiedby' => '2',
2064             'maxmark' => '13.0000000',
2065             'options' => (object) array(
2066                 'questions' => array(
2067                     1 => (object) array(
2068                         'id' => '20',
2069                         'category' => '2',
2070                         'parent' => '19',
2071                         'name' => 'Cloze',
2072                         'questiontext' => '{1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another  wrong answer#Feedback for the other wrong answer~=Correct  answer#Feedback for correct answer~%50%Answer that gives half the  credit#Feedback for half credit answer}',
2073                         'questiontextformat' => '0',
2074                         'generalfeedback' => '',
2075                         'generalfeedbackformat' => '1',
2076                         'defaultgrade' => '1.0000000',
2077                         'penalty' => '0.0000000',
2078                         'qtype' => 'multichoice',
2079                         'length' => '1',
2080                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164439+cAuJ4r',
2081                         'version' => 'tjh238.vledev2.open.ac.uk+110525164439+5bnnys',
2082                         'hidden' => '0',
2083                         'timecreated' => '1306341879',
2084                         'timemodified' => '1306341879',
2085                         'createdby' => '2',
2086                         'modifiedby' => '2',
2087                         'options' => (object) array(
2088                             'id' => '3',
2089                             'question' => '20',
2090                             'layout' => '0',
2091                             'answers' => array(
2092                                 29 => (object) array(
2093                                     'id' => '29',
2094                                     'question' => '20',
2095                                     'answer' => 'Wrong answer',
2096                                     'answerformat' => '1',
2097                                     'fraction' => '0.0000000',
2098                                     'feedback' => 'Feedback for this wrong answer',
2099                                     'feedbackformat' => '1',
2100                                 ),
2101                                 30 => (object) array(
2102                                     'id' => '30',
2103                                     'question' => '20',
2104                                     'answer' => 'Another  wrong answer',
2105                                     'answerformat' => '1',
2106                                     'fraction' => '0.0000000',
2107                                     'feedback' => 'Feedback for the other wrong answer',
2108                                     'feedbackformat' => '1',
2109                                 ),
2110                                 31 => (object) array(
2111                                     'id' => '31',
2112                                     'question' => '20',
2113                                     'answer' => 'Correct  answer',
2114                                     'answerformat' => '1',
2115                                     'fraction' => '1.0000000',
2116                                     'feedback' => 'Feedback for correct answer',
2117                                     'feedbackformat' => '1',
2118                                 ),
2119                                 32 => (object) array(
2120                                     'id' => '32',
2121                                     'question' => '20',
2122                                     'answer' => 'Answer that gives half the  credit',
2123                                     'answerformat' => '1',
2124                                     'fraction' => '0.5000000',
2125                                     'feedback' => 'Feedback for half credit answer',
2126                                     'feedbackformat' => '1',
2127                                 ),
2128                             ),
2129                             'single' => '1',
2130                             'shuffleanswers' => '1',
2131                             'correctfeedback' => '',
2132                             'correctfeedbackformat' => '1',
2133                             'partiallycorrectfeedback' => '',
2134                             'partiallycorrectfeedbackformat' => '1',
2135                             'incorrectfeedback' => '',
2136                             'incorrectfeedbackformat' => '1',
2137                             'answernumbering' => '0',
2138                         ),
2139                         'maxgrade' => '1.0000000',
2140                     ),
2141                     2 => (object) array(
2142                         'id' => '21',
2143                         'category' => '2',
2144                         'parent' => '19',
2145                         'name' => 'Cloze',
2146                         'questiontext' => '{1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct  answer#Feedback for correct answer~%50%Answer that gives half the  credit#Feedback for half credit answer}',
2147                         'questiontextformat' => '0',
2148                         'generalfeedback' => '',
2149                         'generalfeedbackformat' => '1',
2150                         'defaultgrade' => '1.0000000',
2151                         'penalty' => '0.0000000',
2152                         'qtype' => 'shortanswer',
2153                         'length' => '1',
2154                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164440+EN6wCk',
2155                         'version' => 'tjh238.vledev2.open.ac.uk+110525164440+bQzatI',
2156                         'hidden' => '0',
2157                         'timecreated' => '1306341880',
2158                         'timemodified' => '1306341880',
2159                         'createdby' => '2',
2160                         'modifiedby' => '2',
2161                         'options' => (object) array(
2162                             'answers' => array(
2163                                 33 => (object) array(
2164                                     'id' => '33',
2165                                     'question' => '21',
2166                                     'answer' => 'Wrong answer',
2167                                     'answerformat' => '0',
2168                                     'fraction' => '0.0000000',
2169                                     'feedback' => 'Feedback for this wrong answer',
2170                                     'feedbackformat' => '1',
2171                                 ),
2172                                 34 => (object) array(
2173                                     'id' => '34',
2174                                     'question' => '21',
2175                                     'answer' => 'Correct  answer',
2176                                     'answerformat' => '0',
2177                                     'fraction' => '1.0000000',
2178                                     'feedback' => 'Feedback for correct answer',
2179                                     'feedbackformat' => '1',
2180                                 ),
2181                                 35 => (object) array(
2182                                     'id' => '35',
2183                                     'question' => '21',
2184                                     'answer' => 'Answer that gives half the  credit',
2185                                     'answerformat' => '0',
2186                                     'fraction' => '0.5000000',
2187                                     'feedback' => 'Feedback for half credit answer',
2188                                     'feedbackformat' => '1',
2189                                 ),
2190                             ),
2191                             'usecase' => '0',
2192                         ),
2193                         'maxgrade' => '1.0000000',
2194                     ),
2195                     3 => (object) array(
2196                         'id' => '22',
2197                         'category' => '2',
2198                         'parent' => '19',
2199                         'name' => 'Cloze',
2200                         'questiontext' => '{2:NUMERICAL:=23.8:0.1#Feedback for correct answer  23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of  the correct answer}',
2201                         'questiontextformat' => '0',
2202                         'generalfeedback' => '',
2203                         'generalfeedbackformat' => '1',
2204                         'defaultgrade' => '2.0000000',
2205                         'penalty' => '0.0000000',
2206                         'qtype' => 'numerical',
2207                         'length' => '1',
2208                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164440+Xr29c2',
2209                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+QTwsGM',
2210                         'hidden' => '0',
2211                         'timecreated' => '1306341880',
2212                         'timemodified' => '1306341880',
2213                         'createdby' => '2',
2214                         'modifiedby' => '2',
2215                         'options' => (object) array(
2216                             'answers' => array(
2217                                 36 => (object) array(
2218                                     'id' => '36',
2219                                     'question' => '22',
2220                                     'answer' => '23.8',
2221                                     'answerformat' => '0',
2222                                     'fraction' => '1.0000000',
2223                                     'feedback' => 'Feedback for correct answer  23.8',
2224                                     'feedbackformat' => '1',
2225                                     'tolerance' => '0.1',
2226                                 ),
2227                                 37 => (object) array(
2228                                     'id' => '37',
2229                                     'question' => '22',
2230                                     'answer' => '23.8',
2231                                     'answerformat' => '0',
2232                                     'fraction' => '0.5000000',
2233                                     'feedback' => 'Feedback for half credit answer in the nearby region of  the correct answer',
2234                                     'feedbackformat' => '1',
2235                                     'tolerance' => '2',
2236                                 ),
2237                             ),
2238                             'units' => array(
2239                             ),
2240                             'unitgradingtype' => '0',
2241                             'unitpenalty' => '1.0000000',
2242                             'showunits' => '3',
2243                             'unitsleft' => '0',
2244                             'instructions' => '',
2245                             'instructionsformat' => '1',
2246                         ),
2247                         'maxgrade' => '2.0000000',
2248                     ),
2249                     4 => (object) array(
2250                         'id' => '23',
2251                         'category' => '2',
2252                         'parent' => '19',
2253                         'name' => 'Cloze',
2254                         'questiontext' => '{2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong  answer#Feedback for the other wrong answer~=3. Correct answer#Feedback  for correct answer~%50%4. Answer that gives half the credit#Feedback for  half credit answer}',
2255                         'questiontextformat' => '0',
2256                         'generalfeedback' => '',
2257                         'generalfeedbackformat' => '1',
2258                         'defaultgrade' => '2.0000000',
2259                         'penalty' => '0.0000000',
2260                         'qtype' => 'multichoice',
2261                         'length' => '1',
2262                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+7R55HA',
2263                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+uCMoQc',
2264                         'hidden' => '0',
2265                         'timecreated' => '1306341881',
2266                         'timemodified' => '1306341881',
2267                         'createdby' => '2',
2268                         'modifiedby' => '2',
2269                         'options' => (object) array(
2270                             'id' => '4',
2271                             'question' => '23',
2272                             'layout' => '1',
2273                             'answers' => array(
2274                                 38 => (object) array(
2275                                     'id' => '38',
2276                                     'question' => '23',
2277                                     'answer' => '1. Wrong answer',
2278                                     'answerformat' => '1',
2279                                     'fraction' => '0.0000000',
2280                                     'feedback' => 'Feedback for this wrong answer',
2281                                     'feedbackformat' => '1',
2282                                 ),
2283                                 39 => (object) array(
2284                                     'id' => '39',
2285                                     'question' => '23',
2286                                     'answer' => '2. Another wrong  answer',
2287                                     'answerformat' => '1',
2288                                     'fraction' => '0.0000000',
2289                                     'feedback' => 'Feedback for the other wrong answer',
2290                                     'feedbackformat' => '1',
2291                                 ),
2292                                 40 => (object) array(
2293                                     'id' => '40',
2294                                     'question' => '23',
2295                                     'answer' => '3. Correct answer',
2296                                     'answerformat' => '1',
2297                                     'fraction' => '1.0000000',
2298                                     'feedback' => 'Feedback  for correct answer',
2299                                     'feedbackformat' => '1',
2300                                 ),
2301                                 41 => (object) array(
2302                                     'id' => '41',
2303                                     'question' => '23',
2304                                     'answer' => '4. Answer that gives half the credit',
2305                                     'answerformat' => '1',
2306                                     'fraction' => '0.5000000',
2307                                     'feedback' => 'Feedback for  half credit answer',
2308                                     'feedbackformat' => '1',
2309                                 ),
2310                             ),
2311                             'single' => '1',
2312                             'shuffleanswers' => '1',
2313                             'correctfeedback' => '',
2314                             'correctfeedbackformat' => '1',
2315                             'partiallycorrectfeedback' => '',
2316                             'partiallycorrectfeedbackformat' => '1',
2317                             'incorrectfeedback' => '',
2318                             'incorrectfeedbackformat' => '1',
2319                             'answernumbering' => '0',
2320                         ),
2321                         'maxgrade' => '2.0000000',
2322                     ),
2323                     5 => (object) array(
2324                         'id' => '24',
2325                         'category' => '2',
2326                         'parent' => '19',
2327                         'name' => 'Cloze',
2328                         'questiontext' => '{2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong  answer#Feedback for the other wrong answer~=c. Correct answer#Feedback  for correct answer~%50%d. Answer that gives half the credit#Feedback for  half credit answer}',
2329                         'questiontextformat' => '0',
2330                         'generalfeedback' => '',
2331                         'generalfeedbackformat' => '1',
2332                         'defaultgrade' => '2.0000000',
2333                         'penalty' => '0.0000000',
2334                         'qtype' => 'multichoice',
2335                         'length' => '1',
2336                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+QGvRpd',
2337                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+03GsSs',
2338                         'hidden' => '0',
2339                         'timecreated' => '1306341881',
2340                         'timemodified' => '1306341881',
2341                         'createdby' => '2',
2342                         'modifiedby' => '2',
2343                         'options' => (object) array(
2344                             'id' => '5',
2345                             'question' => '24',
2346                             'layout' => '2',
2347                             'answers' => array(
2348                                 42 => (object) array(
2349                                     'id' => '42',
2350                                     'question' => '24',
2351                                     'answer' => 'a. Wrong answer',
2352                                     'answerformat' => '1',
2353                                     'fraction' => '0.0000000',
2354                                     'feedback' => 'Feedback for this wrong answer',
2355                                     'feedbackformat' => '1',
2356                                 ),
2357                                 43 => (object) array(
2358                                     'id' => '43',
2359                                     'question' => '24',
2360                                     'answer' => 'b. Another wrong  answer',
2361                                     'answerformat' => '1',
2362                                     'fraction' => '0.0000000',
2363                                     'feedback' => 'Feedback for the other wrong answer',
2364                                     'feedbackformat' => '1',
2365                                 ),
2366                                 44 => (object) array(
2367                                     'id' => '44',
2368                                     'question' => '24',
2369                                     'answer' => 'c. Correct answer',
2370                                     'answerformat' => '1',
2371                                     'fraction' => '1.0000000',
2372                                     'feedback' => 'Feedback  for correct answer',
2373                                     'feedbackformat' => '1',
2374                                 ),
2375                                 45 => (object) array(
2376                                     'id' => '45',
2377                                     'question' => '24',
2378                                     'answer' => 'd. Answer that gives half the credit',
2379                                     'answerformat' => '1',
2380                                     'fraction' => '0.5000000',
2381                                     'feedback' => 'Feedback for  half credit answer',
2382                                     'feedbackformat' => '1',
2383                                 ),
2384                             ),
2385                             'single' => '1',
2386                             'shuffleanswers' => '1',
2387                             'correctfeedback' => '',
2388                             'correctfeedbackformat' => '1',
2389                             'partiallycorrectfeedback' => '',
2390                             'partiallycorrectfeedbackformat' => '1',
2391                             'incorrectfeedback' => '',
2392                             'incorrectfeedbackformat' => '1',
2393                             'answernumbering' => '0',
2394                         ),
2395                         'maxgrade' => '2.0000000',
2396                     ),
2397                     6 => (object) array(
2398                         'id' => '25',
2399                         'category' => '2',
2400                         'parent' => '19',
2401                         'name' => 'Cloze',
2402                         'questiontext' => '{1:SHORTANSWER_C:moodle#Feedback for moodle in lower  case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for  only first letter in upper case}',
2403                         'questiontextformat' => '0',
2404                         'generalfeedback' => '',
2405                         'generalfeedbackformat' => '1',
2406                         'defaultgrade' => '1.0000000',
2407                         'penalty' => '0.0000000',
2408                         'qtype' => 'shortanswer',
2409                         'length' => '1',
2410                         'stamp' => 'tjh238.vledev2.open.ac.uk+110525164441+n9ETJC',
2411                         'version' => 'tjh238.vledev2.open.ac.uk+110525164441+Bvqo6c',
2412                         'hidden' => '0',
2413                         'timecreated' => '1306341881',
2414                         'timemodified' => '1306341881',
2415                         'createdby' => '2',
2416                         'modifiedby' => '2',
2417                         'options' => (object) array(
2418 &nbs