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
 * Test helpers for the match question type.
19
 *
20
 * @package    qtype_match
21
 * @copyright  2013 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->dirroot . '/question/type/match/question.php');
30
 
31
 
32
/**
33
 * Test helper class for the match question type.
34
 *
35
 * @copyright  2013 The Open University
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class qtype_match_test_helper extends question_test_helper {
39
    public function get_test_questions() {
40
        return array('foursubq', 'trickynums');
41
    }
42
 
43
    /**
44
     * Makes a match question about completing two blanks in some text.
45
     * @return object the question definition data, as it might be returned from
46
     * get_question_options.
47
     */
48
    public function get_match_question_data_foursubq() {
49
        global $USER;
50
        $q = new stdClass();
51
        test_question_maker::initialise_question_data($q);
52
        $q->name = 'Matching question';
53
        $q->qtype = 'match';
54
        $q->parent = 0;
55
        $q->questiontext = 'Classify the animals.';
56
        $q->questiontextformat = FORMAT_HTML;
57
        $q->generalfeedback = 'General feedback.';
58
        $q->generalfeedbackformat = FORMAT_HTML;
59
        $q->defaultmark = 1;
60
        $q->penalty = 0.3333333;
61
        $q->length = 1;
62
        $q->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
63
        $q->versionid = 0;
64
        $q->version = 1;
65
        $q->questionbankentryid = 0;
66
        $q->createdby = $USER->id;
67
        $q->modifiedby = $USER->id;
68
 
69
        $q->options = new stdClass();
70
        $q->options->shuffleanswers = 1;
71
        test_question_maker::set_standard_combined_feedback_fields($q->options);
72
 
73
        $q->options->subquestions = array(
74
            14 => (object) array(
75
                'id' => 14,
76
                'questiontext' => 'frog',
77
                'questiontextformat' => FORMAT_HTML,
78
                'answertext' => 'amphibian'),
79
            15 => (object) array(
80
                'id' => 15,
81
                'questiontext' => 'cat',
82
                'questiontextformat' => FORMAT_HTML,
83
                'answertext' => 'mammal'),
84
            16 => (object) array(
85
                'id' => 16,
86
                'questiontext' => 'newt',
87
                'questiontextformat' => FORMAT_HTML,
88
                'answertext' => 'amphibian'),
89
            17 => (object) array(
90
                'id' => 17,
91
                'questiontext' => '',
92
                'questiontextformat' => FORMAT_HTML,
93
                'answertext' => 'insect'),
94
        );
95
 
96
        return $q;
97
    }
98
 
99
    /**
100
     * Makes a match question about completing two blanks in some text.
101
     * @return object the question definition data, as it might be returned from
102
     *      the question editing form.
103
     */
104
    public function get_match_question_form_data_foursubq() {
105
        $q = new stdClass();
106
        $q->name = 'Matching question';
107
        $q->questiontext = array('text' => 'Classify the animals.', 'format' => FORMAT_HTML);
108
        $q->generalfeedback = array('text' => 'General feedback.', 'format' => FORMAT_HTML);
109
        $q->defaultmark = 1;
110
        $q->penalty = 0.3333333;
111
        $q->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
112
        $q->versionid = 0;
113
        $q->version = 1;
114
        $q->questionbankentryid = 0;
115
 
116
        $q->shuffleanswers = 1;
117
        test_question_maker::set_standard_combined_feedback_form_data($q);
118
 
119
        $q->subquestions = array(
120
 
121
            1 => array('text' => 'cat', 'format' => FORMAT_HTML),
122
            2 => array('text' => 'newt', 'format' => FORMAT_HTML),
123
            3 => array('text' => '', 'format' => FORMAT_HTML));
124
 
125
        $q->subanswers = array(
126
 
127
            1 => 'mammal',
128
            2 => 'amphibian',
129
            3 => 'insect'
130
        );
131
 
132
        $q->noanswers = 4;
133
 
1441 ariadna 134
        $q->hint = [
135
            [
136
                'text' => 'Frog and newt are the same',
137
                'format' => FORMAT_HTML,
138
            ],
139
        ];
140
 
1 efrain 141
        return $q;
142
    }
143
 
144
    /**
145
     * Makes a matching question to classify 'Dog', 'Frog', 'Toad' and 'Cat' as
146
     * 'Mammal', 'Amphibian' or 'Insect'.
147
     * defaultmark 1. Stems are shuffled by default.
148
     * @return qtype_match_question
149
     */
150
    public static function make_match_question_foursubq() {
151
        question_bank::load_question_definition_classes('match');
152
        $match = new qtype_match_question();
153
        test_question_maker::initialise_a_question($match);
154
        $match->name = 'Matching question';
155
        $match->questiontext = 'Classify the animals.';
156
        $match->generalfeedback = 'Frogs and toads are amphibians, the others are mammals.';
157
        $match->qtype = question_bank::get_qtype('match');
158
 
159
        $match->shufflestems = 1;
160
 
161
        test_question_maker::set_standard_combined_feedback_fields($match);
162
 
163
        // Using unset to get 1-based arrays.
164
        $match->stems = array('', 'Dog', 'Frog', 'Toad', 'Cat');
165
        $match->stemformat = array('', FORMAT_HTML, FORMAT_HTML, FORMAT_HTML, FORMAT_HTML);
166
        $match->choices = array('', 'Mammal', 'Amphibian', 'Insect');
167
        $match->right = array('', 1, 2, 2, 1);
168
        unset($match->stems[0]);
169
        unset($match->stemformat[0]);
170
        unset($match->choices[0]);
171
        unset($match->right[0]);
172
 
173
        return $match;
174
    }
