~ubuntu-branches/ubuntu/trusty/moodle/trusty-proposed

« back to all changes in this revision

Viewing changes to question/format/multianswer/tests/multianswerformat_test.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-07-19 08:52:46 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130719085246-yebwditc2exoap2r
Tags: 2.5.1-1
* New upstream version: 2.5.1.
  - Fixes security issues:
    CVE-2013-2242 CVE-2013-2243 CVE-2013-2244 CVE-2013-2245
    CVE-2013-2246
* Depend on apache2 instead of obsolete apache2-mpm-prefork.
* Use packaged libphp-phpmailer (closes: #429339), adodb,
  HTMLPurifier, PclZip.
* Update debconf translations, thanks Salvatore Merone, Pietro Tollot,
  Joe Hansen, Yuri Kozlov, Holger Wansing, Américo Monteiro,
  Adriano Rafael Gomes, victory, Michał Kułach.
  (closes: #716972, #716986, #717080, #717108, #717278)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}