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 Embedded answer (Cloze) question importer.
20
* @package qformat_multianswer
21
* @copyright 2012 The Open University
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/multianswer/format.php');
32
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
36
* Unit tests for the Embedded answer (Cloze) question importer.
38
* @copyright 2012 The Open University
39
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
class qformat_multianswer_test extends question_testcase {
43
public function test_import() {
44
$lines = file(__DIR__ . '/fixtures/questions.multianswer.txt');
46
$importer = new qformat_multianswer();
47
$qs = $importer->readquestions($lines);
49
$expectedq = (object) array(
50
'name' => 'Match the following cities with the correct state:
53
'questiontext' => 'Match the following cities with the correct state:
58
The capital of France is {#5}.
60
'questiontextformat' => FORMAT_MOODLE,
61
'generalfeedback' => '',
62
'generalfeedbackformat' => FORMAT_MOODLE,
63
'qtype' => 'multianswer',
65
'penalty' => 0.3333333,
69
$this->assertEquals(1, count($qs));
70
$this->assert(new question_check_specified_fields_expectation($expectedq), $qs[0]);
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);