MDL-47494 ddimageortext: Improve the drag-drop question Behat tests.
[moodle.git] / question / type / ddimageortext / tests / helper.php
CommitLineData
a2bb148a 1<?php
a2bb148a
TH
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
5b4602d2 17/**
c109c901 18 * Test helpers for the drag-and-drop onto image question type.
5b4602d2 19 *
c109c901 20 * @package qtype_ddimageortext
5b4602d2
TH
21 * @copyright 2010 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
a2bb148a 25
42536280
TH
26defined('MOODLE_INTERNAL') || die();
27
28
a2bb148a 29/**
c109c901 30 * Test helper class for the drag-and-drop onto image question type.
a2bb148a 31 *
5b4602d2
TH
32 * @copyright 2010 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a2bb148a 34 */
31077627 35class qtype_ddimageortext_test_helper extends question_test_helper {
46b0a973 36 public function get_test_questions() {
42865c84 37 return array('fox', 'maths', 'xsection');
46b0a973
TH
38 }
39
a2bb148a 40 /**
31077627 41 * @return qtype_ddimageortext_question
a2bb148a 42 */
31077627
JP
43 public function make_ddimageortext_question_fox() {
44 question_bank::load_question_definition_classes('ddimageortext');
45 $dd = new qtype_ddimageortext_question();
a2bb148a
TH
46
47 test_question_maker::initialise_a_question($dd);
48
c109c901 49 $dd->name = 'Drag-and-drop onto image question';
bfe79134 50 $dd->questiontext = 'The quick brown fox jumped over the lazy dog.';
a2bb148a 51 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
31077627 52 $dd->qtype = question_bank::get_qtype('ddimageortext');
a2bb148a
TH
53
54 $dd->shufflechoices = true;
55
56 test_question_maker::set_standard_combined_feedback_fields($dd);
57
bfe79134 58 $dd->choices = $this->make_choice_structure(array(
31077627
JP
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', 1, 2),
62 new qtype_ddimageortext_drag_item('dog', 2, 2)
bfe79134
JP
63
64 ));
65
66 $dd->places = $this->make_place_structure(array(
31077627
JP
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)
bfe79134
JP
71 ));
72 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
a2bb148a
TH
73
74 return $dd;
75 }
76
bfe79134
JP
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] = array();
82 }
83 $choicestructure[$choice->group][$choice->no] = $choice;
84 }
85 return $choicestructure;
86 }
87
88 protected function make_place_structure($places) {
89 $placestructure = array();
90 foreach ($places as $place) {
91 $placestructure[$place->no] = $place;
92 }
93 return $placestructure;
94 }
95
a2bb148a 96 /**
31077627 97 * @return qtype_ddimageortext_question
a2bb148a 98 */
31077627
JP
99 public function make_ddimageortext_question_maths() {
100 question_bank::load_question_definition_classes('ddimageortext');
101 $dd = new qtype_ddimageortext_question();
a2bb148a
TH
102
103 test_question_maker::initialise_a_question($dd);
104
c109c901 105 $dd->name = 'Drag-and-drop onto image question';
a2bb148a
TH
106 $dd->questiontext = 'Fill in the operators to make this equation work: ' .
107 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3';
108 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
31077627 109 $dd->qtype = question_bank::get_qtype('ddimageortext');
a2bb148a
TH
110
111 $dd->shufflechoices = true;
112
113 test_question_maker::set_standard_combined_feedback_fields($dd);
114
bfe79134 115 $dd->choices = $this->make_choice_structure(array(
31077627
JP
116 new qtype_ddimageortext_drag_item('+', 1, 1),
117 new qtype_ddimageortext_drag_item('-', 2, 1)
bfe79134
JP
118 ));
119
120 $dd->places = $this->make_place_structure(array(
31077627
JP
121 new qtype_ddimageortext_drop_zone('', 1, 1),
122 new qtype_ddimageortext_drop_zone('', 2, 1),
123 new qtype_ddimageortext_drop_zone('', 3, 1),
124 new qtype_ddimageortext_drop_zone('', 4, 1)
bfe79134 125 ));
a2bb148a 126 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
a2bb148a
TH
127
128 return $dd;
129 }
42865c84
TH
130
131 /**
132 * @return stdClass date to create a ddimageortext question.
133 */
134 public function get_ddimageortext_question_form_data_xsection() {
135 global $CFG, $USER;
136 $fromform = new stdClass();
137
138 $bgdraftitemid = 0;
139 file_prepare_draft_area($bgdraftitemid, null, null, null, null);
140 $fs = get_file_storage();
141 $filerecord = new stdClass();
142 $filerecord->contextid = context_user::instance($USER->id)->id;
143 $filerecord->component = 'user';
144 $filerecord->filearea = 'draft';
145 $filerecord->itemid = $bgdraftitemid;
146 $filerecord->filepath = '/';
147 $filerecord->filename = 'oceanfloorbase.jpg';
148 $fs->create_file_from_pathname($filerecord, $CFG->dirroot .
149 '/question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg');
150
151 $fromform->name = 'Geography cross-section';
152 $fromform->questiontext = array(
153 'text' => '<p>Identify the features in this cross-section by dragging the labels into the boxes.</p>
154 <p><em>Use the mouse to drag the boxed words into the empty boxes. Alternatively, use the tab key to select an empty box, then use the space key to cycle through the options.</em></p>',
155 'format' => FORMAT_HTML,
156 );
157 $fromform->defaultmark = 1;
158 $fromform->generalfeedback = array(
159 'text' => '<p>More information about the major features of the Earth\'s surface can be found in Block 3, Section 6.2.</p>',
160 'format' => FORMAT_HTML,
161 );
162 $fromform->bgimage = $bgdraftitemid;
163 $fromform->shuffleanswers = 0;
164 $fromform->drags = array(
165 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
166 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
167 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
168 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
169 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
170 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
171 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
172 array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
173 );
174 $fromform->dragitem = array(0, 0, 0, 0, 0, 0, 0, 0);
175 $fromform->draglabel =
176 array(
177 'island<br/>arc',
178 'mid-ocean<br/>ridge',
179 'abyssal<br/>plain',
180 'continental<br/>rise',
181 'ocean<br/>trench',
182 'continental<br/>slope',
183 'mountain<br/>belt',
184 'continental<br/>shelf',
185 );
186 $fromform->drops = array(
187 array('xleft' => '53', 'ytop' => '17', 'choice' => '7', 'droplabel' => ''),
188 array('xleft' => '172', 'ytop' => '2', 'choice' => '8', 'droplabel' => ''),
189 array('xleft' => '363', 'ytop' => '31', 'choice' => '5', 'droplabel' => ''),
190 array('xleft' => '440', 'ytop' => '13', 'choice' => '3', 'droplabel' => ''),
191 array('xleft' => '115', 'ytop' => '74', 'choice' => '6', 'droplabel' => ''),
192 array('xleft' => '210', 'ytop' => '94', 'choice' => '4', 'droplabel' => ''),
193 array('xleft' => '310', 'ytop' => '87', 'choice' => '1', 'droplabel' => ''),
194 array('xleft' => '479', 'ytop' => '84', 'choice' => '2', 'droplabel' => ''),
195 );
196
197 test_question_maker::set_standard_combined_feedback_form_data($fromform);
198
199 $fromform->penalty ='0.3333333';
200 $fromform->hint = array(
201 array(
202 'text' => '<p>Incorrect placements will be removed.</p>',
203 'format' => FORMAT_HTML,
204 ),
205 array(
206 'text' => '<ul>
207 <li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
208 <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
209 <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
210 <li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
211 <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
212 <li>A mountain belt is a long range of mountains.</li>
213 <li>An island arc is a chain of volcanic islands.</li>
214 <li>An oceanic trench is a deep trough in the ocean floor.</li>
215 </ul>',
216 'format' => FORMAT_HTML,
217 ),
218 array(
219 'text' => '<p>Incorrect placements will be removed.</p>',
220 'format' => FORMAT_HTML,
221 ),
222 array(
223 'text' => '<ul>
224 <li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
225 <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
226 <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
227 <li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
228 <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
229 <li>A mountain belt is a long range of mountains.</li>
230 <li>An island arc is a chain of volcanic islands.</li>
231 <li>An oceanic trench is a deep trough in the ocean floor.</li>
232 </ul>',
233 'format' => FORMAT_HTML,
234 ),
235 );
236 $fromform->hintclearwrong = array(1, 0, 1, 0);
237 $fromform->hintshownumcorrect = array(1, 1, 1, 1);
238
239 return $fromform;
240 }
a2bb148a 241}