175
 
176
    /**
177
     * Makes a matching question with choices including '0' and '0.0'.
178
     *
179
     * @return object the question definition data, as it might be returned from
180
     * get_question_options.
181
     */
182
    public function get_match_question_data_trickynums() {
183
        global $USER;
184
 
185
        $q = new stdClass();
186
        test_question_maker::initialise_question_data($q);
187
        $q->name = 'Java matching';
188
        $q->qtype = 'match';
189
        $q->parent = 0;
190
        $q->questiontext = 'What is the output of each of these lines of code?';
191
        $q->questiontextformat = FORMAT_HTML;
192
        $q->generalfeedback = 'Java has some advantages over PHP I guess!';
193
        $q->generalfeedbackformat = FORMAT_HTML;
194
        $q->defaultmark = 1;
195
        $q->penalty = 0.3333333;
196
        $q->length = 1;
197
        $q->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
198
        $q->versionid = 0;
199
        $q->version = 1;
200
        $q->questionbankentryid = 0;
201
        $q->createdby = $USER->id;
202
        $q->modifiedby = $USER->id;
203
 
204
        $q->options = new stdClass();
205
        $q->options->shuffleanswers = 1;
206
        test_question_maker::set_standard_combined_feedback_fields($q->options);
207
 
208
        $q->options->subquestions = array(
209
                14 => (object) array(
210
                        'id' => 14,
211
                        'questiontext' => 'System.out.println(0);',
212
                        'questiontextformat' => FORMAT_HTML,
213
                        'answertext' => '0'),
214
                15 => (object) array(
215
                        'id' => 15,
216
                        'questiontext' => 'System.out.println(0.0);',
217
                        'questiontextformat' => FORMAT_HTML,
218
                        'answertext' => '0.0'),
219
                16 => (object) array(
220
                        'id' => 16,
221
                        'questiontext' => '',
222
                        'questiontextformat' => FORMAT_HTML,
223
                        'answertext' => 'NULL'),
224
        );
225
 
226
        return $q;
227
    }
228
 
229
    /**
230
     * Makes a match question about completing two blanks in some text.
231
     * @return object the question definition data, as it might be returned from
232
     *      the question editing form.
233
     */
234
    public function get_match_question_form_data_trickynums() {
235
        $q = new stdClass();
236
        $q->name = 'Java matching';
237
        $q->questiontext = ['text' => 'What is the output of each of these lines of code?', 'format' => FORMAT_HTML];
238
        $q->generalfeedback = ['text' => 'Java has some advantages over PHP I guess!', 'format' => FORMAT_HTML];
239
        $q->defaultmark = 1;
240
        $q->penalty = 0.3333333;
241
        $q->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
242
        $q->versionid = 0;
243
        $q->version = 1;
244
        $q->questionbankentryid = 0;
245
 
246
        $q->shuffleanswers = 1;
247
        test_question_maker::set_standard_combined_feedback_form_data($q);
248
 
249
        $q->subquestions = array(
250
 
251
            1 => array('text' => 'System.out.println(0.0);', 'format' => FORMAT_HTML),
252
            2 => array('text' => '', 'format' => FORMAT_HTML),
253
        );
254
 
255
        $q->subanswers = array(
256
 
257
            1 => '0.0',
258
            2 => 'NULL',
259
        );
260
 
261
        $q->noanswers = 3;
262
 
263
        return $q;
264
    }
265
 
266
    /**
267
     * Makes a matching question with choices including '0' and '0.0'.
268
     *
269
     * @return qtype_match_question
270
     */
271
    public static function make_match_question_trickynums() {
272
        question_bank::load_question_definition_classes('match');
273
        $match = new qtype_match_question();
274
        test_question_maker::initialise_a_question($match);
275
        $match->name = 'Java matching';
276
        $match->questiontext = 'What is the output of each of these lines of code?';
277
        $match->generalfeedback = 'Java has some advantages over PHP I guess!';
278
        $match->qtype = question_bank::get_qtype('match');
279
 
280
        $match->shufflestems = 1;
281
 
282
        test_question_maker::set_standard_combined_feedback_fields($match);
283
 
284
        // Using unset to get 1-based arrays.
285
        $match->stems = array('', 'System.out.println(0);', 'System.out.println(0.0);');
286
        $match->stemformat = array('', FORMAT_HTML, FORMAT_HTML);
287
        $match->choices = array('', '0', '0.0', 'NULL');
288
        $match->right = array('', 1, 2);
289
        unset($match->stems[0]);
290
        unset($match->stemformat[0]);
291
        unset($match->choices[0]);
292
        unset($match->right[0]);
293
 
294
        return $match;
295
    }
296
}