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 shortanswer question type.
19
 *
20
 * @package    qtype_shortanswer
21
 * @copyright  2012 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 shortanswer 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_shortanswer_test_helper extends question_test_helper {
36
    public function get_test_questions() {
37
        return array('frogtoad', 'frogonly', 'escapedwildcards');
38
    }
39
 
40
    /**
41
     * Makes a shortanswer question with correct ansewer 'frog', partially
42
     * correct answer 'toad' and defaultmark 1. This question also has a
43
     * '*' match anything answer.
44
     * @return qtype_shortanswer_question
45
     */
46
    public function make_shortanswer_question_frogtoad() {
47
        question_bank::load_question_definition_classes('shortanswer');
48
        $sa = new qtype_shortanswer_question();
49
        test_question_maker::initialise_a_question($sa);
50
        $sa->name = 'Short answer question';
51
        $sa->questiontext = 'Name an amphibian: __________';
52
        $sa->generalfeedback = 'Generalfeedback: frog or toad would have been OK.';
53
        $sa->usecase = false;
54
        $sa->answers = array(
55
            13 => new question_answer(13, 'frog', 1.0, 'Frog is a very good answer.', FORMAT_HTML),
56
            14 => new question_answer(14, 'toad', 0.8, 'Toad is an OK good answer.', FORMAT_HTML),
57
            15 => new question_answer(15, '*', 0.0, 'That is a bad answer.', FORMAT_HTML),
58
        );
59
        $sa->qtype = question_bank::get_qtype('shortanswer');
60
 
61
        return $sa;
62
    }
63
 
64
    /**
65
     * Gets the question data for a shortanswer question with with correct
66
     * ansewer 'frog', partially correct answer 'toad' and defaultmark 1.
67
     * This question also has a '*' match anything answer.
68
     * @return stdClass
69
     */
70
    public function get_shortanswer_question_data_frogtoad() {
71
        $qdata = new stdClass();
72
        test_question_maker::initialise_question_data($qdata);
73
 
74
        $qdata->qtype = 'shortanswer';
75
        $qdata->name = 'Short answer question';
76
        $qdata->questiontext = 'Name an amphibian: __________';
77
        $qdata->generalfeedback = 'Generalfeedback: frog or toad would have been OK.';
78
        $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
79
 
80
        $qdata->options = new stdClass();
81
        $qdata->options->usecase = 0;
82
        $qdata->options->answers = array(
83
            13 => new question_answer(13, 'frog', 1.0, 'Frog is a very good answer.', FORMAT_HTML),
84
            14 => new question_answer(14, 'toad', 0.8, 'Toad is an OK good answer.', FORMAT_HTML),
85
            15 => new question_answer(15, '*', 0.0, 'That is a bad answer.', FORMAT_HTML),
86
        );
87
 
88
        return $qdata;
89
    }
90
 
91
    /**
92
     * Gets the question form data for a shortanswer question with with correct
93
     * answer 'frog', partially correct answer 'toad' and defaultmark 1.
94
     * This question also has a '*' match anything answer.
95
     * @return stdClass
96
     */
97
    public function get_shortanswer_question_form_data_frogtoad() {
98
        $form = new stdClass();
99
 
100
        $form->name = 'Short answer question';
101
        $form->questiontext = array('text' => 'Name an amphibian: __________', 'format' => FORMAT_HTML);
102
        $form->defaultmark = 1.0;
103
        $form->generalfeedback = array('text' => 'Generalfeedback: frog or toad would have been OK.', 'format' => FORMAT_HTML);
104
        $form->usecase = false;
105
        $form->answer = array('frog', 'toad', '*');
106
        $form->fraction = array('1.0', '0.8', '0.0');
107
        $form->feedback = array(
108
            array('text' => 'Frog is a very good answer.', 'format' => FORMAT_HTML),
109
            array('text' => 'Toad is an OK good answer.', 'format' => FORMAT_HTML),
110
            array('text' => 'That is a bad answer.', 'format' => FORMAT_HTML),
111
        );
112
        $form->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
1441 ariadna 113
        $form->hint = [
114
            [
115
                'text' => 'Rhymes with dog',
116
                'format' => FORMAT_HTML,
117
            ],
118
        ];
1 efrain 119
        return $form;
120
    }
121
 
122
    /**
123
     * Makes a shortanswer question with just the correct ansewer 'frog', and
124
     * no other answer matching.
125
     * @return qtype_shortanswer_question
126
     */
127
    public function make_shortanswer_question_frogonly() {
128
        question_bank::load_question_definition_classes('shortanswer');
129
        $sa = new qtype_shortanswer_question();
130
        test_question_maker::initialise_a_question($sa);
131
        $sa->name = 'Short answer question';
132
        $sa->questiontext = 'Name the best amphibian: __________';
133
        $sa->generalfeedback = 'Generalfeedback: you should have said frog.';
134
        $sa->usecase = false;
135
        $sa->answers = array(
136
            13 => new question_answer(13, 'frog', 1.0, 'Frog is right.', FORMAT_HTML),
137
        );
138
        $sa->qtype = question_bank::get_qtype('shortanswer');
139
 
140
        return $sa;
141
    }
142
 
143
    /**
144
     * Gets the question data for a shortanswer questionwith just the correct
145
     * ansewer 'frog', and no other answer matching.
146
     * @return stdClass
147
     */
148
    public function get_shortanswer_question_data_frogonly() {
149
        $qdata = new stdClass();
150
        test_question_maker::initialise_question_data($qdata);
151
 
152
        $qdata->qtype = 'shortanswer';
153
        $qdata->name = 'Short answer question';
154
        $qdata->questiontext = 'Name the best amphibian: __________';
155
        $qdata->generalfeedback = 'Generalfeedback: you should have said frog.';
156
        $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
157
 
158
        $qdata->options = new stdClass();
159
        $qdata->options->usecase = false;
160
        $qdata->options->answers = array(
161
            13 => new question_answer(13, 'frog', 1.0, 'Frog is right.', FORMAT_HTML),
162
        );
163
 
164
        return $qdata;
165
    }
166
 
167
    /**
168
     * Makes a shortanswer question with just the correct ansewer 'frog', and
169
     * no other answer matching.
170
     * @return qtype_shortanswer_question
171
     */
172
    public function make_shortanswer_question_escapedwildcards() {
173
        question_bank::load_question_definition_classes('shortanswer');
174
        $sa = new qtype_shortanswer_question();
175
        test_question_maker::initialise_a_question($sa);
176
        $sa->name = 'Question with escaped * in the answer.';
177
        $sa->questiontext = 'How to you write x times y in C? __________';
178
        $sa->generalfeedback = 'In C, this expression is written x * y.';
179
        $sa->usecase = false;
180
        $sa->answers = array(
181
            13 => new question_answer(13, '*x\*y*', 1.0, 'Well done.', FORMAT_HTML),
182
        );
183
        $sa->qtype = question_bank::get_qtype('shortanswer');
184
 
185
        return $sa;
186
    }
187
}