Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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_pool_test extends question_testcase {
  42  
  43      public function make_test_xml() {
  44          $xmlfile = new qformat_blackboard_six_file();
  45          $xmlfile->filetype = 2;
  46          $xmlfile->text = file_get_contents(__DIR__ . '/fixtures/sample_blackboard_pool.dat');
  47          return array(0 => $xmlfile);
  48      }
  49  
  50      public function test_import_match() {
  51  
  52          $xml = $this->make_test_xml();
  53  
  54          $importer = new qformat_blackboard_six();
  55          $questions = $importer->readquestions($xml);
  56  
  57          $q = $questions[5];
  58  
  59          // If qtype_ddmatch is installed, the formatter produces ddmatch
  60          // qtypes, not match ones.
  61          $ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch');
  62  
  63          $expectedq = new stdClass();
  64          $expectedq->qtype = $ddmatchisinstalled ? 'ddmatch' : 'match';
  65          $expectedq->name = 'Classify the animals.';
  66          $expectedq->questiontext = '<i>Classify the animals.</i>';
  67          $expectedq->questiontextformat = FORMAT_HTML;
  68          $expectedq->correctfeedback = array('text' => '',
  69                  'format' => FORMAT_HTML);
  70          $expectedq->partiallycorrectfeedback = array('text' => '',
  71                  'format' => FORMAT_HTML);
  72          $expectedq->incorrectfeedback = array('text' => '',
  73                  'format' => FORMAT_HTML);
  74          $expectedq->generalfeedback = '';
  75          $expectedq->generalfeedbackformat = FORMAT_HTML;
  76          $expectedq->defaultmark = 1;
  77          $expectedq->length = 1;
  78          $expectedq->penalty = 0.3333333;
  79          $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
  80          $expectedq->subquestions = array(
  81              array('text' => 'cat', 'format' => FORMAT_HTML),
  82              array('text' => '', 'format' => FORMAT_HTML),
  83              array('text' => 'frog', 'format' => FORMAT_HTML),
  84              array('text' => 'newt', 'format' => FORMAT_HTML));
  85  
  86          if ($ddmatchisinstalled) {
  87              $expectedq->subanswers = array(
  88                  array('text' => 'mammal', 'format' => FORMAT_HTML),
  89                  array('text' => 'insect', 'format' => FORMAT_HTML),
  90                  array('text' => 'amphibian', 'format' => FORMAT_HTML),
  91                  array('text' => 'amphibian', 'format' => FORMAT_HTML),
  92              );
  93          } else {
  94              $expectedq->subanswers = array('mammal', 'insect', 'amphibian', 'amphibian');
  95          }
  96          $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
  97      }
  98  
  99      public function test_import_multichoice_single() {
 100  
 101          $xml = $this->make_test_xml();
 102  
 103          $importer = new qformat_blackboard_six();
 104          $questions = $importer->readquestions($xml);
 105          $q = $questions[2];
 106  
 107          $expectedq = new stdClass();
 108          $expectedq->qtype = 'multichoice';
 109          $expectedq->single = 1;
 110          $expectedq->name = 'What\'s between orange and green in the spectrum?';
 111          $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
 112          $expectedq->questiontextformat = FORMAT_HTML;
 113          $expectedq->correctfeedback = array('text' => 'You gave the right answer.',
 114                  'format' => FORMAT_HTML);
 115          $expectedq->partiallycorrectfeedback = array('text' => '',
 116                  'format' => FORMAT_HTML);
 117          $expectedq->incorrectfeedback = array('text' => 'Only yellow is between orange and green in the spectrum.',
 118                  'format' => FORMAT_HTML);
 119          $expectedq->generalfeedback = '';
 120          $expectedq->generalfeedbackformat = FORMAT_HTML;
 121          $expectedq->defaultmark = 1;
 122          $expectedq->length = 1;
 123          $expectedq->penalty = 0.3333333;
 124          $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
 125          $expectedq->answer = array(
 126                  0 => array(
 127                      'text' => '<span style="font-size:12pt">red</span>',
 128                      'format' => FORMAT_HTML,
 129                  ),
 130                  1 => array(
 131                      'text' => '<span style="font-size:12pt">yellow</span>',
 132                      'format' => FORMAT_HTML,
 133                  ),
 134                  2 => array(
 135                      'text' => '<span style="font-size:12pt">blue</span>',
 136                      'format' => FORMAT_HTML,
 137                  )
 138              );
 139          $expectedq->fraction = array(0, 1, 0);
 140          $expectedq->feedback = array(
 141                  0 => array(
 142                      'text' => '',
 143                      'format' => FORMAT_HTML,
 144                  ),
 145                  1 => array(
 146                      'text' => '',
 147                      'format' => FORMAT_HTML,
 148                  ),
 149                  2 => array(
 150                      'text' => '',
 151                      'format' => FORMAT_HTML,
 152                  )
 153              );
 154  
 155          $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
 156      }
 157  
 158      public function test_import_multichoice_multi() {
 159  
 160          $xml = $this->make_test_xml();
 161  
 162          $importer = new qformat_blackboard_six();
 163          $questions = $importer->readquestions($xml);
 164          $q = $questions[3];
 165  
 166          $expectedq = new stdClass();
 167          $expectedq->qtype = 'multichoice';
 168          $expectedq->single = 0;
 169          $expectedq->name = 'What\'s between orange and green in the spectrum?';
 170          $expectedq->questiontext = '<span style="font-size:12pt">What\'s between orange and green in the spectrum?</span>';
 171          $expectedq->questiontextformat = FORMAT_HTML;
 172          $expectedq->correctfeedback = array(
 173                  'text' => 'You gave the right answer.',
 174                  'format' => FORMAT_HTML,
 175              );
 176          $expectedq->partiallycorrectfeedback = array(
 177                  'text' => 'Only yellow and off-beige are between orange and green in the spectrum.',
 178                  'format' => FORMAT_HTML,
 179              );
 180          $expectedq->incorrectfeedback = array(
 181                  'text' => 'Only yellow and off-beige are between orange and green in the spectrum.',
 182                  'format' => FORMAT_HTML,
 183                  );
 184          $expectedq->generalfeedback = '';
 185          $expectedq->generalfeedbackformat = FORMAT_HTML;
 186          $expectedq->defaultmark = 1;
 187          $expectedq->length = 1;
 188          $expectedq->penalty = 0.3333333;
 189          $expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
 190          $expectedq->answer = array(
 191                  0 => array(
 192                      'text' => '<span style="font-size:12pt">yellow</span>',
 193                      'format' => FORMAT_HTML,
 194                  ),
 195                  1 => array(
 196                      'text' => '<span style="font-size:12pt">red</span>',
 197                      'format' => FORMAT_HTML,
 198                  ),
 199                  2 => array(
 200                      'text' => '<span style="font-size:12pt">off-beige</span>',
 201                      'format' => FORMAT_HTML,
 202                  ),
 203                  3 => array(
 204                      'text' => '<span style="font-size:12pt">blue</span>',
 205                      'format' => FORMAT_HTML,
 206                  )
 207              );
 208          $expectedq->fraction = array(0.5, 0, 0.5, 0);
 209          $expectedq->feedback = array(
 210                  0 => array(
 211                      'text' => '',
 212                      'format' => FORMAT_HTML,
 213                  ),
 214                  1 => array(
 215                      'text' => '',
 216                      'format' => FORMAT_HTML,
 217                  ),
 218                  2 => array(
 219                      'text' => '',
 220                      'format' => FORMAT_HTML,
 221                  ),
 222                  3 => array(
 223                      'text' => '',
 224                      'format' => FORMAT_HTML,
 225                  )
 226              );
 227  
 228          $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
 229      }
 230  
 231      public function test_import_truefalse() {
 232  
 233          $xml = $this->make_test_xml();
 234  
 235          $importer = new qformat_blackboard_six();
 236          $questions = $importer->readquestions($xml);
 237          $q = $questions[1];
 238  
 239          $expectedq = new stdClass();
 240          $expectedq->qtype = 'truefalse';
 241          $expectedq->name = '42 is the Absolute Answer to everything.';
 242          $expectedq->questiontext = '<span style="font-size:12pt">42 is the Absolute Answer to everything.</span>';
 243          $expectedq->questiontextformat = FORMAT_HTML;
 244          $expectedq->generalfeedback = '';
 245          $expectedq->generalfeedbackformat = FORMAT_HTML;
 246          $expectedq->defaultmark = 1;
 247          $expectedq->length = 1;
 248          $expectedq->correctanswer = 0;
 249          $expectedq->feedbacktrue = array(
 250                  'text' => '42 is the Ultimate Answer.',
 251                  'format' => FORMAT_HTML,
 252              );
 253          $expectedq->feedbackfalse = array(
 254                  'text' => 'You gave the right answer.',
 255                  'format' => FORMAT_HTML,
 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[4];
 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' => '',
 283                      'format' => FORMAT_HTML,
 284                  ),
 285                  1 => array(
 286                      'text' => '',
 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 = 'exam 3 2008-9';
 333  
 334          $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
 335      }
 336  }