MDL-32323 convert question tests
[moodle.git] / question / type / calculatedmulti / tests / helper.php
CommitLineData
603bd001
PS
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 * Test helpers for the calculated question type.
19 *
20 * @package qtype
21 * @subpackage calculatedmulti
22 * @copyright 2011 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30require_once($CFG->dirroot . '/question/type/calculated/question.php');
31
32
33/**
34 * Test helper class for the calculated multiple-choice question type.
35 *
36 * @copyright 2011 The Open University
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class qtype_calculatedmulti_test_helper extends question_test_helper {
40 public function get_test_questions() {
41 return array('sum');
42 }
43
44 /**
45 * Makes a calculated multiple-choice question about summing two numbers.
46 * @return qtype_calculatedmulti_question
47 */
48 public function make_calculatedmulti_question_sum() {
49 // TODO
50 question_bank::load_question_definition_classes('calculated');
51 $q = new qtype_calculatedmulti_question();
52 test_question_maker::initialise_a_question($q);
53 $q->name = 'Simple sum';
54 $q->questiontext = 'What is {a} + {b}?';
55 $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.';
56 $q->answers = array(
57 13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0),
58 14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.',
59 FORMAT_HTML, 0),
60 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
61 );
62 $q->qtype = question_bank::get_qtype('calculated');
63 $q->unitdisplay = qtype_numerical::UNITNONE;
64 $q->unitgradingtype = 0;
65 $q->unitpenalty = 0;
66 $q->ap = new qtype_numerical_answer_processor(array());
67
68 $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array(
69 array('a' => 1, 'b' => 5),
70 array('a' => 3, 'b' => 4),
71 ));
72
73 return $q;
74 }
75}