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 drag-and-drop onto image question type.
19
 *
20
 * @package    qtype_ddimageortext
21
 * @copyright  2010 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 drag-and-drop onto image question type.
31
 *
32
 * @copyright  2010 The Open University
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class qtype_ddimageortext_test_helper extends question_test_helper {
36
    public function get_test_questions() {
1441 ariadna 37
        return ['fox', 'maths', 'xsection', 'mixedlang', 'mathjax'];
1 efrain 38
    }
39
 
40
    /**
41
     * @return qtype_ddimageortext_question
42
     */
43
    public function make_ddimageortext_question_fox() {
44
        question_bank::load_question_definition_classes('ddimageortext');
45
        $dd = new qtype_ddimageortext_question();
46
 
47
        test_question_maker::initialise_a_question($dd);
48
 
49
        $dd->name = 'Drag-and-drop onto image question';
50
        $dd->questiontext = 'The quick brown fox jumped over the lazy dog.';
51
        $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
52
        $dd->qtype = question_bank::get_qtype('ddimageortext');
53
 
54
        $dd->shufflechoices = true;
55
 
56
        test_question_maker::set_standard_combined_feedback_fields($dd);
57
 
58
        $dd->choices = $this->make_choice_structure(array(
59
                    new qtype_ddimageortext_drag_item('quick', 1, 1),
60
                    new qtype_ddimageortext_drag_item('fox', 2, 1),
61
                    new qtype_ddimageortext_drag_item('lazy', 3, 2),
62
                    new qtype_ddimageortext_drag_item('dog', 4, 2)
63
 
64
        ));
65
 
66
        $dd->places = $this->make_place_structure(array(
67
                            new qtype_ddimageortext_drop_zone('', 1, 1),
68
                            new qtype_ddimageortext_drop_zone('', 2, 1),
69
                            new qtype_ddimageortext_drop_zone('', 3, 2),
70
                            new qtype_ddimageortext_drop_zone('', 4, 2)
71
        ));
72
        $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 4);
73
 
74
        return $dd;
75
    }
76
 
77
    protected function make_choice_structure($choices) {
78
        $choicestructure = array();
79
        foreach ($choices as $choice) {
80
            if (!isset($choicestructure[$choice->group])) {
81
                $choicestructure[$choice->group][1] = $choice;
82
            } else {
83
                $choicestructure[$choice->group][$choice->no] = $choice;
84
            }
85
        }
86
        return $choicestructure;
87
    }
88
 
89
    protected function make_place_structure($places) {
90
        $placestructure = array();
91
        foreach ($places as $place) {
92
            $placestructure[$place->no] = $place;
93
        }
94
        return $placestructure;
95
    }
96
 
97
    /**
98
     * Make a mathematical ddimageortext question.
99
     *
100
     * @return qtype_ddimageortext_question
101
     */
102
    public function make_ddimageortext_question_maths() {
103
        question_bank::load_question_definition_classes('ddimageortext');
104
        $dd = new qtype_ddimageortext_question();
105
 
106
        test_question_maker::initialise_a_question($dd);
107
 
108
        $dd->name = 'Drag-and-drop onto image question';
109
        $dd->questiontext = 'Fill in the operators to make this equation work: ' .
110
                '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
111
        $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
112
        $dd->qtype = question_bank::get_qtype('ddimageortext');
113
 
114
        $dd->shufflechoices = true;
115
 
116
        test_question_maker::set_standard_combined_feedback_fields($dd);
117
 
118
        $dd->choices = $this->make_choice_structure(array(
119
                new qtype_ddimageortext_drag_item('+', 1, 1),
120
                new qtype_ddimageortext_drag_item('-', 2, 1)
121
        ));
122
 
123
        $dd->places = $this->make_place_structure(array(
124
                            new qtype_ddimageortext_drop_zone('', 1, 1),
125
                            new qtype_ddimageortext_drop_zone('', 2, 1),
126
                            new qtype_ddimageortext_drop_zone('', 3, 1),
127
                            new qtype_ddimageortext_drop_zone('', 4, 1)
128
        ));
129
        $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
130
 
131
        return $dd;
132
    }
133
 
134
    /**
135
     * @return stdClass date to create a ddimageortext question.
136
     */
