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 words into sentences question type.
19
 *
20
 * @package   qtype_ddwtos
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 words into sentences 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_ddwtos_test_helper extends question_test_helper {
36
    public function get_test_questions() {
1441 ariadna 37
        return ['fox', 'maths', 'oddgroups', 'missingchoiceno', 'infinite', 'mathjax'];
1 efrain 38
    }
39
 
40
    /**
41
     * @return qtype_ddwtos_question
42
     */
43
    public function make_ddwtos_question_fox() {
44
        question_bank::load_question_definition_classes('ddwtos');
45
        $dd = new qtype_ddwtos_question();
46
 
47
        test_question_maker::initialise_a_question($dd);
48
 
49
        $dd->name = 'Drag-and-drop words into sentences question';
50
        $dd->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
51
        $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
52
        $dd->qtype = question_bank::get_qtype('ddwtos');
53
 
54
        $dd->shufflechoices = true;
55
 
56
        test_question_maker::set_standard_combined_feedback_fields($dd);
57
 
58
        $dd->choices = array(
59
            1 => array(
60
                1 => new qtype_ddwtos_choice('quick', 1),
61
                2 => new qtype_ddwtos_choice('slow', 1)),
62
            2 => array(
63
                1 => new qtype_ddwtos_choice('fox', 2),
64
                2 => new qtype_ddwtos_choice('dog', 2)),
65
            3 => array(
66
                1 => new qtype_ddwtos_choice('lazy', 3),
67
                2 => new qtype_ddwtos_choice('assiduous', 3)),
68
        );
69
 
70
        $dd->places = array(1 => 1, 2 => 2, 3 => 3);
71
        $dd->rightchoices = array(1 => 1, 2 => 1, 3 => 1);
72
        $dd->textfragments = array('The ', ' brown ', ' jumped over the ', ' dog.');
73
 
74
        return $dd;
75
    }
76
 
77
    /**
78
     * This is a simple question with choices in three groups.
79
     *
80
     * @return stdClass data to create a ddwtos question.
81
     */
82
    public function get_ddwtos_question_form_data_fox() {
83
        $fromform = new stdClass();
84
 
85
        $fromform->name = 'Drag-and-drop words into sentences question';
86
        $fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML);
87
        $fromform->defaultmark = 1.0;
88
        $fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML);
89
        $fromform->choices = array(
90
            array('answer' => 'quick',     'choicegroup' => '1'),
91
            array('answer' => 'fox',       'choicegroup' => '2'),
92
            array('answer' => 'lazy',      'choicegroup' => '3'),
93
            array('answer' => 'slow',      'choicegroup' => '1'),
94
            array('answer' => 'dog',       'choicegroup' => '2'),
95
            array('answer' => 'assiduous', 'choicegroup' => '3'),
96
        );
97
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
98
        $fromform->shownumcorrect = 0;
99
        $fromform->penalty = 0.3333333;
100
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
101
 
1441 ariadna 102
        $fromform->hint = [
103
            [
104
                'text' => 'Fast',
105
                'format' => FORMAT_HTML,
106
            ],
107
        ];
108
 
1 efrain 109
        return $fromform;
110
    }
111
 
112
    /**
113
     * Similar to the 'fox' example above, but using different, non-continuous group numbers.
114
     *
115
     * @return stdClass data to create a ddwtos question.
116
     */
117
    public function get_ddwtos_question_form_data_oddgroups() {
118
        $fromform = new stdClass();
119
 
120
        $fromform->name = 'Drag-and-drop words with strange groups';
121
        $fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML);
122
        $fromform->defaultmark = 1.0;
123
        $fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML);
124
        $fromform->choices = array(
125
            array('answer' => 'quick',     'choicegroup' => '5'),
126
            array('answer' => 'fox',       'choicegroup' => '7'),
127
            array('answer' => 'lazy',      'choicegroup' => '3'),
128
            array('answer' => 'slow',      'choicegroup' => '5'),
129
            array('answer' => 'dog',       'choicegroup' => '7'),
130
            array('answer' => 'assiduous', 'choicegroup' => '3'),
131
        );
132
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
133
        $fromform->shownumcorrect = 0;
134
        $fromform->penalty = 0.3333333;
135
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
136
 
137
        return $fromform;
138
    }
139
 
140
    /**
141
     * Get data required to save a drag-drop into text question where the author
142
     * missed out one of the group numbers.
143
     *
144
     * @return stdClass data to create a ddwtos question.
145
     */
