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