Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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() { 37 return array('fox', 'maths', 'oddgroups', 'missingchoiceno', 'infinite'); 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 101 return $fromform; 102 } 103 104 /** 105 * Similar to the 'fox' example above, but using different, non-continuous group numbers. 106 * 107 * @return stdClass data to create a ddwtos question. 108 */ 109 public function get_ddwtos_question_form_data_oddgroups() { 110 $fromform = new stdClass(); 111 112 $fromform->name = 'Drag-and-drop words with strange groups'; 113 $fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML); 114 $fromform->defaultmark = 1.0; 115 $fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML); 116 $fromform->choices = array( 117 array('answer' => 'quick', 'choicegroup' => '5'), 118 array('answer' => 'fox', 'choicegroup' => '7'), 119 array('answer' => 'lazy', 'choicegroup' => '3'), 120 array('answer' => 'slow', 'choicegroup' => '5'), 121 array('answer' => 'dog', 'choicegroup' => '7'), 122 array('answer' => 'assiduous', 'choicegroup' => '3'), 123 ); 124 test_question_maker::set_standard_combined_feedback_form_data($fromform); 125 $fromform->shownumcorrect = 0; 126 $fromform->penalty = 0.3333333; 127 128 return $fromform; 129 } 130 131 /** 132 * Get data required to save a drag-drop into text question where the author 133 * missed out one of the group numbers. 134 * 135 * @return stdClass data to create a ddwtos question. 136 */ 137 public function get_ddwtos_question_form_data_missingchoiceno() { 138 $fromform = new stdClass(); 139 140 $fromform->name = 'Drag-drop into text question with one index missing'; 141 $fromform->questiontext = ['text' => 'The [[1]] sat on the [[3]].', 'format' => FORMAT_HTML]; 142 $fromform->defaultmark = 1.0; 143 $fromform->generalfeedback = array('text' => 'The right answer is: "The cat sat on the mat."', 'format' => FORMAT_HTML); 144 $fromform->choices = array( 145 array('answer' => 'cat', 'choicegroup' => '1'), 146 array('answer' => '', 'choicegroup' => '1'), 147 array('answer' => 'mat', 'choicegroup' => '1'), 148 ); 149 test_question_maker::set_standard_combined_feedback_form_data($fromform); 150 $fromform->shownumcorrect = 0; 151 $fromform->penalty = 0.3333333; 152 153 return $fromform; 154 } 155 156 /** 157 * @return qtype_ddwtos_question 158 */ 159 public function make_ddwtos_question_maths() { 160 question_bank::load_question_definition_classes('ddwtos'); 161 $dd = new qtype_ddwtos_question(); 162 163 test_question_maker::initialise_a_question($dd); 164 165 $dd->name = 'Drag-and-drop words into sentences question'; 166 $dd->questiontext = 'Fill in the operators to make this equation work: ' . 167 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; 168 $dd->generalfeedback = 'This sentence uses each letter of the alphabet.'; 169 $dd->qtype = question_bank::get_qtype('ddwtos'); 170 171 $dd->shufflechoices = true; 172 173 test_question_maker::set_standard_combined_feedback_fields($dd); 174 175 $dd->choices = array( 176 1 => array( 177 1 => new qtype_ddwtos_choice('+', 1, true), 178 2 => new qtype_ddwtos_choice('-', 1, true), 179 3 => new qtype_ddwtos_choice('*', 1, true), 180 4 => new qtype_ddwtos_choice('/', 1, true), 181 )); 182 183 $dd->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1); 184 $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); 185 $dd->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3'); 186 187 return $dd; 188 } 189 190 /** 191 * This is a simple question with infinite mode. 192 * 193 * @return stdClass data to create a ddwtos question. 194 */ 195 public function get_ddwtos_question_form_data_infinite() { 196 $fromform = new stdClass(); 197 198 $fromform->name = 'Drag-and-drop infinite question'; 199 $fromform->questiontext = ['text' => 'One [[1]] Two [[2]] Three [[3]]', 'format' => FORMAT_HTML]; 200 $fromform->defaultmark = 1.0; 201 $fromform->generalfeedback = ['text' => 'This is general feedback', 'format' => FORMAT_HTML]; 202 $fromform->choices = [ 203 ['answer' => 'Option1', 'choicegroup' => '1', 'infinite' => true], 204 ['answer' => 'Option2', 'choicegroup' => '1', 'infinite' => true], 205 ['answer' => 'Option3', 'choicegroup' => '1', 'infinite' => true] 206 ]; 207 test_question_maker::set_standard_combined_feedback_form_data($fromform); 208 $fromform->shownumcorrect = 0; 209 $fromform->penalty = 0.3333333; 210 211 return $fromform; 212 } 213 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body