|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->dirroot . '/question/type/multianswer/question.php'); 00030 00031 00038 class qtype_multianswer_test_helper extends question_test_helper { 00039 public function get_test_questions() { 00040 return array('twosubq'); 00041 } 00042 00047 public function make_multianswer_question_twosubq() { 00048 question_bank::load_question_definition_classes('multianswer'); 00049 $q = new qtype_multianswer_question(); 00050 test_question_maker::initialise_a_question($q); 00051 $q->name = 'Simple multianswer'; 00052 $q->questiontext = 00053 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".'; 00054 $q->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' . 00055 '"The owl and the pussycat went to sea'; 00056 00057 // Shortanswer subquestion. 00058 question_bank::load_question_definition_classes('shortanswer'); 00059 $sa = new qtype_shortanswer_question(); 00060 test_question_maker::initialise_a_question($sa); 00061 $sa->name = 'Simple multianswer'; 00062 $sa->questiontext = '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}'; 00063 $sa->questiontextformat = FORMAT_HTML; 00064 $sa->generalfeedback = ''; 00065 $sa->generalfeedbackformat = FORMAT_HTML; 00066 $sa->usecase = true; 00067 $sa->answers = array( 00068 13 => new question_answer(13, 'Dog', 0.0, 'Wrong, silly!', FORMAT_HTML), 00069 14 => new question_answer(14, 'Owl', 1.0, 'Well done!', FORMAT_HTML), 00070 15 => new question_answer(15, '*', 0.0, 'Wrong answer', FORMAT_HTML), 00071 ); 00072 $sa->qtype = question_bank::get_qtype('shortanswer'); 00073 $sa->maxmark = 1; 00074 00075 // Multiple-choice subquestion. 00076 question_bank::load_question_definition_classes('multichoice'); 00077 $mc = new qtype_multichoice_single_question(); 00078 test_question_maker::initialise_a_question($mc); 00079 $mc->name = 'Simple multianswer'; 00080 $mc->questiontext = '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!' . 00081 '~Wiggly worm#Now you are just being rediculous!~=Pussy-cat#Well done!}'; 00082 $mc->questiontextformat = FORMAT_HTML; 00083 $mc->generalfeedback = ''; 00084 $mc->generalfeedbackformat = FORMAT_HTML; 00085 00086 $mc->shuffleanswers = 1; 00087 $mc->answernumbering = 'none'; 00088 $mc->layout = qtype_multichoice_base::LAYOUT_DROPDOWN; 00089 00090 $mc->answers = array( 00091 13 => new question_answer(13, 'Bow-wow', 0, 00092 'You seem to have a dog obsessions!', FORMAT_HTML), 00093 14 => new question_answer(14, 'Wiggly worm', 0, 00094 'Now you are just being rediculous!', FORMAT_HTML), 00095 15 => new question_answer(15, 'Pussy-cat', 1, 00096 'Well done!', FORMAT_HTML), 00097 ); 00098 $mc->qtype = question_bank::get_qtype('multichoice'); 00099 $mc->maxmark = 1; 00100 00101 $q->subquestions = array( 00102 1 => $sa, 00103 2 => $mc, 00104 ); 00105 00106 return $q; 00107 } 00108 00114 public function get_multianswer_question_data_twosubq() { 00115 $qdata = new stdClass(); 00116 test_question_maker::initialise_question_data($qdata); 00117 00118 $qdata->name = 'Simple multianswer'; 00119 $qdata->questiontext = 00120 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".'; 00121 $qdata->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' . 00122 '"The owl and the pussycat went to sea'; 00123 00124 $qdata->defaultmark = 2.0; 00125 $qdata->qtype = 'multianswer'; 00126 00127 $sa = new stdClass(); 00128 test_question_maker::initialise_question_data($sa); 00129 00130 $sa->name = 'Simple multianswer'; 00131 $sa->questiontext = '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}'; 00132 $sa->generalfeedback = ''; 00133 $sa->penalty = 0.0; 00134 $sa->qtype = 'shortanswer'; 00135 00136 $sa->options = new stdClass(); 00137 $sa->options->usecase = 0; 00138 00139 $sa->options->answers = array( 00140 13 => new question_answer(13, 'Dog', 0, 'Wrong, silly!', FORMAT_HTML), 00141 14 => new question_answer(14, 'Owl', 1, 'Well done!', FORMAT_HTML), 00142 15 => new question_answer(15, '*', 0, 'Wrong answer', FORMAT_HTML), 00143 ); 00144 00145 $mc = new stdClass(); 00146 test_question_maker::initialise_question_data($mc); 00147 00148 $mc->name = 'Simple multianswer'; 00149 $mc->questiontext = '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!~' . 00150 'Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!}'; 00151 $mc->generalfeedback = ''; 00152 $mc->penalty = 0.0; 00153 $mc->qtype = 'multichoice'; 00154 00155 $mc->options = new stdClass(); 00156 $mc->options->layout = 0; 00157 $mc->options->single = 1; 00158 $mc->options->shuffleanswers = 1; 00159 $mc->options->correctfeedback = ''; 00160 $mc->options->correctfeedbackformat = 1; 00161 $mc->options->partiallycorrectfeedback = ''; 00162 $mc->options->partiallycorrectfeedbackformat = 1; 00163 $mc->options->incorrectfeedback = ''; 00164 $mc->options->incorrectfeedbackformat = 1; 00165 $mc->options->answernumbering = ''; 00166 $mc->options->shownumcorrect = 0; 00167 00168 $mc->options->answers = array( 00169 23 => new question_answer(23, 'Bow-wow', 0, 00170 'You seem to have a dog obsessions!', FORMAT_HTML), 00171 24 => new question_answer(24, 'Wiggly worm', 0, 00172 'Now you are just being ridiculous!', FORMAT_HTML), 00173 25 => new question_answer(25, 'Pussy-cat', 1, 00174 'Well done!', FORMAT_HTML), 00175 ); 00176 00177 $qdata->options = new stdClass(); 00178 $qdata->options->questions = array( 00179 1 => $sa, 00180 2 => $mc, 00181 ); 00182 00183 $qdata->hints = array( 00184 new question_hint(0, 'Hint 1', FORMAT_HTML), 00185 new question_hint(0, 'Hint 2', FORMAT_HTML), 00186 ); 00187 00188 return $qdata; 00189 } 00190 00196 public function get_multianswer_question_form_data_twosubq() { 00197 $formdata = new stdClass(); 00198 test_question_maker::initialise_question_form_data($formdata); 00199 00200 $formdata->name = 'Simple multianswer'; 00201 $formdata->questiontext = 'Complete this opening line of verse: "The ' . 00202 '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer} ' . 00203 'and the {1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!' . 00204 '~Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!}' . 00205 ' went to sea".'; 00206 $formdata->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" ' . 00207 'by Lear: "The owl and the pussycat went to sea'; 00208 00209 $formdata->hint = array( 00210 0 => array('text' => 'Hint 1', 'format' => FORMAT_HTML, 'itemid' => 0), 00211 1 => array('text' => 'Hint 2', 'format' => FORMAT_HTML, 'itemid' => 0), 00212 ); 00213 00214 return $formdata; 00215 } 00216 }