Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Contains the helper class for the select missing words question type tests.
19
 *
20
 * @package   qtype_gapselect
21
 * @copyright 2011 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
 
29
/**
30
 * Test helper class for the select missing words question type.
31
 *
32
 * @copyright 2011 The Open University
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class qtype_gapselect_test_helper extends question_test_helper {
36
 
37
    public function get_test_questions() {
38
        return array('fox', 'maths', 'currency', 'multilang', 'missingchoiceno');
39
    }
40
 
41
    /**
42
     * Get data you would get by loading a typical select missing words question.
43
     *
44
     * @return stdClass as returned by question_bank::load_question_data for this qtype.
45
     */
46
    public static function get_gapselect_question_data_fox() {
47
        global $USER;
48
 
49
        $gapselect = new stdClass();
50
        $gapselect->id = 0;
51
        $gapselect->category = 0;
52
        $gapselect->contextid = 0;
53
        $gapselect->parent = 0;
54
        $gapselect->questiontextformat = FORMAT_HTML;
55
        $gapselect->generalfeedbackformat = FORMAT_HTML;
56
        $gapselect->defaultmark = 1;
57
        $gapselect->penalty = 0.3333333;
58
        $gapselect->length = 1;
59
        $gapselect->stamp = make_unique_id_code();
60
        $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
61
        $gapselect->versionid = 0;
62
        $gapselect->version = 1;
63
        $gapselect->questionbankentryid = 0;
64
        $gapselect->idnumber = null;
65
        $gapselect->timecreated = time();
66
        $gapselect->timemodified = time();
67
        $gapselect->createdby = $USER->id;
68
        $gapselect->modifiedby = $USER->id;
69
 
70
        $gapselect->name = 'Selection from drop down list question';
71
        $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
72
        $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
73
        $gapselect->qtype = 'gapselect';
74
 
75
        $gapselect->options = new stdClass();
76
        $gapselect->options->shuffleanswers = true;
77
 
78
        test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
79
 
80
        $gapselect->options->answers = array(
81
            (object) array('answer' => 'quick', 'feedback' => '1'),
82
            (object) array('answer' => 'fox', 'feedback' => '2'),
83
            (object) array('answer' => 'lazy', 'feedback' => '3'),
84
            (object) array('answer' => 'assiduous', 'feedback' => '3'),
85
            (object) array('answer' => 'dog', 'feedback' => '2'),
86
            (object) array('answer' => 'slow', 'feedback' => '1'),
87
        );
88
 
89
        return $gapselect;
90
    }
91
 
92
    /**
93
     * Get data required to save a select missing words question where
94
     * the author missed out one of the group numbers.
95
     *
96
     * @return stdClass data to create a gapselect question.
97
     */
98
    public function get_gapselect_question_form_data_missingchoiceno() {
99
        $fromform = new stdClass();
100
 
101
        $fromform->name = 'Select missing words question';
102
        $fromform->questiontext = ['text' => 'The [[1]] sat on the [[3]].', 'format' => FORMAT_HTML];
103
        $fromform->defaultmark = 1.0;
104
        $fromform->generalfeedback = ['text' => 'The right answer is: "The cat sat on the mat."', 'format' => FORMAT_HTML];
105
        $fromform->choices = [
106
                ['answer' => 'cat', 'choicegroup' => '1'],
107
                ['answer' => '',    'choicegroup' => '1'],
108
                ['answer' => 'mat', 'choicegroup' => '1'],
109
        ];
110
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
111
        $fromform->shownumcorrect = 0;
112
        $fromform->penalty = 0.3333333;
113
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
114
 
1441 ariadna 115
        $fromform->hint = [
116
            [
117
                'text' => 'Cat',
118
                'format' => FORMAT_HTML,
119
            ],
120
        ];
121
 
1 efrain 122
        return $fromform;
123
    }
124
 
125
    /**
126
     * Get an example gapselect question to use for testing. This examples has one of each item.
127
     * @return qtype_gapselect_question
128
     */