146
    public function get_ddwtos_question_form_data_missingchoiceno() {
147
        $fromform = new stdClass();
148
 
149
        $fromform->name = 'Drag-drop into text question with one index missing';
150
        $fromform->questiontext = ['text' => 'The [[1]] sat on the [[3]].', 'format' => FORMAT_HTML];
151
        $fromform->defaultmark = 1.0;
152
        $fromform->generalfeedback = array('text' => 'The right answer is: "The cat sat on the mat."', 'format' => FORMAT_HTML);
153
        $fromform->choices = array(
154
                array('answer' => 'cat', 'choicegroup' => '1'),
155
                array('answer' => '',    'choicegroup' => '1'),
156
                array('answer' => 'mat', 'choicegroup' => '1'),
157
        );
158
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
159
        $fromform->shownumcorrect = 0;
160
        $fromform->penalty = 0.3333333;
161
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
162
 
163
        return $fromform;
164
    }
165
 
166
    /**
1441 ariadna 167
     * Get data required to save a drag-drop into text question where the the answer contain equation
168
     *
169
     *
170
     * @return stdClass data to create a ddwtos question.
171
     */
172
    public function get_ddwtos_question_form_data_mathjax() {
173
        $fromform = new stdClass();
174
 
175
        $fromform->name = 'Drag-and-drop words into sentences question with equation';
176
        $fromform->questiontext = ['text' => 'Fill in the correct mathjax equation: y = 2, x =4 : [[1]]', 'format' => FORMAT_HTML];
177
        $fromform->defaultmark = 1.0;
178
        $fromform->generalfeedback = ['text' => 'The right answer is: "y = x^2"', 'format' => FORMAT_HTML];
179
        $fromform->choices = [
180
            ['answer' => '$$ y = x^2 $$', 'choicegroup' => '1'],
181
            ['answer' => '$$ y = x^5 $$', 'choicegroup' => '1'],
182
        ];
183
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
184
        $fromform->shownumcorrect = 0;
185
        $fromform->penalty = 0.3333333;
186
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
187
        return $fromform;
188
    }
189
 
190
    /**
1 efrain 191
     * @return qtype_ddwtos_question
192
     */
193
    public function make_ddwtos_question_maths() {
194
        question_bank::load_question_definition_classes('ddwtos');
195
        $dd = new qtype_ddwtos_question();
196
 
197
        test_question_maker::initialise_a_question($dd);
198
 
199
        $dd->name = 'Drag-and-drop words into sentences question';
200
        $dd->questiontext = 'Fill in the operators to make this equation work: ' .
201
                '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
202
        $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
203
        $dd->qtype = question_bank::get_qtype('ddwtos');
204
 
205
        $dd->shufflechoices = true;
206
 
207
        test_question_maker::set_standard_combined_feedback_fields($dd);
208
 
209
        $dd->choices = array(
210
            1 => array(
211
                1 => new qtype_ddwtos_choice('+', 1, true),
212
                2 => new qtype_ddwtos_choice('-', 1, true),
213
                3 => new qtype_ddwtos_choice('*', 1, true),
214
                4 => new qtype_ddwtos_choice('/', 1, true),
215
            ));
216
 
217
        $dd->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1);
218
        $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
219
        $dd->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3');
220
 
221
        return $dd;
222
    }
223
 
224
    /**
225
     * This is a simple question with infinite mode.
226
     *
227
     * @return stdClass data to create a ddwtos question.
228
     */
229
    public function get_ddwtos_question_form_data_infinite() {
230
        $fromform = new stdClass();
231
 
232
        $fromform->name = 'Drag-and-drop infinite question';
233
        $fromform->questiontext = ['text' => 'One [[1]] Two [[2]] Three [[3]]', 'format' => FORMAT_HTML];
234
        $fromform->defaultmark = 1.0;
235
        $fromform->generalfeedback = ['text' => 'This is general feedback', 'format' => FORMAT_HTML];
236
        $fromform->choices = [
237
                ['answer' => 'Option1', 'choicegroup' => '1', 'infinite' => true],
238
                ['answer' => 'Option2', 'choicegroup' => '1', 'infinite' => true],
239
                ['answer' => 'Option3', 'choicegroup' => '1', 'infinite' => true]
240
        ];
241
        test_question_maker::set_standard_combined_feedback_form_data($fromform);
242
        $fromform->shownumcorrect = 0;
243
        $fromform->penalty = 0.3333333;
244
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
245
 
246
        return $fromform;
247
    }
248
}