See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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 * This file contains tests for the 'missing' question type. 19 * 20 * @package qtype 21 * @subpackage missingtype 22 * @copyright 2010 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once (__DIR__ . '/../../../engine/tests/helpers.php'); 31 require_once (__DIR__ . '/../../../behaviour/deferredfeedback/behaviour.php'); 32 require_once (__DIR__ . '/../question.php'); 33 require_once($CFG->dirroot . '/question/type/missingtype/questiontype.php'); 34 35 /** 36 * Unit tests for the 'missing' question type. 37 * 38 * @copyright 2010 The Open University 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class qtype_missing_test extends question_testcase { 42 43 protected function get_unknown_questiondata() { 44 $questiondata = new stdClass(); 45 $questiondata->id = 0; 46 $questiondata->category = 0; 47 $questiondata->contextid = 0; 48 $questiondata->parent = 0; 49 $questiondata->name = 'Test'; 50 $questiondata->questiontext = 'This is the question text.'; 51 $questiondata->questiontextformat = FORMAT_HTML; 52 $questiondata->generalfeedback = 'This is the general feedback.'; 53 $questiondata->generalfeedbackformat = FORMAT_HTML; 54 $questiondata->defaultmark = 1; 55 $questiondata->penalty = 0.3333333; 56 $questiondata->qtype = 'strange_unknown'; 57 $questiondata->length = 1; 58 $questiondata->stamp = make_unique_id_code(); 59 $questiondata->version = make_unique_id_code(); 60 $questiondata->hidden = 0; 61 $questiondata->idnumber = null; 62 $questiondata->timecreated = 0; 63 $questiondata->timemodified = 0; 64 $questiondata->createdby = 0; 65 $questiondata->modifiedby = 0; 66 67 return $questiondata; 68 } 69 70 /** 71 * @expectedException moodle_exception 72 */ 73 public function test_cannot_grade() { 74 $q = new qtype_missingtype_question(); 75 $q->grade_response(array()); 76 } 77 78 /** 79 * @expectedException moodle_exception 80 */ 81 public function test_load_qtype_strict() { 82 $qtype = question_bank::get_qtype('strange_unknown'); 83 } 84 85 public function test_load_qtype_lax() { 86 $qtype = question_bank::get_qtype('strange_unknown', false); 87 $this->assertInstanceOf('qtype_missingtype', $qtype); 88 } 89 90 public function test_make_question() { 91 $questiondata = $this->get_unknown_questiondata(); 92 $q = question_bank::make_question($questiondata); 93 $this->assertInstanceOf('qtype_missingtype_question', $q); 94 $this->assertEquals($q->questiontext, html_writer::tag('div', 95 get_string('missingqtypewarning', 'qtype_missingtype'), 96 array('class' => 'warning missingqtypewarning')) . 97 $questiondata->questiontext); 98 } 99 100 public function test_render_missing() { 101 $questiondata = $this->get_unknown_questiondata(); 102 $q = question_bank::make_question($questiondata); 103 $qa = new testable_question_attempt($q, 0); 104 105 $step = new question_attempt_step(array('answer' => 'frog')); 106 $step->set_state(question_state::$todo); 107 $qa->add_step($step); 108 $qa->set_behaviour(new qbehaviour_deferredfeedback($qa, 'deferredfeedback')); 109 110 $output = $qa->render(new question_display_options(), '1'); 111 112 $this->assertRegExp('/' . 113 preg_quote($qa->get_question(false)->questiontext, '/') . '/', $output); 114 $this->assertRegExp('/' . 115 preg_quote(get_string('missingqtypewarning', 'qtype_missingtype'), '/') . '/', $output); 116 $this->assert(new question_contains_tag_with_attribute( 117 'div', 'class', 'warning missingqtypewarning'), $output); 118 } 119 120 public function test_get_question_summary() { 121 $q = new qtype_missingtype_question(); 122 $q->questiontext = '<b>Test</b>'; 123 $this->assertEquals('TEST', $q->get_question_summary()); 124 } 125 126 public function test_summarise_response() { 127 $q = new qtype_missingtype_question(); 128 $this->assertNull($q->summarise_response(array('a' => 'irrelevant'))); 129 } 130 131 public function test_can_analyse_responses() { 132 $qtype = new qtype_missingtype(); 133 $this->assertFalse($qtype->can_analyse_responses()); 134 } 135 136 public function test_get_random_guess_score() { 137 $qtype = new qtype_missingtype(); 138 $this->assertNull($qtype->get_random_guess_score(null)); 139 } 140 141 public function test_get_possible_responses() { 142 $qtype = new qtype_missingtype(); 143 $this->assertEquals(array(), $qtype->get_possible_responses(null)); 144 } 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body