137
    public function get_ddimageortext_question_form_data_xsection() {
138
        global $CFG, $USER;
139
        $fromform = new stdClass();
140
 
141
        $bgdraftitemid = 0;
142
        file_prepare_draft_area($bgdraftitemid, null, null, null, null);
143
        $fs = get_file_storage();
144
        $filerecord = new stdClass();
145
        $filerecord->contextid = context_user::instance($USER->id)->id;
146
        $filerecord->component = 'user';
147
        $filerecord->filearea = 'draft';
148
        $filerecord->itemid = $bgdraftitemid;
149
        $filerecord->filepath = '/';
150
        $filerecord->filename = 'oceanfloorbase.jpg';
151
        $fs->create_file_from_pathname($filerecord, $CFG->dirroot .
152
                '/question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg');
153
 
154
        $fromform->name = 'Geography cross-section';
155
        $fromform->questiontext = array(
156
            'text' => '<p>Identify the features in this cross-section by dragging the labels into the boxes.</p>
157
                       <p><em>Use the mouse to drag the boxed words into the empty boxes. '.
158
                      'Alternatively, use the tab key to select an empty box, '.
159
                      'then use the space key to cycle through the options.</em></p>',
160
            'format' => FORMAT_HTML,
161
        );
162
        $fromform->defaultmark = 1;
163
        $fromform->generalfeedback = array(
164
            'text' => '<p>More information about the major features of the Earth\'s surface '.
165
                      'can be found in Block 3, Section 6.2.</p>',
166
            'format' => FORMAT_HTML,
167
        );
168
        $fromform->bgimage = $bgdraftitemid;
169
        $fromform->shuffleanswers = 0;
1441 ariadna 170
        $fromform->dropzonevisibility = 0;
1 efrain 171
        $fromform->drags = array(
172
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
173
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
174
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
175
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
176
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
177
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
178
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
179
            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
180
        );
181
        $fromform->dragitem = array(0, 0, 0, 0, 0, 0, 0, 0);
182
        $fromform->draglabel =
183
        array(
184
            'island<br/>arc',
185
            'mid-ocean<br/>ridge',
186
            'abyssal<br/>plain',
187
            'continental<br/>rise',
188
            'ocean<br/>trench',
189
            'continental<br/>slope',
190
            'mountain<br/>belt',
191
            'continental<br/>shelf',
192
        );
193
        $fromform->drops = array(
194
            array('xleft' => '53', 'ytop' => '17', 'choice' => '7', 'droplabel' => ''),
195
            array('xleft' => '172', 'ytop' => '2', 'choice' => '8', 'droplabel' => ''),
196
            array('xleft' => '363', 'ytop' => '31', 'choice' => '5', 'droplabel' => ''),
197
            array('xleft' => '440', 'ytop' => '13', 'choice' => '3', 'droplabel' => ''),
198
            array('xleft' => '115', 'ytop' => '74', 'choice' => '6', 'droplabel' => ''),
199
            array('xleft' => '210', 'ytop' => '94', 'choice' => '4', 'droplabel' => ''),
200
            array('xleft' => '310', 'ytop' => '87', 'choice' => '1', 'droplabel' => ''),
201
            array('xleft' => '479', 'ytop' => '84', 'choice' => '2', 'droplabel' => ''),
202
        );
203
 
204
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
205
 
206
        $fromform->penalty = '0.3333333';
207
        $fromform->hint = array(
208
            array(
1441 ariadna 209
                'text' => '<p>1. Incorrect placements will be removed.</p>',
1 efrain 210
                'format' => FORMAT_HTML,
211
            ),
212
            array(
213
                'text' => '<ul>
1441 ariadna 214
                           <li>2. The abyssal plain is a flat almost featureless expanse of ocean '.
1 efrain 215
                           'floor 4km to 6km below sea-level.</li>
216
                           <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
217
                           <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
218
                           <li>The continental slope is the relatively steep part of the ocean floor '.
219
                           'beyond the continental shelf.</li>
220
                           <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
221
                           <li>A mountain belt is a long range of mountains.</li>
222
                           <li>An island arc is a chain of volcanic islands.</li>
223
                           <li>An oceanic trench is a deep trough in the ocean floor.</li>
224
                           </ul>',
225
                'format' => FORMAT_HTML,
226
            ),
227
            array(
1441 ariadna 228
                'text' => '<p>3. Incorrect placements will be removed.</p>',
1 efrain 229
                'format' => FORMAT_HTML,
230
            ),
231
            array(
232
                'text' => '<ul>
1441 ariadna 233
                           <li>4. The abyssal plain is a flat almost featureless expanse of ocean '.
1 efrain 234
                           'floor 4km to 6km below sea-level.</li>
235
                           <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
236
                           <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
237
                           <li>The continental slope is the relatively steep part of the ocean floor '.
238
                           'beyond the continental shelf.</li>
239
                           <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
240
                           <li>A mountain belt is a long range of mountains.</li>
241
                           <li>An island arc is a chain of volcanic islands.</li>
242
                           <li>An oceanic trench is a deep trough in the ocean floor.</li>
243
                           </ul>',
244
                'format' => FORMAT_HTML,
245
            ),
246
        );
247
        $fromform->hintclearwrong = array(1, 0, 1, 0);
248
        $fromform->hintshownumcorrect = array(1, 1, 1, 1);
249
 
250
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
251
 
252
        return $fromform;
253
    }
