|
| 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 | + * Tests for the quiz answer sheet report. |
| 19 | + * |
| 20 | + * @package quiz_answersheets |
| 21 | + * @copyright 2019 The Open University |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | + |
| 25 | +defined('MOODLE_INTERNAL') || die(); |
| 26 | + |
| 27 | +/** |
| 28 | + * Tests for the quiz answer sheet report. |
| 29 | + * |
| 30 | + * @package quiz_answersheets |
| 31 | + * @copyright 2019 The Open University |
| 32 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 33 | + */ |
| 34 | +class quiz_answersheets_report_testcase extends advanced_testcase { |
| 35 | + |
| 36 | + /** |
| 37 | + * Test get_question_instruction function |
| 38 | + * |
| 39 | + * @dataProvider get_question_instruction_cases |
| 40 | + * @param string $questiontype Question type name |
| 41 | + * @param string $expectedinstruction Expected instruction for question |
| 42 | + */ |
| 43 | + public function test_get_question_instruction(string $questiontype, string $expectedinstruction) { |
| 44 | + $this->resetAfterTest(); |
| 45 | + if (question_bank::is_qtype_installed($questiontype)) { |
| 46 | + $instruction = \quiz_answersheets\utils::get_question_instruction($questiontype); |
| 47 | + $this->assert_same_instruction($expectedinstruction, $instruction); |
| 48 | + } else { |
| 49 | + $this->markTestSkipped(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Test case for test_get_question_instruction |
| 55 | + * |
| 56 | + * @return array List of test cases |
| 57 | + */ |
| 58 | + public function get_question_instruction_cases() { |
| 59 | + return [ |
| 60 | + [ |
| 61 | + 'coderunner', |
| 62 | + 'Write your answer in the space provided' |
| 63 | + ], |
| 64 | + [ |
| 65 | + 'ddwtos', |
| 66 | + 'Write the letter of the corresponding answer (A, B, C, D, ...) in the space provided. |
| 67 | +After the item is the maximum number of times it can be used. e.g. (1) means that the item can be used once, (2) means twice etc. An asterisk (*) means that the items’ use is unlimited' |
| 68 | + ], |
| 69 | + [ |
| 70 | + 'ddmarker', |
| 71 | + 'Mark the points on the image and write the letter of corresponding answer (A, B, C, D, …) beside them. |
| 72 | +After the item is the maximum number of times it can be used. e.g. (1) means that the item can be used once, (2) means twice etc. An asterisk (*) means that the items’ use is unlimited' |
| 73 | + ], |
| 74 | + [ |
| 75 | + 'ddimageortext', |
| 76 | + 'Mark the points on the image and write the letter of corresponding answer (A, B, C, D, …) beside them. |
| 77 | +After the item is the maximum number of times it can be used. e.g. (1) means that the item can be used once, (2) means twice etc. An asterisk (*) means that the items’ use is unlimited' |
| 78 | + ], |
| 79 | + [ |
| 80 | + 'essay', |
| 81 | + 'Write your answer in the space provided' |
| 82 | + ], |
| 83 | + [ |
| 84 | + 'match', |
| 85 | + 'Write the letter of the corresponding answer (A, B, C, D, ...) in the space provided' |
| 86 | + ], |
| 87 | + [ |
| 88 | + 'multichoice', |
| 89 | + 'Select the correct answer' |
| 90 | + ], |
| 91 | + [ |
| 92 | + 'numerical', |
| 93 | + 'Write your answer (in numerical value) in the space provided' |
| 94 | + ], |
| 95 | + [ |
| 96 | + 'ordering', |
| 97 | + 'Write the correct order in the space provided' |
| 98 | + ], |
| 99 | + [ |
| 100 | + 'oumultiresponse', |
| 101 | + 'Select the correct answer(s)' |
| 102 | + ], |
| 103 | + [ |
| 104 | + 'pmatch', |
| 105 | + 'Write your answer in the space provided. Please keep it to a sentence or two' |
| 106 | + ], |
| 107 | + [ |
| 108 | + 'pmatchjme', |
| 109 | + 'Write your answer in the space provided' |
| 110 | + ], |
| 111 | + [ |
| 112 | + 'gapselect', |
| 113 | + 'Write the letter of the corresponding answer (A, B, C, D, ...) in the space provided' |
| 114 | + ], |
| 115 | + [ |
| 116 | + 'shortanswer', |
| 117 | + 'Write your answer in the space provided. Please keep it to a sentence or two' |
| 118 | + ], |
| 119 | + [ |
| 120 | + 'stack', |
| 121 | + 'Write your answer in the space provided' |
| 122 | + ], |
| 123 | + [ |
| 124 | + 'truefalse', |
| 125 | + 'Select the correct answer' |
| 126 | + ], |
| 127 | + [ |
| 128 | + 'varnumeric', |
| 129 | + 'Write your answer in the space provided' |
| 130 | + ], |
| 131 | + [ |
| 132 | + 'varnumericset', |
| 133 | + 'Write your answer in the space provided' |
| 134 | + ], |
| 135 | + [ |
| 136 | + 'varnumunit', |
| 137 | + 'Write your answer in the space provided' |
| 138 | + ], |
| 139 | + [ |
| 140 | + 'wordselect', |
| 141 | + 'Select the answer(s) by circling the key word(s)' |
| 142 | + ] |
| 143 | + ]; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Replace line break and assert the instruction |
| 148 | + * |
| 149 | + * @param string $expectedinstrction Expected instruction |
| 150 | + * @param string $instruction Actual instruction |
| 151 | + */ |
| 152 | + private function assert_same_instruction(string $expectedinstrction, string $instruction): void { |
| 153 | + $this->assertEquals(str_replace("\r\n", "\n", $expectedinstrction), str_replace("\r\n", "\n", $instruction)); |
| 154 | + } |
| 155 | +} |
0 commit comments