0746b51a813d051f08cbe8c4b313ef2ec9e70801
[moodle.git] / question / type / multichoice / tests / helper.php
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/>.
17 /**
18  * Test helper code for the multiple choice question type.
19  *
20  * @package    qtype_multichoice
21  * @copyright  2013 The Open University
22  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
26 defined('MOODLE_INTERNAL') || die();
29 /**
30  * Test helper class for the multiple choice question type.
31  *
32  * @copyright  2013 The Open University
33  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34  */
35 class qtype_multichoice_test_helper extends question_test_helper {
36     public function get_test_questions() {
37         return array('two_of_four');
38     }
40     /**
41      * Get the question data, as it would be loaded by get_question_options.
42      * @return object
43      */
44     public static function get_multichoice_question_data_two_of_four() {
45         global $USER;
47         $qdata = new stdClass();
49         $qdata->createdby = $USER->id;
50         $qdata->modifiedby = $USER->id;
51         $qdata->qtype = 'multichoice';
52         $qdata->name = 'Multiple choice question';
53         $qdata->questiontext = 'Which are the odd numbers?';
54         $qdata->questiontextformat = FORMAT_HTML;
55         $qdata->generalfeedback = 'The odd numbers are One and Three.';
56         $qdata->generalfeedbackformat = FORMAT_HTML;
57         $qdata->defaultmark = 1;
58         $qdata->length = 1;
59         $qdata->penalty = 0.3333333;
60         $qdata->hidden = 0;
62         $qdata->options = new stdClass();
63         $qdata->options->shuffleanswers = 1;
64         $qdata->options->answernumbering = '123';
65         $qdata->options->layout = 0;
66         $qdata->options->single = 0;
67         $qdata->options->correctfeedback =
68                 test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK;
69         $qdata->options->correctfeedbackformat = FORMAT_HTML;
70         $qdata->options->partiallycorrectfeedback =
71                 test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK;
72         $qdata->options->partiallycorrectfeedbackformat = FORMAT_HTML;
73         $qdata->options->shownumcorrect = 1;
74         $qdata->options->incorrectfeedback =
75                 test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK;
76         $qdata->options->incorrectfeedbackformat = FORMAT_HTML;
78         $qdata->options->answers = array(
79             13 => (object) array(
80                 'id' => 13,
81                 'answer' => 'One',
82                 'answerformat' => FORMAT_PLAIN,
83                 'fraction' => '0.5',
84                 'feedback' => 'One is odd.',
85                 'feedbackformat' => FORMAT_HTML,
86             ),
87             14 => (object) array(
88                 'id' => 14,
89                 'answer' => 'Two',
90                 'answerformat' => FORMAT_PLAIN,
91                 'fraction' => '0.0',
92                 'feedback' => 'Two is even.',
93                 'feedbackformat' => FORMAT_HTML,
94             ),
95             15 => (object) array(
96                 'id' => 15,
97                 'answer' => 'Three',
98                 'answerformat' => FORMAT_PLAIN,
99                 'fraction' => '0.5',
100                 'feedback' => 'Three is odd.',
101                 'feedbackformat' => FORMAT_HTML,
102             ),
103             16 => (object) array(
104                 'id' => 16,
105                 'answer' => 'Four',
106                 'answerformat' => FORMAT_PLAIN,
107                 'fraction' => '0.0',
108                 'feedback' => 'Four is even.',
109                 'feedbackformat' => FORMAT_HTML,
110             ),
111         );
113         $qdata->hints = array(
114             1 => (object) array(
115                 'hint' => 'Hint 1.',
116                 'hintformat' => FORMAT_HTML,
117                 'shownumcorrect' => 1,
118                 'clearwrong' => 0,
119                 'options' => 0,
120             ),
121             2 => (object) array(
122                 'hint' => 'Hint 2.',
123                 'hintformat' => FORMAT_HTML,
124                 'shownumcorrect' => 1,
125                 'clearwrong' => 1,
126                 'options' => 1,
127             ),
128         );
130         return $qdata;
131     }
132     /**
133      * Get the question data, as it would be loaded by get_question_options.
134      * @return object
135      */
136     public static function get_multichoice_question_form_data_two_of_four() {
137         $qdata = new stdClass();
139         $qdata->name = 'multiple choice question';
140         $qdata->questiontext = array('text' => 'Which are the odd numbers?', 'format' => FORMAT_HTML);
141         $qdata->generalfeedback = array('text' => 'The odd numbers are One and Three.', 'format' => FORMAT_HTML);
142         $qdata->defaultmark = 1;
143         $qdata->noanswers = 5;
144         $qdata->numhints = 2;
145         $qdata->penalty = 0.3333333;
147         $qdata->shuffleanswers = 1;
148         $qdata->answernumbering = '123';
149         $qdata->single = '0';
150         $qdata->correctfeedback = array('text' => test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK,
151                                                  'format' => FORMAT_HTML);
152         $qdata->partiallycorrectfeedback = array('text' => test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK,
153                                                           'format' => FORMAT_HTML);
154         $qdata->shownumcorrect = 1;
155         $qdata->incorrectfeedback = array('text' => test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK,
156                                                    'format' => FORMAT_HTML);
157         $qdata->fraction = array('0.5', '0.0', '0.5', '0.0', '0.0');
158         $qdata->answer = array(
159             0 => array(
160                 'text' => 'One',
161                 'format' => FORMAT_PLAIN
162             ),
163             1 => array(
164                 'text' => 'Two',
165                 'format' => FORMAT_PLAIN
166             ),
167             2 => array(
168                 'text' => 'Three',
169                 'format' => FORMAT_PLAIN
170             ),
171             3 => array(
172                 'text' => 'Four',
173                 'format' => FORMAT_PLAIN
174             ),
175             4 => array(
176                 'text' => '',
177                 'format' => FORMAT_PLAIN
178             )
179         );
181         $qdata->feedback = array(
182             0 => array(
183                 'text' => 'One is odd.',
184                 'format' => FORMAT_HTML
185             ),
186             1 => array(
187                 'text' => 'Two is even.',
188                 'format' => FORMAT_HTML
189             ),
190             2 => array(
191                 'text' => 'Three is odd.',
192                 'format' => FORMAT_HTML
193             ),
194             3 => array(
195                 'text' => 'Four is even.',
196                 'format' => FORMAT_HTML
197             ),
198             4 => array(
199                 'text' => '',
200                 'format' => FORMAT_HTML
201             )
202         );
204         $qdata->hint = array(
205             0 => array(
206                 'text' => 'Hint 1.',
207                 'format' => FORMAT_HTML
208             ),
209             1 => array(
210                 'text' => 'Hint 2.',
211                 'format' => FORMAT_HTML
212             )
213         );
214         $qdata->hintclearwrong = array(0, 1);
215         $qdata->hintshownumcorrect = array(1, 1);
217         return $qdata;
218     }