129
    public static function make_gapselect_question_fox() {
130
        question_bank::load_question_definition_classes('gapselect');
131
        $gapselect = new qtype_gapselect_question();
132
 
133
        test_question_maker::initialise_a_question($gapselect);
134
 
135
        $gapselect->name = 'Selection from drop down list question';
136
        $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
137
        $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
138
        $gapselect->qtype = question_bank::get_qtype('gapselect');
139
        $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
140
 
141
        $gapselect->shufflechoices = true;
142
 
143
        test_question_maker::set_standard_combined_feedback_fields($gapselect);
144
 
145
        $gapselect->choices = array(
146
            1 => array(
147
                1 => new qtype_gapselect_choice('quick', 1),
148
                2 => new qtype_gapselect_choice('slow', 1)),
149
            2 => array(
150
                1 => new qtype_gapselect_choice('fox', 2),
151
                2 => new qtype_gapselect_choice('dog', 2)),
152
            3 => array(
153
                1 => new qtype_gapselect_choice('lazy', 3),
154
                2 => new qtype_gapselect_choice('assiduous', 3)),
155
        );
156
 
157
        $gapselect->places = array(1 => 1, 2 => 2, 3 => 3);
158
        $gapselect->rightchoices = array(1 => 1, 2 => 1, 3 => 1);
159
        $gapselect->textfragments = array('The ', ' brown ', ' jumped over the ', ' dog.');
160
 
161
        return $gapselect;
162
    }
163
 
164
    /**
165
     * Get an example gapselect question to use for testing. This exmples had unlimited items.
166
     * @return qtype_gapselect_question
167
     */
168
    public static function make_gapselect_question_maths() {
169
        question_bank::load_question_definition_classes('gapselect');
170
        $gapselect = new qtype_gapselect_question();
171
 
172
        test_question_maker::initialise_a_question($gapselect);
173
 
174
        $gapselect->name = 'Selection from drop down list question';
175
        $gapselect->questiontext = 'Fill in the operators to make this equation work: ' .
176
                '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
177
        $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
178
        $gapselect->qtype = question_bank::get_qtype('gapselect');
179
        $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
180
 
181
        $gapselect->shufflechoices = true;
182
 
183
        test_question_maker::set_standard_combined_feedback_fields($gapselect);
184
 
185
        $gapselect->choices = array(
186
            1 => array(
187
                1 => new qtype_gapselect_choice('+', 1),
188
                2 => new qtype_gapselect_choice('-', 1),
189
                3 => new qtype_gapselect_choice('*', 1),
190
                4 => new qtype_gapselect_choice('/', 1),
191
            ));
192
 
193
        $gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1);
194
        $gapselect->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
195
        $gapselect->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3');
196
 
197
        return $gapselect;
198
    }
199
 
200
    /**
201
     * Get an example gapselect question with multilang entries to use for testing.
202
     * @return qtype_gapselect_question
203
     */
204
    public static function make_gapselect_question_multilang() {
205
        question_bank::load_question_definition_classes('gapselect');
206
        $gapselect = new qtype_gapselect_question();
207
 
208
        test_question_maker::initialise_a_question($gapselect);
209
 
210
        $gapselect->name = 'Multilang select missing words question';
211
        $gapselect->questiontext = '<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>[[1]] ' .
212
            '<span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> [[2]].';
213
        $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
214
        $gapselect->qtype = question_bank::get_qtype('gapselect');
215
        $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
216
 
217
        $gapselect->shufflechoices = true;
218
 
219
        test_question_maker::set_standard_combined_feedback_fields($gapselect);
220
 
221
        $gapselect->choices = array(
222
                1 => array(
223
                    1 => new qtype_gapselect_choice('<span lang="en" class="multilang">cat</span><span lang="ru" ' .
224
                        'class="multilang">кошка</span>', 1),
225
                    2 => new qtype_gapselect_choice('<span lang="en" class="multilang">dog</span><span lang="ru" ' .
226
                        'class="multilang">пес</span>', 1)),
227
                2 => array(
228
                    1 => new qtype_gapselect_choice('<span lang="en" class="multilang">mat</span><span lang="ru" ' .
229
                        'class="multilang">коврике</span>', 2),
230
                    2 => new qtype_gapselect_choice('<span lang="en" class="multilang">bat</span><span lang="ru" ' .
231
                        'class="multilang">бита</span>', 2))
232
                );
233
 
234
        $gapselect->places = array(1 => 1, 2 => 2);
235
        $gapselect->rightchoices = array(1 => 1, 2 => 1);
236
        $gapselect->textfragments = array('<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>',
237
            ' <span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> ', '.');
238
 
239
        return $gapselect;
240
    }
