2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Test helpers for the drag-and-drop onto image question type.
20 * @package qtype_ddimageortext
21 * @copyright 2010 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
30 * Test helper class for the drag-and-drop onto image question type.
32 * @copyright 2010 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class qtype_ddimageortext_test_helper extends question_test_helper {
36 public function get_test_questions() {
37 return array('fox', 'maths');
41 * @return qtype_ddimageortext_question
43 public function make_ddimageortext_question_fox() {
44 question_bank::load_question_definition_classes('ddimageortext');
45 $dd = new qtype_ddimageortext_question();
47 test_question_maker::initialise_a_question($dd);
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');
54 $dd->shufflechoices = true;
56 test_question_maker::set_standard_combined_feedback_fields($dd);
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', 1, 2),
62 new qtype_ddimageortext_drag_item('dog', 2, 2)
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)
72 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);
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();
83 $choicestructure[$choice->group][$choice->no] = $choice;
85 return $choicestructure;
88 protected function make_place_structure($places) {
89 $placestructure = array();
90 foreach ($places as $place) {
91 $placestructure[$place->no] = $place;
93 return $placestructure;
97 * @return qtype_ddimageortext_question
99 public function make_ddimageortext_question_maths() {
100 question_bank::load_question_definition_classes('ddimageortext');
101 $dd = new qtype_ddimageortext_question();
103 test_question_maker::initialise_a_question($dd);
105 $dd->name = 'Drag-and-drop onto image question';
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.';
109 $dd->qtype = question_bank::get_qtype('ddimageortext');
111 $dd->shufflechoices = true;
113 test_question_maker::set_standard_combined_feedback_fields($dd);
115 $dd->choices = $this->make_choice_structure(array(
116 new qtype_ddimageortext_drag_item('+', 1, 1),
117 new qtype_ddimageortext_drag_item('-', 2, 1)
120 $dd->places = $this->make_place_structure(array(
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)
126 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2);