[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/question/format/multianswer/tests/ -> multianswerformat_test.php (source)

   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 Embedded answer (Cloze) question importer.
  19   *
  20   * @package   qformat_multianswer
  21   * @copyright 2012 The Open University
  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/multianswer/format.php');
  32  require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
  33  
  34  
  35  /**
  36   * Unit tests for the Embedded answer (Cloze) question importer.
  37   *
  38   * @copyright 2012 The Open University
  39   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class qformat_multianswer_test extends question_testcase {
  42  
  43      public function test_import() {
  44          $lines = file(__DIR__ . '/fixtures/questions.multianswer.txt');
  45  
  46          $importer = new qformat_multianswer();
  47          $qs = $importer->readquestions($lines);
  48  
  49          $expectedq = (object) array(
  50              'name' => 'Match the following cities with the correct state:
  51  * San Francisco: {#1}
  52  * ...',
  53              'questiontext' => 'Match the following cities with the correct state:
  54  * San Francisco: {#1}
  55  * Tucson: {#2}
  56  * Los Angeles: {#3}
  57  * Phoenix: {#4}
  58  The capital of France is {#5}.
  59  ',
  60              'questiontextformat' => FORMAT_MOODLE,
  61              'generalfeedback' => '',
  62              'generalfeedbackformat' => FORMAT_MOODLE,
  63              'qtype' => 'multianswer',
  64              'defaultmark' => 5,
  65              'penalty' => 0.3333333,
  66              'length' => 1,
  67          );
  68  
  69          $this->assertEquals(1, count($qs));
  70          $this->assert(new question_check_specified_fields_expectation($expectedq), $qs[0]);
  71  
  72          $this->assertEquals('multichoice', $qs[0]->options->questions[1]->qtype);
  73          $this->assertEquals('multichoice', $qs[0]->options->questions[2]->qtype);
  74          $this->assertEquals('multichoice', $qs[0]->options->questions[3]->qtype);
  75          $this->assertEquals('multichoice', $qs[0]->options->questions[4]->qtype);
  76          $this->assertEquals('shortanswer', $qs[0]->options->questions[5]->qtype);
  77      }
  78  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1