MDL-63812 qtype_gapselect: test data generator to standard qtype pattern
[moodle.git] / question / type / gapselect / tests / helper.php
CommitLineData
0d24b17a 1<?php
0d24b17a
TH
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
0d24b17a
TH
17/**
18 * Contains the helper class for the select missing words question type tests.
19 *
bbe27b2d
TH
20 * @package qtype_gapselect
21 * @copyright 2011 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0d24b17a
TH
23 */
24
25
b28ad86a
TH
26defined('MOODLE_INTERNAL') || die();
27
28
0d24b17a
TH
29/**
30 * Test helper class for the select missing words question type.
31 *
bbe27b2d
TH
32 * @copyright 2011 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0d24b17a 34 */
fdbff6ce
TH
35class qtype_gapselect_test_helper extends question_test_helper {
36 public function get_test_questions() {
37 return array('fox', 'maths', 'currency', 'multilang');
38 }
39
40 public static function get_gapselect_question_data_fox() {
41 global $USER;
42
43 $gapselect = new stdClass();
44 $gapselect->id = 0;
45 $gapselect->category = 0;
46 $gapselect->contextid = 0;
47 $gapselect->parent = 0;
48 $gapselect->questiontextformat = FORMAT_HTML;
49 $gapselect->generalfeedbackformat = FORMAT_HTML;
50 $gapselect->defaultmark = 1;
51 $gapselect->penalty = 0.3333333;
52 $gapselect->length = 1;
53 $gapselect->stamp = make_unique_id_code();
54 $gapselect->version = make_unique_id_code();
55 $gapselect->hidden = 0;
56 $gapselect->idnumber = null;
57 $gapselect->timecreated = time();
58 $gapselect->timemodified = time();
59 $gapselect->createdby = $USER->id;
60 $gapselect->modifiedby = $USER->id;
61
62 $gapselect->name = 'Selection from drop down list question';
63 $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
64 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
65 $gapselect->qtype = 'gapselect';
66
67 $gapselect->options = new stdClass();
68 $gapselect->options->shuffleanswers = true;
69
70 test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
71
72 $gapselect->options->answers = array(
73 (object) array('answer' => 'quick', 'feedback' => '1'),
74 (object) array('answer' => 'fox', 'feedback' => '2'),
75 (object) array('answer' => 'lazy', 'feedback' => '3'),
76 (object) array('answer' => 'assiduous', 'feedback' => '3'),
77 (object) array('answer' => 'dog', 'feedback' => '2'),
78 (object) array('answer' => 'slow', 'feedback' => '1'),
79 );
80
81 return $gapselect;
82 }
83
0d24b17a 84 /**
647d9373 85 * Get an example gapselect question to use for testing. This examples has one of each item.
0d24b17a
TH
86 * @return qtype_gapselect_question
87 */
fdbff6ce 88 public static function make_gapselect_question_fox() {
0d24b17a
TH
89 question_bank::load_question_definition_classes('gapselect');
90 $gapselect = new qtype_gapselect_question();
91
92 test_question_maker::initialise_a_question($gapselect);
93
94 $gapselect->name = 'Selection from drop down list question';
95 $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
96 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
97 $gapselect->qtype = question_bank::get_qtype('gapselect');
98
99 $gapselect->shufflechoices = true;
100
101 test_question_maker::set_standard_combined_feedback_fields($gapselect);
102
103 $gapselect->choices = array(
104 1 => array(
105 1 => new qtype_gapselect_choice('quick', 1),
106 2 => new qtype_gapselect_choice('slow', 1)),
107 2 => array(
108 1 => new qtype_gapselect_choice('fox', 2),
109 2 => new qtype_gapselect_choice('dog', 2)),
110 3 => array(
111 1 => new qtype_gapselect_choice('lazy', 3),
112 2 => new qtype_gapselect_choice('assiduous', 3)),
113 );
114
115 $gapselect->places = array(1 => 1, 2 => 2, 3 => 3);
116 $gapselect->rightchoices = array(1 => 1, 2 => 1, 3 => 1);
117 $gapselect->textfragments = array('The ', ' brown ', ' jumped over the ', ' dog.');
118
119 return $gapselect;
120 }
121
122 /**
647d9373 123 * Get an example gapselect question to use for testing. This exmples had unlimited items.
0d24b17a
TH
124 * @return qtype_gapselect_question
125 */
fdbff6ce 126 public static function make_gapselect_question_maths() {
0d24b17a
TH
127 question_bank::load_question_definition_classes('gapselect');
128 $gapselect = new qtype_gapselect_question();
129
130 test_question_maker::initialise_a_question($gapselect);
131
132 $gapselect->name = 'Selection from drop down list question';
133 $gapselect->questiontext = 'Fill in the operators to make this equation work: ' .
134 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
135 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
136 $gapselect->qtype = question_bank::get_qtype('gapselect');
137
138 $gapselect->shufflechoices = true;
139
140 test_question_maker::set_standard_combined_feedback_fields($gapselect);
141
142 $gapselect->choices = array(
143 1 => array(
fdbff6ce
TH
144 1 => new qtype_gapselect_choice('+', 1),
145 2 => new qtype_gapselect_choice('-', 1),
146 3 => new qtype_gapselect_choice('*', 1),
147 4 => new qtype_gapselect_choice('/', 1),
0d24b17a
TH
148 ));
149
150 $gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1);
151 $gapselect->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
152 $gapselect->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3');
153
154 return $gapselect;
155 }
adb21080
LB
156
157 /**
158 * Get an example gapselect question with multilang entries to use for testing.
159 * @return qtype_gapselect_question
160 */
fdbff6ce 161 public static function make_gapselect_question_multilang() {
adb21080
LB
162 question_bank::load_question_definition_classes('gapselect');
163 $gapselect = new qtype_gapselect_question();
164
165 test_question_maker::initialise_a_question($gapselect);
166
167 $gapselect->name = 'Multilang select missing words question';
168 $gapselect->questiontext = '<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>[[1]] ' .
169 '<span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> [[2]].';
170 $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
171 $gapselect->qtype = question_bank::get_qtype('gapselect');
172
173 $gapselect->shufflechoices = true;
174
175 test_question_maker::set_standard_combined_feedback_fields($gapselect);
176
177 $gapselect->choices = array(
178 1 => array(
179 1 => new qtype_gapselect_choice('<span lang="en" class="multilang">cat</span><span lang="ru" ' .
fdbff6ce 180 'class="multilang">кошка</span>', 1),
adb21080 181 2 => new qtype_gapselect_choice('<span lang="en" class="multilang">dog</span><span lang="ru" ' .
fdbff6ce 182 'class="multilang">пес</span>', 1)),
adb21080
LB
183 2 => array(
184 1 => new qtype_gapselect_choice('<span lang="en" class="multilang">mat</span><span lang="ru" ' .
fdbff6ce 185 'class="multilang">коврике</span>', 2),
adb21080 186 2 => new qtype_gapselect_choice('<span lang="en" class="multilang">bat</span><span lang="ru" ' .
fdbff6ce 187 'class="multilang">бита</span>', 2))
adb21080
LB
188 );
189
190 $gapselect->places = array(1 => 1, 2 => 2);
191 $gapselect->rightchoices = array(1 => 1, 2 => 1);
192 $gapselect->textfragments = array('<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>',
193 ' <span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> ', '.');
194
195 return $gapselect;
196 }
410a088a
JB
197
198 /**
199 * This examples includes choices with currency like options.
200 * @return qtype_gapselect_question
201 */
fdbff6ce 202 public static function make_gapselect_question_currency() {
410a088a
JB
203 question_bank::load_question_definition_classes('gapselect');
204 $gapselect = new qtype_gapselect_question();
205
206 test_question_maker::initialise_a_question($gapselect);
207
208 $gapselect->name = 'Selection from currency like choices';
209 $gapselect->questiontext = 'The price of the ball is [[1]] approx.';
210 $gapselect->generalfeedback = 'The choice is yours';
211 $gapselect->qtype = question_bank::get_qtype('gapselect');
212
213 $gapselect->shufflechoices = true;
214
215 test_question_maker::set_standard_combined_feedback_fields($gapselect);
216
217 $gapselect->choices = [
218 1 => [
219 1 => new qtype_gapselect_choice('$2', 1),
220 2 => new qtype_gapselect_choice('$3', 1),
221 3 => new qtype_gapselect_choice('$4.99', 1),
222 4 => new qtype_gapselect_choice('-1', 1)
223 ]
224 ];
225
226 $gapselect->places = array(1 => 1);
227 $gapselect->rightchoices = array(1 => 1);
228 $gapselect->textfragments = array('The price of the ball is ', ' approx.');
229
230 return $gapselect;
231 }
fdbff6ce
TH
232
233 /**
234 * Just for backwards compatibility.
235 *
236 * @return qtype_gapselect_question
237 */
238 public static function make_a_gapselect_question() {
239 debugging('qtype_gapselect_test_helper::make_a_gapselect_question is deprecated. ' .
240 "Please use test_question_maker::make_question('gapselect') instead.");
241 return self::make_gapselect_question_fox();
242 }
243
244 /**
245 * Just for backwards compatibility.
246 *
247 * @return qtype_gapselect_question
248 */
249 public static function make_a_maths_gapselect_question() {
250 debugging('qtype_gapselect_test_helper::make_a_maths_gapselect_question is deprecated. ' .
251 "Please use test_question_maker::make_question('gapselect', 'maths') instead.");
252 return self::make_gapselect_question_maths();
253 }
254
255 /**
256 * Just for backwards compatibility.
257 *
258 * @return qtype_gapselect_question
259 */
260 public static function make_a_currency_gapselect_question() {
261 debugging('qtype_gapselect_test_helper::make_a_currency_gapselect_question is deprecated. ' .
262 "Please use test_question_maker::make_question('gapselect', 'currency') instead.");
263 return self::make_gapselect_question_currency();
264 }
265
266 /**
267 * Just for backwards compatibility.
268 *
269 * @return qtype_gapselect_question
270 */
271 public static function make_a_multilang_gapselect_question() {
272 debugging('qtype_gapselect_test_helper::make_a_multilang_gapselect_question is deprecated. ' .
273 "Please use test_question_maker::make_question('gapselect', 'multilang') instead.");
274 return self::make_gapselect_question_multilang();
275 }
0d24b17a 276}