qformat_gift MDL-26059 fails to import truefalse questions with answer true.
[moodle.git] / question / format / gift / simpletest / testgiftformat.php
CommitLineData
5b744492
TH
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18
19/**
20 * Unit tests for the Moodle GIFT format.
21 *
22 * @package qformat_xml
23 * @copyright 2010 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27require_once($CFG->libdir . '/questionlib.php');
28require_once($CFG->dirroot . '/question/format.php');
29require_once($CFG->dirroot . '/question/format/gift/format.php');
30
31
32/**
33 * Unit tests for the GIFT import/export format.
34 *
35 * @copyright 2010 The Open University
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class qformat_gift_test extends UnitTestCase {
39 public function assert_same_gift($expectedtext, $text) {
40 $this->assertEqual(str_replace("\r\n", "\n", $expectedtext),
41 str_replace("\r\n", "\n", $text));
42 }
43
44 public function test_import_essay() {
45 $gift = '
46// essay
47::Q8:: How are you? {}';
48 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
49
50 $importer = new qformat_gift();
51 $q = $importer->readquestion($lines);
52
53 $expectedq = (object) array(
54 'name' => 'Q8',
55 'questiontext' => 'How are you?',
56 'questiontextformat' => FORMAT_MOODLE,
57 'generalfeedback' => '',
58 'generalfeedbackformat' => FORMAT_MOODLE,
59 'qtype' => 'essay',
60 'defaultgrade' => 1,
61 'penalty' => 0.1,
62 'length' => 1,
63 'feedback' => array(
64 'text' => '',
65 'format' => FORMAT_MOODLE,
66 'files' => array(),
67 ),
68 );
69
70 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
71 }
72
73 public function test_export_essay() {
74 $qdata = (object) array(
75 'id' => 666 ,
76 'name' => 'Q8',
77 'questiontext' => 'How are you?',
78 'questiontextformat' => FORMAT_MOODLE,
79 'generalfeedback' => '',
80 'generalfeedbackformat' => FORMAT_MOODLE,
81 'defaultgrade' => 1,
82 'penalty' => 0.1,
83 'length' => 1,
84 'qtype' => 'essay',
85 'options' => (object) array(
86 'answers' => array(
87 123 => (object) array(
88 'id' => 123,
89 'answer' => 666,
90 'answerformat' => FORMAT_MOODLE,
91 'fraction' => 0,
92 'feedback' => '',
93 'feedbackformat' => FORMAT_MOODLE,
94 ),
95 ),
96 ),
97 );
98
99 $exporter = new qformat_gift();
100 $gift = $exporter->writequestion($qdata);
101
102 $expectedgift = "// question: 666 name: Q8
103::Q8::How are you?{}
104
105";
106
107 $this->assert_same_gift($expectedgift, $gift);
108 }
109
110 public function test_import_match() {
111 $gift = '
112// question: 2 name: Moodle activities
113::Moodle activities::[html]Match the <b>activity</b> to the description.{
114 =[html]An activity supporting asynchronous discussions. -> Forum
115 =[moodle]A teacher asks a question and specifies a choice of multiple responses. -> Choice
116 =[plain]A bank of record entries which participants can add to. -> Database
117 =[markdown]A collection of web pages that anyone can add to or edit. -> Wiki
118 = -> Chat
119}';
120 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
121
122 $importer = new qformat_gift();
123 $q = $importer->readquestion($lines);
124
125 $expectedq = (object) array(
126 'name' => 'Moodle activities',
127 'questiontext' => 'Match the <b>activity</b> to the description.',
128 'questiontextformat' => FORMAT_HTML,
129 'generalfeedback' => '',
130 'generalfeedbackformat' => FORMAT_HTML,
131 'qtype' => 'match',
132 'defaultgrade' => 1,
133 'penalty' => 0.1,
134 'length' => 1,
135 'shuffleanswers' => '1',
136 'subquestions' => array(
137 0 => array(
138 'text' => 'An activity supporting asynchronous discussions.',
139 'format' => FORMAT_HTML,
140 'files' => array(),
141 ),
142 1 => array(
143 'text' => 'A teacher asks a question and specifies a choice of multiple responses.',
144 'format' => FORMAT_MOODLE,
145 'files' => array(),
146 ),
147 2 => array(
148 'text' => 'A bank of record entries which participants can add to.',
149 'format' => FORMAT_PLAIN,
150 'files' => array(),
151 ),
152 3 => array(
153 'text' => 'A collection of web pages that anyone can add to or edit.',
154 'format' => FORMAT_MARKDOWN,
155 'files' => array(),
156 ),
157 4 => array(
158 'text' => '',
159 'format' => FORMAT_HTML,
160 'files' => array(),
161 ),
162 ),
163 'subanswers' => array(
164 0 => 'Forum',
165 1 => 'Choice',
166 2 => 'Database',
167 3 => 'Wiki',
168 4 => 'Chat',
169 ),
170 );
171
172 // Repeated test for better failure messages.
173 $this->assertEqual($expectedq->subquestions, $q->subquestions);
174 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
175 }
176
177 public function test_export_match() {
178 $qdata = (object) array(
179 'id' => 666 ,
180 'name' => 'Moodle activities',
181 'questiontext' => 'Match the <b>activity</b> to the description.',
182 'questiontextformat' => FORMAT_HTML,
183 'generalfeedback' => '',
184 'generalfeedbackformat' => FORMAT_HTML,
185 'defaultgrade' => 1,
186 'penalty' => 0.1,
187 'length' => 1,
188 'qtype' => 'match',
189 'options' => (object) array(
190 'id' => 123,
191 'question' => 666,
192 'shuffleanswers' => 1,
193 'subquestions' => array(
194 42 => (object) array(
195 'id' => 1234,
196 'code' => 12341234,
197 'question' => 666,
198 'questiontext' => 'An activity supporting asynchronous discussions.',
199 'questiontextformat' => FORMAT_HTML,
200 'answertext' => 'Forum',
201 ),
202 43 => (object) array(
203 'id' => 1234,
204 'code' => 12341234,
205 'question' => 666,
206 'questiontext' => 'A teacher asks a question and specifies a choice of multiple responses.',
207 'questiontextformat' => FORMAT_MOODLE,
208 'answertext' => 'Choice',
209 ),
210 44 => (object) array(
211 'id' => 1234,
212 'code' => 12341234,
213 'question' => 666,
214 'questiontext' => 'A bank of record entries which participants can add to.',
215 'questiontextformat' => FORMAT_PLAIN,
216 'answertext' => 'Database',
217 ),
218 45 => (object) array(
219 'id' => 1234,
220 'code' => 12341234,
221 'question' => 666,
222 'questiontext' => 'A collection of web pages that anyone can add to or edit.',
223 'questiontextformat' => FORMAT_MARKDOWN,
224 'answertext' => 'Wiki',
225 ),
226 46 => (object) array(
227 'id' => 1234,
228 'code' => 12341234,
229 'question' => 666,
230 'questiontext' => '',
231 'questiontextformat' => FORMAT_MARKDOWN,
232 'answertext' => 'Chat',
233 ),
234 ),
235 ),
236 );
237
238 $exporter = new qformat_gift();
239 $gift = $exporter->writequestion($qdata);
240
241 $expectedgift = "// question: 666 name: Moodle activities
242::Moodle activities::[html]Match the <b>activity</b> to the description.{
243\t=An activity supporting asynchronous discussions. -> Forum
244\t=[moodle]A teacher asks a question and specifies a choice of multiple responses. -> Choice
245\t=[plain]A bank of record entries which participants can add to. -> Database
246\t=[markdown]A collection of web pages that anyone can add to or edit. -> Wiki
247\t= -> Chat
248}
249
250";
251
252 $this->assert_same_gift($expectedgift, $gift);
253 }
254
255 public function test_import_multichoice() {
256 $gift = "
257// multiple choice with specified feedback for right and wrong answers
258::Q2:: What's between orange and green in the spectrum?
259{
260 =yellow # right; good!
261 ~red # [html]wrong, it's yellow
262 ~[plain]blue # wrong, it's yellow
263}";
264 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
265
266 $importer = new qformat_gift();
267 $q = $importer->readquestion($lines);
268
269 $expectedq = (object) array(
270 'name' => 'Q2',
271 'questiontext' => "What's between orange and green in the spectrum?",
272 'questiontextformat' => FORMAT_MOODLE,
273 'generalfeedback' => '',
274 'generalfeedbackformat' => FORMAT_MOODLE,
275 'qtype' => 'multichoice',
276 'defaultgrade' => 1,
277 'penalty' => 0.1,
278 'length' => 1,
279 'single' => 1,
280 'shuffleanswers' => '1',
281 'answernumbering' => 'abc',
282 'correctfeedback' => array(
283 'text' => '',
284 'format' => FORMAT_MOODLE,
285 'files' => array(),
286 ),
287 'partiallycorrectfeedback' => array(
288 'text' => '',
289 'format' => FORMAT_MOODLE,
290 'files' => array(),
291 ),
292 'incorrectfeedback' => array(
293 'text' => '',
294 'format' => FORMAT_MOODLE,
295 'files' => array(),
296 ),
297 'answer' => array(
298 0 => array(
299 'text' => 'yellow',
300 'format' => FORMAT_MOODLE,
301 'files' => array(),
302 ),
303 1 => array(
304 'text' => 'red',
305 'format' => FORMAT_MOODLE,
306 'files' => array(),
307 ),
308 2 => array(
309 'text' => 'blue',
310 'format' => FORMAT_PLAIN,
311 'files' => array(),
312 ),
313 ),
314 'fraction' => array(1, 0, 0),
315 'feedback' => array(
316 0 => array(
317 'text' => 'right; good!',
318 'format' => FORMAT_MOODLE,
319 'files' => array(),
320 ),
321 1 => array(
322 'text' => "wrong, it's yellow",
323 'format' => FORMAT_HTML,
324 'files' => array(),
325 ),
326 2 => array(
327 'text' => "wrong, it's yellow",
328 'format' => FORMAT_MOODLE,
329 'files' => array(),
330 ),
331 ),
332 );
333
334 // Repeated test for better failure messages.
335 $this->assertEqual($expectedq->answer, $q->answer);
336 $this->assertEqual($expectedq->feedback, $q->feedback);
337 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
338 }
339
340 public function test_export_multichoice() {
341 $qdata = (object) array(
342 'id' => 666 ,
343 'name' => 'Q8',
344 'questiontext' => "What's between orange and green in the spectrum?",
345 'questiontextformat' => FORMAT_MOODLE,
346 'generalfeedback' => '',
347 'generalfeedbackformat' => FORMAT_MOODLE,
348 'defaultgrade' => 1,
349 'penalty' => 0.1,
350 'length' => 1,
351 'qtype' => 'multichoice',
352 'options' => (object) array(
353 'single' => 1,
354 'shuffleanswers' => '1',
355 'answernumbering' => 'abc',
356 'correctfeedback' => '',
357 'correctfeedbackformat' => FORMAT_MOODLE,
358 'partiallycorrectfeedback' => '',
359 'partiallycorrectfeedbackformat' => FORMAT_MOODLE,
360 'incorrectfeedback' => '',
361 'incorrectfeedbackformat' => FORMAT_MOODLE,
362 'answers' => array(
363 123 => (object) array(
364 'id' => 123,
365 'answer' => 'yellow',
366 'answerformat' => FORMAT_MOODLE,
367 'fraction' => 1,
368 'feedback' => 'right; good!',
369 'feedbackformat' => FORMAT_MOODLE,
370 ),
371 124 => (object) array(
372 'id' => 124,
373 'answer' => 'red',
374 'answerformat' => FORMAT_MOODLE,
375 'fraction' => 0,
376 'feedback' => "wrong, it's yellow",
377 'feedbackformat' => FORMAT_HTML,
378 ),
379 125 => (object) array(
380 'id' => 125,
381 'answer' => 'blue',
382 'answerformat' => FORMAT_PLAIN,
383 'fraction' => 0,
384 'feedback' => "wrong, it's yellow",
385 'feedbackformat' => FORMAT_MOODLE,
386 ),
387 ),
388 ),
389 );
390
391 $exporter = new qformat_gift();
392 $gift = $exporter->writequestion($qdata);
393
394 $expectedgift = "// question: 666 name: Q8
395::Q8::What's between orange and green in the spectrum?{
396\t=yellow#right; good!
397\t~red#[html]wrong, it's yellow
398\t~[plain]blue#wrong, it's yellow
399}
400
401";
402
403 $this->assert_same_gift($expectedgift, $gift);
404 }
405
406 public function test_import_numerical() {
407 $gift = "
408// math range question
409::Q5:: What is a number from 1 to 5? {#3:2~#Completely wrong}";
410 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
411
412 $importer = new qformat_gift();
413 $q = $importer->readquestion($lines);
414
415 $expectedq = (object) array(
416 'name' => 'Q5',
417 'questiontext' => "What is a number from 1 to 5?",
418 'questiontextformat' => FORMAT_MOODLE,
419 'generalfeedback' => '',
420 'generalfeedbackformat' => FORMAT_MOODLE,
421 'qtype' => 'numerical',
422 'defaultgrade' => 1,
423 'penalty' => 0.1,
424 'length' => 1,
425 'answer' => array(
426 '3',
427 '*',
428 ),
429 'fraction' => array(1, 0),
430 'feedback' => array(
431 0 => array(
432 'text' => '',
433 'format' => FORMAT_MOODLE,
434 'files' => array(),
435 ),
436 1 => array(
437 'text' => "Completely wrong",
438 'format' => FORMAT_MOODLE,
439 'files' => array(),
440 ),
441 ),
442 'tolerance' => array(2, 0),
443 );
444
445 // Repeated test for better failure messages.
446 $this->assertEqual($expectedq->answer, $q->answer);
447 $this->assertEqual($expectedq->fraction, $q->fraction);
448 $this->assertEqual($expectedq->feedback, $q->feedback);
449 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
450 }
451
452 public function test_export_numerical() {
453 $qdata = (object) array(
454 'id' => 666 ,
455 'name' => 'Q5',
456 'questiontext' => "What is a number from 1 to 5?",
457 'questiontextformat' => FORMAT_MOODLE,
458 'generalfeedback' => '',
459 'generalfeedbackformat' => FORMAT_MOODLE,
460 'defaultgrade' => 1,
461 'penalty' => 1,
462 'length' => 1,
463 'qtype' => 'numerical',
464 'options' => (object) array(
465 'id' => 123,
466 'question' => 666,
467 'instructions' => '',
468 'instructionsformat' => FORMAT_MOODLE,
469 'showunits' => 0,
470 'unitsleft' => 0,
471 'showunits' => 2,
472 'unitgradingtype' => 0,
473 'unitpenalty' => 0,
474 'answers' => array(
475 1 => (object) array(
476 'id' => 123,
477 'answer' => '3',
478 'answerformat' => 0,
479 'fraction' => 1,
480 'tolerance' => 2,
481 'feedback' => '',
482 'feedbackformat' => FORMAT_MOODLE,
483 ),
484 2 => (object) array(
485 'id' => 124,
486 'answer' => '*',
487 'answerformat' => 0,
488 'fraction' => 0,
489 'tolerance' => 0,
490 'feedback' => "Completely wrong",
491 'feedbackformat' => FORMAT_MOODLE,
492 ),
493 ),
494 ),
495 );
496
497 $exporter = new qformat_gift();
498 $gift = $exporter->writequestion($qdata);
499
500 $expectedgift = "// question: 666 name: Q5
501::Q5::What is a number from 1 to 5?{#
502\t=%100%3:2#
503\t~#Completely wrong
504}
505
506";
507
508 $this->assert_same_gift($expectedgift, $gift);
509 }
510
511 public function test_import_shortanswer() {
512 $gift = "
513// question: 666 name: Shortanswer
514::Shortanswer::Which is the best animal?{
515 =Frog#Good!
516 =%50%Cat#What is it with Moodlers and cats?
517 =%0%*#Completely wrong
518}";
519 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
520
521 $importer = new qformat_gift();
522 $q = $importer->readquestion($lines);
523
524 $expectedq = (object) array(
525 'name' => 'Shortanswer',
526 'questiontext' => "Which is the best animal?",
527 'questiontextformat' => FORMAT_MOODLE,
528 'generalfeedback' => '',
529 'generalfeedbackformat' => FORMAT_MOODLE,
530 'qtype' => 'shortanswer',
531 'defaultgrade' => 1,
532 'penalty' => 0.1,
533 'length' => 1,
534 'answer' => array(
535 'Frog',
536 'Cat',
537 '*',
538 ),
539 'fraction' => array(1, 0.5, 0),
540 'feedback' => array(
541 0 => array(
542 'text' => 'Good!',
543 'format' => FORMAT_MOODLE,
544 'files' => array(),
545 ),
546 1 => array(
547 'text' => "What is it with Moodlers and cats?",
548 'format' => FORMAT_MOODLE,
549 'files' => array(),
550 ),
551 2 => array(
552 'text' => "Completely wrong",
553 'format' => FORMAT_MOODLE,
554 'files' => array(),
555 ),
556 ),
557 );
558
559 // Repeated test for better failure messages.
560 $this->assertEqual($expectedq->answer, $q->answer);
561 $this->assertEqual($expectedq->fraction, $q->fraction);
562 $this->assertEqual($expectedq->feedback, $q->feedback);
563 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
564 }
565
566 public function test_export_shortanswer() {
567 $qdata = (object) array(
568 'id' => 666 ,
569 'name' => 'Shortanswer',
570 'questiontext' => "Which is the best animal?",
571 'questiontextformat' => FORMAT_MOODLE,
572 'generalfeedback' => '',
573 'generalfeedbackformat' => FORMAT_MOODLE,
574 'defaultgrade' => 1,
575 'penalty' => 1,
576 'length' => 1,
577 'qtype' => 'shortanswer',
578 'options' => (object) array(
579 'id' => 123,
580 'question' => 666,
581 'usecase' => 1,
582 'answers' => array(
583 1 => (object) array(
584 'id' => 1,
585 'answer' => 'Frog',
586 'answerformat' => 0,
587 'fraction' => 1,
588 'feedback' => 'Good!',
589 'feedbackformat' => FORMAT_MOODLE,
590 ),
591 2 => (object) array(
592 'id' => 2,
593 'answer' => 'Cat',
594 'answerformat' => 0,
595 'fraction' => 0.5,
596 'feedback' => "What is it with Moodlers and cats?",
597 'feedbackformat' => FORMAT_MOODLE,
598 ),
599 3 => (object) array(
600 'id' => 3,
601 'answer' => '*',
602 'answerformat' => 0,
603 'fraction' => 0,
604 'feedback' => "Completely wrong",
605 'feedbackformat' => FORMAT_MOODLE,
606 ),
607 ),
608 ),
609 );
610
611 $exporter = new qformat_gift();
612 $gift = $exporter->writequestion($qdata);
613
614 $expectedgift = "// question: 666 name: Shortanswer
615::Shortanswer::Which is the best animal?{
616\t=%100%Frog#Good!
617\t=%50%Cat#What is it with Moodlers and cats?
618\t=%0%*#Completely wrong
619}
620
621";
622
623 $this->assert_same_gift($expectedgift, $gift);
624 }
625
626 public function test_import_truefalse() {
627 $gift = "
628// true/false
629::Q1:: 42 is the Absolute Answer to everything.{
630FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
631 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
632
633 $importer = new qformat_gift();
634 $q = $importer->readquestion($lines);
635
636 $expectedq = (object) array(
637 'name' => 'Q1',
638 'questiontext' => "42 is the Absolute Answer to everything.",
639 'questiontextformat' => FORMAT_MOODLE,
640 'generalfeedback' => '',
641 'generalfeedbackformat' => FORMAT_MOODLE,
642 'qtype' => 'truefalse',
643 'defaultgrade' => 1,
644 'penalty' => 1,
645 'length' => 1,
646 'correctanswer' => 0,
647 'feedbacktrue' => array(
648 'text' => '42 is the Ultimate Answer.',
649 'format' => FORMAT_MOODLE,
650 'files' => array(),
651 ),
652 'feedbackfalse' => array(
653 'text' => 'You gave the right answer.',
654 'format' => FORMAT_MOODLE,
655 'files' => array(),
656 ),
657 );
658
659 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
660 }
661
2c00fa16
TH
662 public function test_import_truefalse_true_answer1() {
663 $gift = "// name 0-11
664::2-08 TSL::TSL is blablabla.{T}";
665 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
666
667 $importer = new qformat_gift();
668 $q = $importer->readquestion($lines);
669
670 $expectedq = (object) array(
671 'name' => '2-08 TSL',
672 'questiontext' => "TSL is blablabla.",
673 'questiontextformat' => FORMAT_MOODLE,
674 'generalfeedback' => '',
675 'generalfeedbackformat' => FORMAT_MOODLE,
676 'qtype' => 'truefalse',
677 'defaultgrade' => 1,
678 'penalty' => 1,
679 'length' => 1,
680 'correctanswer' => 1,
681 'feedbacktrue' => array(
682 'text' => '',
683 'format' => FORMAT_MOODLE,
684 'files' => array(),
685 ),
686 'feedbackfalse' => array(
687 'text' => '',
688 'format' => FORMAT_MOODLE,
689 'files' => array(),
690 ),
691 );
692
693 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
694 }
695
696 public function test_import_truefalse_true_answer2() {
697 $gift = "// name 0-11
698::2-08 TSL::TSL is blablabla.{TRUE}";
699 $lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
700
701 $importer = new qformat_gift();
702 $q = $importer->readquestion($lines);
703
704 $expectedq = (object) array(
705 'name' => '2-08 TSL',
706 'questiontext' => "TSL is blablabla.",
707 'questiontextformat' => FORMAT_MOODLE,
708 'generalfeedback' => '',
709 'generalfeedbackformat' => FORMAT_MOODLE,
710 'qtype' => 'truefalse',
711 'defaultgrade' => 1,
712 'penalty' => 1,
713 'length' => 1,
714 'correctanswer' => 1,
715 'feedbacktrue' => array(
716 'text' => '',
717 'format' => FORMAT_MOODLE,
718 'files' => array(),
719 ),
720 'feedbackfalse' => array(
721 'text' => '',
722 'format' => FORMAT_MOODLE,
723 'files' => array(),
724 ),
725 );
726
727 $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
728 }
729
5b744492
TH
730 public function test_export_truefalse() {
731 $qdata = (object) array(
732 'id' => 666 ,
733 'name' => 'Q1',
734 'questiontext' => "42 is the Absolute Answer to everything.",
735 'questiontextformat' => FORMAT_MOODLE,
736 'generalfeedback' => '',
737 'generalfeedbackformat' => FORMAT_MOODLE,
738 'defaultgrade' => 1,
739 'penalty' => 1,
740 'length' => 1,
741 'qtype' => 'truefalse',
742 'options' => (object) array(
743 'id' => 123,
744 'question' => 666,
745 'trueanswer' => 1,
746 'falseanswer' => 2,
747 'answers' => array(
748 1 => (object) array(
749 'id' => 123,
750 'answer' => 'True',
751 'answerformat' => 0,
752 'fraction' => 1,
753 'feedback' => 'You gave the right answer.',
754 'feedbackformat' => FORMAT_MOODLE,
755 ),
756 2 => (object) array(
757 'id' => 124,
758 'answer' => 'False',
759 'answerformat' => 0,
760 'fraction' => 0,
761 'feedback' => "42 is the Ultimate Answer.",
762 'feedbackformat' => FORMAT_HTML,
763 ),
764 ),
765 ),
766 );
767
768 $exporter = new qformat_gift();
769 $gift = $exporter->writequestion($qdata);
770
771 $expectedgift = "// question: 666 name: Q1
772::Q1::42 is the Absolute Answer to everything.{TRUE#[html]42 is the Ultimate Answer.#You gave the right answer.}
773
774";
775
776 $this->assert_same_gift($expectedgift, $gift);
777 }
778}