See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Unit tests for the Moodle Blackboard V6+ format. 19 * 20 * @package qformat_blackboard_six 21 * @copyright 2012 Jean-Michel Vedrine 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->libdir . '/questionlib.php'); 30 require_once($CFG->dirroot . '/question/format.php'); 31 require_once($CFG->dirroot . '/question/format/blackboard_six/format.php'); 32 require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); 33 34 35 /** 36 * Unit tests for the blackboard question import format. 37 * 38 * @copyright 2012 Jean-Michel Vedrine 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class qformat_blackboard_six_qti_test extends question_testcase { 42 43 public function make_test_xml() { 44 $xmlfile = new qformat_blackboard_six_file(); 45 $xmlfile->filetype = 1; 46 $xmlfile->text = file_get_contents(__DIR__ . '/fixtures/sample_blackboard_qti.dat'); 47 return array(0 => $xmlfile); 48 } 49 public function test_import_match() { 50 $xml = $this->make_test_xml(); 51 52 $importer = new qformat_blackboard_six(); 53 $questions = $importer->readquestions($xml); 54 $q = $questions[4]; 55 56 // If qtype_ddmatch is installed, the formatter produces ddmatch 57 // qtypes, not match ones. 58 $ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch'); 59 60 $expectedq = new stdClass(); 61 $expectedq->qtype = $ddmatchisinstalled ? 'ddmatch' : 'match'; 62 $expectedq->name = 'Classify the animals.'; 63 $expectedq->questiontext = 'Classify the animals.'; 64 $expectedq->questiontextformat = FORMAT_HTML; 65 $expectedq->correctfeedback = array('text' => '', 66 'format' => FORMAT_HTML, 'files' => array()); 67 $expectedq->partiallycorrectfeedback = array('text' => '', 68 'format' => FORMAT_HTML, 'files' => array()); 69 $expectedq->incorrectfeedback = array('text' => '', 70 'format' => FORMAT_HTML, 'files' => array()); 71 $expectedq->generalfeedback = ''; 72 $expectedq->generalfeedbackformat = FORMAT_HTML; 73 $expectedq->defaultmark = 1; 74 $expectedq->length = 1; 75 $expectedq->penalty = 0.3333333; 76 $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers'); 77 $expectedq->subquestions = array( 78 array('text' => '', 'format' => FORMAT_HTML), 79 array('text' => 'cat', 'format' => FORMAT_HTML), 80 array('text' => 'frog', 'format' => FORMAT_HTML), 81 array('text' => 'newt', 'format' => FORMAT_HTML)); 82 if ($ddmatchisinstalled) { 83 $expectedq->subanswers = array( 84 array('text' => 'insect', 'format' => FORMAT_HTML), 85 array('text' => 'mammal', 'format' => FORMAT_HTML), 86 array('text' => 'amphibian', 'format' => FORMAT_HTML), 87 array('text' => 'amphibian', 'format' => FORMAT_HTML), 88 ); 89 } else { 90 $expectedq->subanswers = array('insect', 'mammal', 'amphibian', 'amphibian'); 91 } 92 93 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 94 } 95 96 public function test_import_multichoice_single() { 97 $xml = $this->make_test_xml(); 98 99 $importer = new qformat_blackboard_six(); 100 $questions = $importer->readquestions($xml); 101 $q = $questions[2]; 102 103 $expectedq = new stdClass(); 104 $expectedq->qtype = 'multichoice'; 105 $expectedq->single = 1; 106 $expectedq->name = 'What\'s between orange and green in the spectrum?'; 107 $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>'; 108 $expectedq->questiontextformat = FORMAT_HTML; 109 $expectedq->correctfeedback = array('text' => '', 110 'format' => FORMAT_HTML, 'files' => array()); 111 $expectedq->partiallycorrectfeedback = array('text' => '', 112 'format' => FORMAT_HTML, 'files' => array()); 113 $expectedq->incorrectfeedback = array('text' => '', 114 'format' => FORMAT_HTML, 'files' => array()); 115 $expectedq->generalfeedback = ''; 116 $expectedq->generalfeedbackformat = FORMAT_HTML; 117 $expectedq->defaultmark = 1; 118 $expectedq->length = 1; 119 $expectedq->penalty = 0.3333333; 120 $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers'); 121 $expectedq->answer = array( 122 0 => array( 123 'text' => '<span style="font-size:12pt">red</span>', 124 'format' => FORMAT_HTML, 125 ), 126 1 => array( 127 'text' => '<span style="font-size:12pt">yellow</span>', 128 'format' => FORMAT_HTML, 129 ), 130 2 => array( 131 'text' => '<span style="font-size:12pt">blue</span>', 132 'format' => FORMAT_HTML, 133 ) 134 ); 135 $expectedq->fraction = array(0, 1, 0); 136 $expectedq->feedback = array( 137 0 => array( 138 'text' => 'Red is not between orange and green in the spectrum but yellow is.', 139 'format' => FORMAT_HTML, 140 ), 141 1 => array( 142 'text' => 'You gave the right answer.', 143 'format' => FORMAT_HTML, 144 ), 145 2 => array( 146 'text' => 'Blue is not between orange and green in the spectrum but yellow is.', 147 'format' => FORMAT_HTML, 148 ) 149 ); 150 151 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 152 } 153 154 public function test_import_multichoice_multi() { 155 156 $xml = $this->make_test_xml(); 157 158 $importer = new qformat_blackboard_six(); 159 $questions = $importer->readquestions($xml); 160 $q = $questions[3]; 161 162 $expectedq = new stdClass(); 163 $expectedq->qtype = 'multichoice'; 164 $expectedq->single = 0; 165 $expectedq->name = 'What\'s between orange and green in the spectrum?'; 166 $expectedq->questiontext = '<i>What\'s between orange and green in the spectrum?</i>'; 167 $expectedq->questiontextformat = FORMAT_HTML; 168 $expectedq->correctfeedback = array( 169 'text' => '', 170 'format' => FORMAT_HTML, 171 'files' => array(), 172 ); 173 $expectedq->partiallycorrectfeedback = array( 174 'text' => '', 175 'format' => FORMAT_HTML, 176 'files' => array(), 177 ); 178 $expectedq->incorrectfeedback = array( 179 'text' => '', 180 'format' => FORMAT_HTML, 181 'files' => array(), 182 ); 183 $expectedq->generalfeedback = ''; 184 $expectedq->generalfeedbackformat = FORMAT_HTML; 185 $expectedq->defaultmark = 1; 186 $expectedq->length = 1; 187 $expectedq->penalty = 0.3333333; 188 $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers'); 189 $expectedq->answer = array( 190 0 => array( 191 'text' => '<span style="font-size:12pt">yellow</span>', 192 'format' => FORMAT_HTML, 193 ), 194 1 => array( 195 'text' => '<span style="font-size:12pt">red</span>', 196 'format' => FORMAT_HTML, 197 ), 198 2 => array( 199 'text' => '<span style="font-size:12pt">off-beige</span>', 200 'format' => FORMAT_HTML, 201 ), 202 3 => array( 203 'text' => '<span style="font-size:12pt">blue</span>', 204 'format' => FORMAT_HTML, 205 ) 206 ); 207 $expectedq->fraction = array(0.5, 0, 0.5, 0); 208 $expectedq->feedback = array( 209 0 => array( 210 'text' => '', 211 'format' => FORMAT_HTML, 212 ), 213 1 => array( 214 'text' => '', 215 'format' => FORMAT_HTML, 216 ), 217 2 => array( 218 'text' => '', 219 'format' => FORMAT_HTML, 220 ), 221 3 => array( 222 'text' => '', 223 'format' => FORMAT_HTML, 224 ) 225 ); 226 227 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 228 } 229 230 public function test_import_truefalse() { 231 232 $xml = $this->make_test_xml(); 233 234 $importer = new qformat_blackboard_six(); 235 $questions = $importer->readquestions($xml); 236 $q = $questions[1]; 237 238 $expectedq = new stdClass(); 239 $expectedq->qtype = 'truefalse'; 240 $expectedq->name = '42 is the Absolute Answer to everything.'; 241 $expectedq->questiontext = '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>'; 242 $expectedq->questiontextformat = FORMAT_HTML; 243 $expectedq->generalfeedback = ''; 244 $expectedq->generalfeedbackformat = FORMAT_HTML; 245 $expectedq->defaultmark = 1; 246 $expectedq->length = 1; 247 $expectedq->correctanswer = 0; 248 $expectedq->feedbacktrue = array( 249 'text' => '42 is the <b>Ultimate</b> Answer.', 250 'format' => FORMAT_HTML, 251 ); 252 $expectedq->feedbackfalse = array( 253 'text' => 'You gave the right answer.', 254 'format' => FORMAT_HTML, 255 ); 256 257 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 258 } 259 260 public function test_import_fill_in_the_blank() { 261 262 $xml = $this->make_test_xml(); 263 264 $importer = new qformat_blackboard_six(); 265 $questions = $importer->readquestions($xml); 266 $q = $questions[5]; 267 268 $expectedq = new stdClass(); 269 $expectedq->qtype = 'shortanswer'; 270 $expectedq->name = 'Name an amphibian: __________.'; 271 $expectedq->questiontext = '<span style="font-size:12pt">Name an amphibian: __________.</span>'; 272 $expectedq->questiontextformat = FORMAT_HTML; 273 $expectedq->generalfeedback = ''; 274 $expectedq->generalfeedbackformat = FORMAT_HTML; 275 $expectedq->defaultmark = 1; 276 $expectedq->length = 1; 277 $expectedq->usecase = 0; 278 $expectedq->answer = array('frog', '*'); 279 $expectedq->fraction = array(1, 0); 280 $expectedq->feedback = array( 281 0 => array( 282 'text' => 'A frog is an amphibian.', 283 'format' => FORMAT_HTML, 284 ), 285 1 => array( 286 'text' => 'A frog is an amphibian.', 287 'format' => FORMAT_HTML, 288 ) 289 ); 290 291 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 292 } 293 294 public function test_import_essay() { 295 296 $xml = $this->make_test_xml(); 297 298 $importer = new qformat_blackboard_six(); 299 $questions = $importer->readquestions($xml); 300 $q = $questions[6]; 301 302 $expectedq = new stdClass(); 303 $expectedq->qtype = 'essay'; 304 $expectedq->name = 'How are you?'; 305 $expectedq->questiontext = 'How are you?'; 306 $expectedq->questiontextformat = FORMAT_HTML; 307 $expectedq->generalfeedback = ''; 308 $expectedq->generalfeedbackformat = FORMAT_HTML; 309 $expectedq->defaultmark = 1; 310 $expectedq->length = 1; 311 $expectedq->responseformat = 'editor'; 312 $expectedq->responsefieldlines = 15; 313 $expectedq->attachments = 0; 314 $expectedq->graderinfo = array( 315 'text' => 'Blackboard answer for essay questions will be imported as informations for graders.', 316 'format' => FORMAT_HTML, 317 ); 318 319 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 320 } 321 322 public function test_import_category() { 323 324 $xml = $this->make_test_xml(); 325 326 $importer = new qformat_blackboard_six(); 327 $questions = $importer->readquestions($xml); 328 $q = $questions[0]; 329 330 $expectedq = new stdClass(); 331 $expectedq->qtype = 'category'; 332 $expectedq->category = 'sample_blackboard_six'; 333 334 $this->assert(new question_check_specified_fields_expectation($expectedq), $q); 335 } 336 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body