254
 
255
    /**
1441 ariadna 256
     * Get data required to save a drag-drop into text question where the the answer contain equation
257
     *
258
     *
259
     * @return stdClass data to create a ddwtos question.
260
     */
261
    public function get_ddimageortext_question_form_data_mathjax() {
262
        global $CFG, $USER;
263
        $fromform = new stdClass();
264
 
265
        $bgdraftitemid = 0;
266
        file_prepare_draft_area($bgdraftitemid, null, null, null, null);
267
        $fs = get_file_storage();
268
        $filerecord = new stdClass();
269
        $filerecord->contextid = context_user::instance($USER->id)->id;
270
        $filerecord->component = 'user';
271
        $filerecord->filearea = 'draft';
272
        $filerecord->itemid = $bgdraftitemid;
273
        $filerecord->filepath = '/';
274
        $filerecord->filename = 'oceanfloorbase.jpg';
275
        $fs->create_file_from_pathname($filerecord, $CFG->dirroot .
276
            '/question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg');
277
        $fromform->name = 'Drag-and-drop words into image question with equation';
278
        $fromform->questiontext = ['text' => 'Fill in the correct mathjax equation: y = 2, x =4', 'format' => FORMAT_HTML];
279
        $fromform->defaultmark = 1.0;
280
        $fromform->generalfeedback = ['text' => 'The right answer is: "y = x^2"', 'format' => FORMAT_HTML];
281
        $fromform->drags = [
282
            ['dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'],
283
            ['dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'],
284
        ];
285
        $fromform->bgimage = $bgdraftitemid;
286
        $fromform->dragitem = [0, 0];
287
        $fromform->draglabel =
288
            [
289
                '$$ y = x^2 $$',
290
                '$$ y = x^5 $$',
291
            ];
292
        $fromform->drops = [
293
            ['xleft' => '53', 'ytop' => '17', 'choice' => '1', 'droplabel' => ''],
294
            ['xleft' => '172', 'ytop' => '2', 'choice' => '2', 'droplabel' => ''],
295
        ];
296
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
297
        $fromform->shownumcorrect = 0;
298
        $fromform->penalty = 0.3333333;
299
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
300
        return $fromform;
301
    }
302
 
303
    /**
1 efrain 304
     * Make a test question where the drag items are a different language than the main question text.
305
     *
306
     * @return qtype_ddimageortext_question
307
     */
308
    public function make_ddimageortext_question_mixedlang() {
309
        question_bank::load_question_definition_classes('ddimageortext');
310
        $dd = new qtype_ddimageortext_question();
311
 
312
        test_question_maker::initialise_a_question($dd);
313
 
314
        $dd->name = 'Question about French in English.';
315
        $dd->questiontext = '<p>Complete the blanks in this sentence.</p>' .
316
                '<p lang="fr">J\'ai perdu [[1]] plume de [[2]] tante - l\'avez-vous vue?</p>';
317
        $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
318
        $dd->qtype = question_bank::get_qtype('ddimageortext');
319
 
320
        $dd->shufflechoices = true;
321
 
322
        test_question_maker::set_standard_combined_feedback_fields($dd);
323
 
324
        $dd->choices = $this->make_choice_structure(array(
325
                new qtype_ddimageortext_drag_item('<span lang="fr">la</span>', 1, 1),
326
                new qtype_ddimageortext_drag_item('<span lang="fr">ma</span>', 2, 1),
327
        ));
328
 
329
        $dd->places = $this->make_place_structure(array(
330
                new qtype_ddimageortext_drop_zone('', 1, 1),
331
                new qtype_ddimageortext_drop_zone('', 2, 1)
332
        ));
333
        $dd->rightchoices = array(1 => 1, 2 => 2);
334
 
335
        return $dd;
336
    }
337
}