|
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/lib.php'); 00030 require_once(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php'); 00031 require_once(dirname(__FILE__) . '/../behaviour.php'); 00032 00033 00040 class qbehaviour_missing_test extends UnitTestCase { 00041 public function test_missing_cannot_start() { 00042 $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); 00043 $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); 00044 $this->expectException(); 00045 $behaviour->init_first_step(new question_attempt_step(array()), 1); 00046 } 00047 00048 public function test_missing_cannot_process() { 00049 $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); 00050 $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); 00051 $this->expectException(); 00052 $behaviour->process_action(new question_attempt_pending_step(array())); 00053 } 00054 00055 public function test_missing_cannot_get_min_grade() { 00056 $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); 00057 $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); 00058 $this->expectException(); 00059 $behaviour->get_min_fraction(); 00060 } 00061 00062 public function test_render_missing() { 00063 $records = new test_recordset(array( 00064 array('questionattemptid', 'contextid', 'questionusageid', 'slot', 00065 'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'flagged', 00066 'questionsummary', 'rightanswer', 'responsesummary', 00067 'timemodified', 'attemptstepid', 'sequencenumber', 'state', 'fraction', 00068 'timecreated', 'userid', 'name', 'value'), 00069 array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 00070 1256233790, 1, 0, 'todo', null, 1256233700, 1, '_order', '1,2,3'), 00071 array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 00072 1256233790, 2, 1, 'complete', 0.50, 1256233705, 1, '-submit', '1'), 00073 array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0000000, 0.0000000, 0, '', '', '', 00074 1256233790, 2, 1, 'complete', 0.50, 1256233705, 1, 'choice0', '1'), 00075 )); 00076 00077 $question = test_question_maker::make_question('truefalse', 'true'); 00078 $question->id = -1; 00079 00080 question_bank::start_unit_test(); 00081 question_bank::load_test_question_data($question); 00082 $qa = question_attempt::load_from_records($records, 1, 00083 new question_usage_null_observer(), 'deferredfeedback'); 00084 question_bank::end_unit_test(); 00085 00086 $this->assertEqual(2, $qa->get_num_steps()); 00087 00088 $step = $qa->get_step(0); 00089 $this->assertEqual(question_state::$todo, $step->get_state()); 00090 $this->assertNull($step->get_fraction()); 00091 $this->assertEqual(1256233700, $step->get_timecreated()); 00092 $this->assertEqual(1, $step->get_user_id()); 00093 $this->assertEqual(array('_order' => '1,2,3'), $step->get_all_data()); 00094 00095 $step = $qa->get_step(1); 00096 $this->assertEqual(question_state::$complete, $step->get_state()); 00097 $this->assertEqual(0.5, $step->get_fraction()); 00098 $this->assertEqual(1256233705, $step->get_timecreated()); 00099 $this->assertEqual(1, $step->get_user_id()); 00100 $this->assertEqual(array('-submit' => '1', 'choice0' => '1'), $step->get_all_data()); 00101 00102 $output = $qa->render(new question_display_options(), '1'); 00103 $this->assertPattern('/' . preg_quote($qa->get_question()->questiontext) . '/', $output); 00104 $this->assertPattern('/' . preg_quote( 00105 get_string('questionusedunknownmodel', 'qbehaviour_missing')) . '/', $output); 00106 $this->assert(new ContainsTagWithAttribute('div', 'class', 'warning'), $output); 00107 } 00108 }