2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Unit tests for the Moodle Blackboard format.
20 * @package qformat_blackboard
21 * @copyright 2012 Jean-Michel Vedrine
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 require_once($CFG->libdir . '/questionlib.php');
30 require_once($CFG->dirroot . '/question/format.php');
31 require_once($CFG->dirroot . '/question/format/blackboard/format.php');
32 require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
36 * Unit tests for the blackboard question import format.
38 * @copyright 2012 Jean-Michel Vedrine
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class qformat_blackboard_test extends question_testcase {
43 public function make_test_xml() {
44 $xml = "<?xml version='1.0' encoding='utf-8'?>
46 <TITLE value='exam 3 2008-9'/>
48 <QUESTION id='q1' class='QUESTION_TRUEFALSE' points='1'/>
49 <QUESTION id='q7' class='QUESTION_MULTIPLECHOICE' points='1'/>
50 <QUESTION id='q8' class='QUESTION_MULTIPLEANSWER' points='1'/>
51 <QUESTION id='q39-44' class='QUESTION_MATCH' points='2'/>
52 <QUESTION id='q9' class='QUESTION_ESSAY' points='1'/>
53 <QUESTION id='q27' class='QUESTION_FILLINBLANK' points='1'/>
55 <QUESTION_TRUEFALSE id='q1'>
57 <TEXT><![CDATA[<span style=\"font-size:12pt\">42 is the Absolute Answer to everything.</span>]]></TEXT>
59 <ISHTML value='true'/>
60 <ISNEWLINELITERAL value='false'/>
70 <CORRECTANSWER answer_id='q1_a2'/>
71 <FEEDBACK_WHEN_CORRECT><![CDATA[You gave the right answer.]]></FEEDBACK_WHEN_CORRECT>
72 <FEEDBACK_WHEN_INCORRECT><![CDATA[42 is the Ultimate Answer.]]></FEEDBACK_WHEN_INCORRECT>
75 <QUESTION_MULTIPLECHOICE id='q7'>
77 <TEXT><![CDATA[<span style=\"font-size:12pt\">What's between orange and green in the spectrum?</span>]]></TEXT>
79 <ISHTML value='true'/>
80 <ISNEWLINELITERAL value='false'/>
83 <ANSWER id='q7_a1' position='1'>
84 <TEXT><![CDATA[<span style=\"font-size:12pt\">red</span>]]></TEXT>
86 <ANSWER id='q7_a2' position='2'>
87 <TEXT><![CDATA[<span style=\"font-size:12pt\">yellow</span>]]></TEXT>
89 <ANSWER id='q7_a3' position='3'>
90 <TEXT><![CDATA[<span style=\"font-size:12pt\">blue</span>]]></TEXT>
93 <CORRECTANSWER answer_id='q7_a2'/>
94 <FEEDBACK_WHEN_CORRECT><![CDATA[You gave the right answer.]]></FEEDBACK_WHEN_CORRECT>
95 <FEEDBACK_WHEN_INCORRECT><![CDATA[Only yellow is between orange and green in the spectrum.]]></FEEDBACK_WHEN_INCORRECT>
97 </QUESTION_MULTIPLECHOICE>
98 <QUESTION_MULTIPLEANSWER id='q8'>
100 <TEXT><![CDATA[<span style=\"font-size:12pt\">What's between orange and green in the spectrum?</span>]]></TEXT>
102 <ISHTML value='true'/>
103 <ISNEWLINELITERAL value='false'/>
106 <ANSWER id='q8_a1' position='1'>
107 <TEXT><![CDATA[<span style=\"font-size:12pt\">yellow</span>]]></TEXT>
109 <ANSWER id='q8_a2' position='2'>
110 <TEXT><![CDATA[<span style=\"font-size:12pt\">red</span>]]></TEXT>
112 <ANSWER id='q8_a3' position='3'>
113 <TEXT><![CDATA[<span style=\"font-size:12pt\">off-beige</span>]]></TEXT>
115 <ANSWER id='q8_a4' position='4'>
116 <TEXT><![CDATA[<span style=\"font-size:12pt\">blue</span>]]></TEXT>
119 <CORRECTANSWER answer_id='q8_a1'/>
120 <CORRECTANSWER answer_id='q8_a3'/>
121 <FEEDBACK_WHEN_CORRECT><![CDATA[You gave the right answer.]]></FEEDBACK_WHEN_CORRECT>
122 <FEEDBACK_WHEN_INCORRECT>
123 <![CDATA[Only yellow and off-beige are between orange and green in the spectrum.]]>
124 </FEEDBACK_WHEN_INCORRECT>
126 </QUESTION_MULTIPLEANSWER>
127 <QUESTION_MATCH id='q39-44'>
129 <TEXT><![CDATA[<i>Classify the animals.</i>]]></TEXT>
131 <ISHTML value='true'/>
132 <ISNEWLINELITERAL value='false'/>
135 <ANSWER id='q39-44_a1' position='1'>
136 <TEXT><![CDATA[frog]]></TEXT>
138 <ANSWER id='q39-44_a2' position='2'>
139 <TEXT><![CDATA[cat]]></TEXT>
141 <ANSWER id='q39-44_a3' position='3'>
142 <TEXT><![CDATA[newt]]></TEXT>
144 <CHOICE id='q39-44_c1' position='1'>
145 <TEXT><![CDATA[mammal]]></TEXT>
147 <CHOICE id='q39-44_c2' position='2'>
148 <TEXT><![CDATA[insect]]></TEXT>
150 <CHOICE id='q39-44_c3' position='3'>
151 <TEXT><![CDATA[amphibian]]></TEXT>
154 <CORRECTANSWER answer_id='q39-44_a1' choice_id='q39-44_c3'/>
155 <CORRECTANSWER answer_id='q39-44_a2' choice_id='q39-44_c1'/>
156 <CORRECTANSWER answer_id='q39-44_a3' choice_id='q39-44_c3'/>
159 <QUESTION_ESSAY id='q9'>
161 <TEXT><![CDATA[How are you?]]></TEXT>
163 <ISHTML value='true'/>
164 <ISNEWLINELITERAL value='false'/>
168 <TEXT><![CDATA[Blackboard answer for essay questions will be imported as informations for graders.]]></TEXT>
173 <QUESTION_FILLINBLANK id='q27'>
175 <TEXT><![CDATA[<span style=\"font-size:12pt\">Name an amphibian: __________.</span>]]></TEXT>
177 <ISHTML value='true'/>
178 <ISNEWLINELITERAL value='false'/>
181 <ANSWER id='q27_a1' position='1'>
186 </QUESTION_FILLINBLANK></POOL>";
189 public function test_import_match() {
191 $xmldata = xmlize($this->make_test_xml());
192 $questions = array();
194 $importer = new qformat_blackboard();
195 $importer->process_matching($xmldata, $questions);
197 $expectedq = new stdClass();
198 $expectedq->qtype = 'match';
199 $expectedq->name = 'Classify the animals.';
200 $expectedq->questiontext = '<i>Classify the animals.</i>';
201 $expectedq->questiontextformat = FORMAT_HTML;
202 $expectedq->correctfeedback = array('text' => '',
203 'format' => FORMAT_HTML, 'files' => array());
204 $expectedq->partiallycorrectfeedback = array('text' => '',
205 'format' => FORMAT_HTML, 'files' => array());
206 $expectedq->incorrectfeedback = array('text' => '',
207 'format' => FORMAT_HTML, 'files' => array());
208 $expectedq->generalfeedback = '';
209 $expectedq->generalfeedbackformat = FORMAT_HTML;
210 $expectedq->defaultmark = 1;
211 $expectedq->length = 1;
212 $expectedq->penalty = 0.3333333;
213 $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
214 $expectedq->subquestions = array(
215 array('text' => 'cat', 'format' => FORMAT_HTML, 'files' => array()),
216 array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
217 array('text' => 'frog', 'format' => FORMAT_HTML, 'files' => array()),
218 array('text' => 'newt', 'format' => FORMAT_HTML, 'files' => array()));
219 $expectedq->subanswers = array('mammal', 'insect', 'amphibian', 'amphibian');
221 $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
224 public function test_import_multichoice_single() {
226 $xmldata = xmlize($this->make_test_xml());
227 $questions = array();
229 $importer = new qformat_blackboard();
230 $importer->process_mc($xmldata, $questions);
233 $expectedq = new stdClass();
234 $expectedq->qtype = 'multichoice';
235 $expectedq->single = 1;
236 $expectedq->name = 'What\'s between orange and green in the spectrum?';
237 $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
238 $expectedq->questiontextformat = FORMAT_HTML;
239 $expectedq->correctfeedback = array('text' => 'You gave the right answer.',
240 'format' => FORMAT_HTML, 'files' => array());
241 $expectedq->partiallycorrectfeedback = array('text' => '',
242 'format' => FORMAT_HTML, 'files' => array());
243 $expectedq->incorrectfeedback = array('text' => 'Only yellow is between orange and green in the spectrum.',
244 'format' => FORMAT_HTML, 'files' => array());
245 $expectedq->generalfeedback = '';
246 $expectedq->generalfeedbackformat = FORMAT_HTML;
247 $expectedq->defaultmark = 1;
248 $expectedq->length = 1;
249 $expectedq->penalty = 0.3333333;
250 $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
251 $expectedq->answer = array(
253 'text' => '<span style="font-size:12pt">red</span>',
254 'format' => FORMAT_HTML,
258 'text' => '<span style="font-size:12pt">yellow</span>',
259 'format' => FORMAT_HTML,
263 'text' => '<span style="font-size:12pt">blue</span>',
264 'format' => FORMAT_HTML,
268 $expectedq->fraction = array(0, 1, 0);
269 $expectedq->feedback = array(
272 'format' => FORMAT_HTML,
277 'format' => FORMAT_HTML,
282 'format' => FORMAT_HTML,
287 $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
290 public function test_import_multichoice_multi() {
292 $xmldata = xmlize($this->make_test_xml());
293 $questions = array();
295 $importer = new qformat_blackboard();
296 $importer->process_ma($xmldata, $questions);
299 $expectedq = new stdClass();
300 $expectedq->qtype = 'multichoice';
301 $expectedq->single = 0;
302 $expectedq->name = 'What\'s between orange and green in the spectrum?';
303 $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
304 $expectedq->questiontextformat = FORMAT_HTML;
305 $expectedq->correctfeedback = array(
306 'text' => 'You gave the right answer.',
307 'format' => FORMAT_HTML,
309 $expectedq->partiallycorrectfeedback = array(
310 'text' => 'Only yellow and off-beige are between orange and green in the spectrum.',
311 'format' => FORMAT_HTML,
313 $expectedq->incorrectfeedback = array(
314 'text' => 'Only yellow and off-beige are between orange and green in the spectrum.',
315 'format' => FORMAT_HTML,
317 $expectedq->generalfeedback = '';
318 $expectedq->generalfeedbackformat = FORMAT_HTML;
319 $expectedq->defaultmark = 1;
320 $expectedq->length = 1;
321 $expectedq->penalty = 0.3333333;
322 $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
323 $expectedq->answer = array(
325 'text' => '<span style="font-size:12pt">yellow</span>',
326 'format' => FORMAT_HTML,
330 'text' => '<span style="font-size:12pt">red</span>',
331 'format' => FORMAT_HTML,
335 'text' => '<span style="font-size:12pt">off-beige</span>',
336 'format' => FORMAT_HTML,
340 'text' => '<span style="font-size:12pt">blue</span>',
341 'format' => FORMAT_HTML,
345 $expectedq->fraction = array(0.5, 0, 0.5, 0);
346 $expectedq->feedback = array(
349 'format' => FORMAT_HTML,
354 'format' => FORMAT_HTML,
359 'format' => FORMAT_HTML,
364 'format' => FORMAT_HTML,
369 $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
372 public function test_import_truefalse() {
374 $xmldata = xmlize($this->make_test_xml());
375 $questions = array();
377 $importer = new qformat_blackboard();
378 $importer->process_tf($xmldata, $questions);
381 $expectedq = new stdClass();
382 $expectedq->qtype = 'truefalse';
383 $expectedq->name = '42 is the Absolute Answer to everything.';
384 $expectedq->questiontext = '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>';
385 $expectedq->questiontextformat = FORMAT_HTML;
386 $expectedq->generalfeedback = '';
387 $expectedq->generalfeedbackformat = FORMAT_HTML;
388 $expectedq->defaultmark = 1;
389 $expectedq->length = 1;
390 $expectedq->correctanswer = 0;
391 $expectedq->feedbacktrue = array(
392 'text' => '42 is the Ultimate Answer.',
393 'format' => FORMAT_HTML,
396 $expectedq->feedbackfalse = array(
397 'text' => 'You gave the right answer.',
398 'format' => FORMAT_HTML,
401 $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
404 public function test_import_fill_in_the_blank() {
406 $xmldata = xmlize($this->make_test_xml());
407 $questions = array();
409 $importer = new qformat_blackboard();
410 $importer->process_fib($xmldata, $questions);
413 $expectedq = new stdClass();
414 $expectedq->qtype = 'shortanswer';
415 $expectedq->name = 'Name an amphibian: __________.';
416 $expectedq->questiontext = '<span style="font-size:12pt">Name an amphibian: __________.</span>';
417 $expectedq->questiontextformat = FORMAT_HTML;
418 $expectedq->generalfeedback = '';
419 $expectedq->generalfeedbackformat = FORMAT_HTML;
420 $expectedq->defaultmark = 1;
421 $expectedq->length = 1;
422 $expectedq->usecase = 0;
423 $expectedq->answer = array('frog', '*');
424 $expectedq->fraction = array(1, 0);
425 $expectedq->feedback = array(
428 'format' => FORMAT_HTML,
433 'format' => FORMAT_HTML,
438 $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
441 public function test_import_essay() {
443 $xmldata = xmlize($this->make_test_xml());
444 $questions = array();
446 $importer = new qformat_blackboard();
447 $importer->process_essay($xmldata, $questions);
450 $expectedq = new stdClass();
451 $expectedq->qtype = 'essay';
452 $expectedq->name = 'How are you?';
453 $expectedq->questiontext = 'How are you?';
454 $expectedq->questiontextformat = FORMAT_HTML;
455 $expectedq->generalfeedback = '';
456 $expectedq->generalfeedbackformat = FORMAT_HTML;
457 $expectedq->defaultmark = 1;
458 $expectedq->length = 1;
459 $expectedq->responseformat = 'editor';
460 $expectedq->responsefieldlines = 15;
461 $expectedq->attachments = 0;
462 $expectedq->graderinfo = array(
463 'text' => 'Blackboard answer for essay questions will be imported as informations for graders.',
464 'format' => FORMAT_HTML,
467 $this->assert(new question_check_specified_fields_expectation($expectedq), $q);