241
 
242
    /**
243
     * This examples includes choices with currency like options.
244
     * @return qtype_gapselect_question
245
     */
246
    public static function make_gapselect_question_currency() {
247
        question_bank::load_question_definition_classes('gapselect');
248
        $gapselect = new qtype_gapselect_question();
249
 
250
        test_question_maker::initialise_a_question($gapselect);
251
 
252
        $gapselect->name = 'Selection from currency like choices';
253
        $gapselect->questiontext = 'The price of the ball is [[1]] approx.';
254
        $gapselect->generalfeedback = 'The choice is yours';
255
        $gapselect->qtype = question_bank::get_qtype('gapselect');
256
        $gapselect->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
257
 
258
        $gapselect->shufflechoices = true;
259
 
260
        test_question_maker::set_standard_combined_feedback_fields($gapselect);
261
 
262
        $gapselect->choices = [
263
                1 => [
264
                        1 => new qtype_gapselect_choice('$2', 1),
265
                        2 => new qtype_gapselect_choice('$3', 1),
266
                        3 => new qtype_gapselect_choice('$4.99', 1),
267
                        4 => new qtype_gapselect_choice('-1', 1)
268
                ]
269
        ];
270
 
271
        $gapselect->places = array(1 => 1);
272
        $gapselect->rightchoices = array(1 => 1);
273
        $gapselect->textfragments = array('The price of the ball is ', ' approx.');
274
 
275
        return $gapselect;
276
    }
277
 
278
    /**
279
     * Just for backwards compatibility.
280
     *
281
     * @return qtype_gapselect_question
282
     */
283
    public static function make_a_gapselect_question() {
284
        debugging('qtype_gapselect_test_helper::make_a_gapselect_question is deprecated. ' .
285
                "Please use test_question_maker::make_question('gapselect') instead.");
286
        return self::make_gapselect_question_fox();
287
    }
288
 
289
    /**
290
     * Just for backwards compatibility.
291
     *
292
     * @return qtype_gapselect_question
293
     */
294
    public static function make_a_maths_gapselect_question() {
295
        debugging('qtype_gapselect_test_helper::make_a_maths_gapselect_question is deprecated. ' .
296
                "Please use test_question_maker::make_question('gapselect', 'maths') instead.");
297
        return self::make_gapselect_question_maths();
298
    }
299
 
300
    /**
301
     * Just for backwards compatibility.
302
     *
303
     * @return qtype_gapselect_question
304
     */
305
    public static function make_a_currency_gapselect_question() {
306
        debugging('qtype_gapselect_test_helper::make_a_currency_gapselect_question is deprecated. ' .
307
                "Please use test_question_maker::make_question('gapselect', 'currency') instead.");
308
        return self::make_gapselect_question_currency();
309
    }
310
 
311
    /**
312
     * Just for backwards compatibility.
313
     *
314
     * @return qtype_gapselect_question
315
     */
316
    public static function make_a_multilang_gapselect_question() {
317
        debugging('qtype_gapselect_test_helper::make_a_multilang_gapselect_question is deprecated. ' .
318
                "Please use test_question_maker::make_question('gapselect', 'multilang') instead.");
319
        return self::make_gapselect_question_multilang();
320
    }
321
}