MDL-34226 multichoice qtype: correct is_complete_response for multianswer
[moodle.git] / question / type / multianswer / 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 multianswer question type.
19 *
20 * @package qtype
21 * @subpackage multianswer
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/multianswer/question.php');
31
32
33/**
34 * Test helper class for the multianswer 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_multianswer_test_helper extends question_test_helper {
40 public function get_test_questions() {
41 return array('twosubq');
42 }
43
44 /**
45 * Makes a multianswer question about completing two blanks in some text.
46 * @return qtype_multianswer_question
47 */
48 public function make_multianswer_question_twosubq() {
49 question_bank::load_question_definition_classes('multianswer');
50 $q = new qtype_multianswer_question();
51 test_question_maker::initialise_a_question($q);
52 $q->name = 'Simple multianswer';
53 $q->questiontext =
54 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".';
55 $q->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' .
56 '"The owl and the pussycat went to sea';
57
58 // Shortanswer subquestion.
59 question_bank::load_question_definition_classes('shortanswer');
60 $sa = new qtype_shortanswer_question();
61 test_question_maker::initialise_a_question($sa);
62 $sa->name = 'Simple multianswer';
63 $sa->questiontext = '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}';
64 $sa->questiontextformat = FORMAT_HTML;
65 $sa->generalfeedback = '';
66 $sa->generalfeedbackformat = FORMAT_HTML;
67 $sa->usecase = true;
68 $sa->answers = array(
69 13 => new question_answer(13, 'Dog', 0.0, 'Wrong, silly!', FORMAT_HTML),
70 14 => new question_answer(14, 'Owl', 1.0, 'Well done!', FORMAT_HTML),
71 15 => new question_answer(15, '*', 0.0, 'Wrong answer', FORMAT_HTML),
72 );
73 $sa->qtype = question_bank::get_qtype('shortanswer');
74 $sa->maxmark = 1;
75
76 // Multiple-choice subquestion.
77 question_bank::load_question_definition_classes('multichoice');
78 $mc = new qtype_multichoice_single_question();
79 test_question_maker::initialise_a_question($mc);
80 $mc->name = 'Simple multianswer';
81 $mc->questiontext = '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!' .
82 '~Wiggly worm#Now you are just being rediculous!~=Pussy-cat#Well done!}';
83 $mc->questiontextformat = FORMAT_HTML;
84 $mc->generalfeedback = '';
85 $mc->generalfeedbackformat = FORMAT_HTML;
86
87 $mc->shuffleanswers = 1;
88 $mc->answernumbering = 'none';
89 $mc->layout = qtype_multichoice_base::LAYOUT_DROPDOWN;
90
91 $mc->answers = array(
92 13 => new question_answer(13, 'Bow-wow', 0,
93 'You seem to have a dog obsessions!', FORMAT_HTML),
94 14 => new question_answer(14, 'Wiggly worm', 0,
95 'Now you are just being rediculous!', FORMAT_HTML),
96 15 => new question_answer(15, 'Pussy-cat', 1,
97 'Well done!', FORMAT_HTML),
98 );
99 $mc->qtype = question_bank::get_qtype('multichoice');
100 $mc->maxmark = 1;
101
102 $q->subquestions = array(
103 1 => $sa,
104 2 => $mc,
105 );
106
107 return $q;
108 }
109
110 /**
111 * Makes a multianswer question about completing two blanks in some text.
112 * @return object the question definition data, as it might be returned from
113 * get_question_options.
114 */
115 public function get_multianswer_question_data_twosubq() {
116 $qdata = new stdClass();
117 test_question_maker::initialise_question_data($qdata);
118
119 $qdata->name = 'Simple multianswer';
120 $qdata->questiontext =
121 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".';
122 $qdata->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' .
123 '"The owl and the pussycat went to sea';
124
125 $qdata->defaultmark = 2.0;
126 $qdata->qtype = 'multianswer';
127
128 $sa = new stdClass();
129 test_question_maker::initialise_question_data($sa);
130
131 $sa->name = 'Simple multianswer';
132 $sa->questiontext = '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}';
133 $sa->generalfeedback = '';
134 $sa->penalty = 0.0;
135 $sa->qtype = 'shortanswer';
136
137 $sa->options = new stdClass();
138 $sa->options->usecase = 0;
139
140 $sa->options->answers = array(
141 13 => new question_answer(13, 'Dog', 0, 'Wrong, silly!', FORMAT_HTML),
142 14 => new question_answer(14, 'Owl', 1, 'Well done!', FORMAT_HTML),
143 15 => new question_answer(15, '*', 0, 'Wrong answer', FORMAT_HTML),
144 );
145
146 $mc = new stdClass();
147 test_question_maker::initialise_question_data($mc);
148
149 $mc->name = 'Simple multianswer';
150 $mc->questiontext = '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!~' .
151 'Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!}';
152 $mc->generalfeedback = '';
153 $mc->penalty = 0.0;
154 $mc->qtype = 'multichoice';
155
156 $mc->options = new stdClass();
157 $mc->options->layout = 0;
158 $mc->options->single = 1;
159 $mc->options->shuffleanswers = 1;
160 $mc->options->correctfeedback = '';
161 $mc->options->correctfeedbackformat = 1;
162 $mc->options->partiallycorrectfeedback = '';
163 $mc->options->partiallycorrectfeedbackformat = 1;
164 $mc->options->incorrectfeedback = '';
165 $mc->options->incorrectfeedbackformat = 1;
166 $mc->options->answernumbering = '';
167 $mc->options->shownumcorrect = 0;
168
169 $mc->options->answers = array(
170 23 => new question_answer(23, 'Bow-wow', 0,
171 'You seem to have a dog obsessions!', FORMAT_HTML),
172 24 => new question_answer(24, 'Wiggly worm', 0,
173 'Now you are just being ridiculous!', FORMAT_HTML),
174 25 => new question_answer(25, 'Pussy-cat', 1,
175 'Well done!', FORMAT_HTML),
176 );
177
178 $qdata->options = new stdClass();
179 $qdata->options->questions = array(
180 1 => $sa,
181 2 => $mc,
182 );
183
184 $qdata->hints = array(
185 new question_hint(0, 'Hint 1', FORMAT_HTML),
186 new question_hint(0, 'Hint 2', FORMAT_HTML),
187 );
188
189 return $qdata;
190 }
191
192 /**
193 * Makes a multianswer question about completing two blanks in some text.
194 * @return object the question definition data, as it might be returned from
195 * the question editing form.
196 */
197 public function get_multianswer_question_form_data_twosubq() {
198 $formdata = new stdClass();
199 test_question_maker::initialise_question_form_data($formdata);
200
201 $formdata->name = 'Simple multianswer';
202 $formdata->questiontext = 'Complete this opening line of verse: "The ' .
203 '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer} ' .
204 'and the {1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!' .
205 '~Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!}' .
206 ' went to sea".';
207 $formdata->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" ' .
208 'by Lear: "The owl and the pussycat went to sea';
209
210 $formdata->hint = array(
211 0 => array('text' => 'Hint 1', 'format' => FORMAT_HTML, 'itemid' => 0),
212 1 => array('text' => 'Hint 2', 'format' => FORMAT_HTML, 'itemid' => 0),
213 );
214
215 return $formdata;
216 }
217}