|
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(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php'); 00030 require_once(dirname(__FILE__) . '/../../../behaviour/deferredfeedback/behaviour.php'); 00031 require_once(dirname(__FILE__) . '/../question.php'); 00032 00033 00040 class qtype_missing_test extends UnitTestCase { 00041 00042 protected function get_unknown_questiondata() { 00043 $questiondata = new stdClass(); 00044 $questiondata->id = 0; 00045 $questiondata->category = 0; 00046 $questiondata->contextid = 0; 00047 $questiondata->parent = 0; 00048 $questiondata->name = 'Test'; 00049 $questiondata->questiontext = 'This is the question text.'; 00050 $questiondata->questiontextformat = FORMAT_HTML; 00051 $questiondata->generalfeedback = 'This is the general feedback.'; 00052 $questiondata->generalfeedbackformat = FORMAT_HTML; 00053 $questiondata->defaultmark = 1; 00054 $questiondata->penalty = 0.3333333; 00055 $questiondata->qtype = 'strange_unknown'; 00056 $questiondata->length = 1; 00057 $questiondata->stamp = make_unique_id_code(); 00058 $questiondata->version = make_unique_id_code(); 00059 $questiondata->hidden = 0; 00060 $questiondata->timecreated = 0; 00061 $questiondata->timemodified = 0; 00062 $questiondata->createdby = 0; 00063 $questiondata->modifiedby = 0; 00064 00065 return $questiondata; 00066 } 00067 00068 public function test_cannot_grade() { 00069 $q = new qtype_missingtype_question(); 00070 $this->expectException(); 00071 $q->grade_response(array()); 00072 } 00073 00074 public function test_load_qtype_strict() { 00075 $this->expectException(); 00076 $qtype = question_bank::get_qtype('strange_unknown'); 00077 } 00078 00079 public function test_load_qtype_lax() { 00080 $qtype = question_bank::get_qtype('strange_unknown', false); 00081 $this->assertIsA($qtype, 'qtype_missingtype'); 00082 } 00083 00084 public function test_make_question() { 00085 $questiondata = $this->get_unknown_questiondata(); 00086 $q = question_bank::make_question($questiondata); 00087 $this->assertIsA($q, 'qtype_missingtype_question'); 00088 $this->assertEqual($q->questiontext, html_writer::tag('div', 00089 get_string('missingqtypewarning', 'qtype_missingtype'), 00090 array('class' => 'warning missingqtypewarning')) . 00091 $questiondata->questiontext); 00092 } 00093 00094 public function test_render_missing() { 00095 $questiondata = $this->get_unknown_questiondata(); 00096 $q = question_bank::make_question($questiondata); 00097 $qa = new testable_question_attempt($q, 0); 00098 00099 $step = new question_attempt_step(array('answer' => 'frog')); 00100 $step->set_state(question_state::$todo); 00101 $qa->add_step($step); 00102 $qa->set_behaviour(new qbehaviour_deferredfeedback($qa, 'deferredfeedback')); 00103 00104 $output = $qa->render(new question_display_options(), '1'); 00105 00106 $this->assertPattern('/' . 00107 preg_quote($qa->get_question()->questiontext, '/') . '/', $output); 00108 $this->assertPattern('/' . 00109 preg_quote(get_string('missingqtypewarning', 'qtype_missingtype')) . '/', $output); 00110 $this->assert(new ContainsTagWithAttribute( 00111 'div', 'class', 'warning missingqtypewarning'), $output); 00112 } 00113 00114 public function test_get_question_summary() { 00115 $q = new qtype_missingtype_question(); 00116 $q->questiontext = '<b>Test</b>'; 00117 $this->assertEqual('TEST', $q->get_question_summary()); 00118 } 00119 00120 public function test_summarise_response() { 00121 $q = new qtype_missingtype_question(); 00122 $this->assertNull($q->summarise_response(array('a' => 'irrelevant'))); 00123 } 00124 00125 public function test_can_analyse_responses() { 00126 $qtype = new qtype_missingtype(); 00127 $this->assertFalse($qtype->can_analyse_responses()); 00128 } 00129 00130 public function test_get_random_guess_score() { 00131 $qtype = new qtype_missingtype(); 00132 $this->assertNull($qtype->get_random_guess_score(null)); 00133 } 00134 00135 public function test_get_possible_responses() { 00136 $qtype = new qtype_missingtype(); 00137 $this->assertEqual(array(), $qtype->get_possible_responses(null)); 00138 } 00139 }