| Línea 35... |
Línea 35... |
| 35 |
* @copyright 2019 the Open University
|
35 |
* @copyright 2019 the Open University
|
| 36 |
* @author 2021, Guillermo Gomez Arias <guillermogomez@catalyst-au.net>
|
36 |
* @author 2021, Guillermo Gomez Arias <guillermogomez@catalyst-au.net>
|
| 37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 38 |
* @coversDefaultClass \qbank_managecategories\question_category_object
|
38 |
* @coversDefaultClass \qbank_managecategories\question_category_object
|
| 39 |
*/
|
39 |
*/
|
| 40 |
class question_category_object_test extends \advanced_testcase {
|
40 |
final class question_category_object_test extends \advanced_testcase {
|
| Línea 41... |
Línea 41... |
| 41 |
|
41 |
|
| 42 |
/**
|
42 |
/**
|
| 43 |
* @var question_category_object used in the tests.
|
43 |
* @var question_category_object used in the tests.
|
| 44 |
*/
|
44 |
*/
|
| Línea 86... |
Línea 86... |
| 86 |
|
86 |
|
| 87 |
protected function setUp(): void {
|
87 |
protected function setUp(): void {
|
| 88 |
parent::setUp();
|
88 |
parent::setUp();
|
| 89 |
self::setAdminUser();
|
89 |
self::setAdminUser();
|
| 90 |
$this->resetAfterTest();
|
- |
|
| 91 |
$this->context = context_course::instance(SITEID);
|
- |
|
| 92 |
$contexts = new question_edit_contexts($this->context);
|
- |
|
| 93 |
$this->topcat = question_get_top_category($this->context->id, true);
|
- |
|
| 94 |
$this->qcobject = new question_category_object(null,
|
- |
|
| 95 |
new moodle_url('/question/bank/managecategories/category.php', ['courseid' => SITEID]),
|
- |
|
| 96 |
$contexts->having_one_edit_tab_cap('categories'), 0, null, 0,
|
- |
|
| Línea 97... |
Línea 90... |
| 97 |
$contexts->having_cap('moodle/question:add'));
|
90 |
$this->resetAfterTest();
|
| 98 |
|
91 |
|
| - |
|
92 |
// Set up tests in a quiz context.
|
| - |
|
93 |
$this->course = $this->getDataGenerator()->create_course();
|
| 99 |
// Set up tests in a quiz context.
|
94 |
$qbank = self::getDataGenerator()->create_module('qbank', ['course' => $this->course->id]);
|
| 100 |
$this->course = $this->getDataGenerator()->create_course();
|
95 |
$qbankcontext = context_module::instance($qbank->cmid);
|
| Línea -... |
Línea 96... |
| - |
|
96 |
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
| - |
|
97 |
$this->qcontexts = new question_edit_contexts(context_module::instance($this->quiz->cmid));
|
| - |
|
98 |
|
| - |
|
99 |
$contexts = new question_edit_contexts($qbankcontext);
|
| - |
|
100 |
$this->topcat = question_get_top_category($qbankcontext->id, true);
|
| - |
|
101 |
$this->resetDebugging();
|
| - |
|
102 |
$this->qcobject = new question_category_object(null,
|
| - |
|
103 |
new moodle_url('/question/bank/managecategories/category.php', ['cmid' => $qbank->cmid]),
|
| - |
|
104 |
$contexts->having_one_edit_tab_cap('categories'), 0, null, 0,
|
| - |
|
105 |
$contexts->having_cap('moodle/question:add')
|
| - |
|
106 |
);
|
| - |
|
107 |
$this->assertDebuggingCalled(
|
| - |
|
108 |
'Deprecation: qbank_managecategories\question_category_object::__construct has been deprecated since 4.5. ' .
|
| - |
|
109 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
110 |
'Use \qbank_managecategories\question_categories or \core_question\category_manager instead. ' .
|
| 101 |
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
111 |
'See MDL-72397 for more information.',
|
| 102 |
$this->qcontexts = new question_edit_contexts(context_module::instance($this->quiz->cmid));
|
112 |
);
|
| Línea -... |
Línea 113... |
| - |
|
113 |
|
| 103 |
|
114 |
$this->defaultcategoryobj = question_get_default_category($this->qcontexts->lowest()->id, true);
|
| 104 |
$this->defaultcategoryobj = question_make_default_categories([$this->qcontexts->lowest()]);
|
115 |
$this->defaultcategory = $this->defaultcategoryobj->id . ',' . $this->defaultcategoryobj->contextid;
|
| 105 |
$this->defaultcategory = $this->defaultcategoryobj->id . ',' . $this->defaultcategoryobj->contextid;
|
116 |
|
| 106 |
|
117 |
$this->resetDebugging();
|
| 107 |
$this->qcobjectquiz = new question_category_object(
|
118 |
$this->qcobjectquiz = new question_category_object(
|
| 108 |
1,
|
119 |
1,
|
| 109 |
new moodle_url('/mod/quiz/edit.php', ['cmid' => $this->quiz->cmid]),
|
120 |
new moodle_url('/mod/quiz/edit.php', ['cmid' => $this->quiz->cmid]),
|
| 110 |
$this->qcontexts->having_one_edit_tab_cap('categories'),
|
121 |
$this->qcontexts->having_one_edit_tab_cap('categories'),
|
| - |
|
122 |
$this->defaultcategoryobj->id,
|
| - |
|
123 |
$this->defaultcategory,
|
| - |
|
124 |
null,
|
| - |
|
125 |
$this->qcontexts->having_cap('moodle/question:add'));
|
| - |
|
126 |
$this->assertDebuggingCalled(
|
| 111 |
$this->defaultcategoryobj->id,
|
127 |
'Deprecation: qbank_managecategories\question_category_object::__construct has been deprecated since 4.5. ' .
|
| 112 |
$this->defaultcategory,
|
128 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| Línea 113... |
Línea 129... |
| 113 |
null,
|
129 |
'Use \qbank_managecategories\question_categories or \core_question\category_manager instead. ' .
|
| 114 |
$this->qcontexts->having_cap('moodle/question:add'));
|
130 |
'See MDL-72397 for more information.',
|
| 115 |
|
131 |
);
|
| 116 |
}
|
132 |
}
|
| 117 |
|
133 |
|
| 118 |
/**
|
134 |
/**
|
| 119 |
* Test creating a category.
|
135 |
* Test creating a category.
|
| Línea -... |
Línea 136... |
| - |
|
136 |
*
|
| 120 |
*
|
137 |
* @covers ::add_category
|
| 121 |
* @covers ::add_category
|
138 |
*/
|
| - |
|
139 |
public function test_add_category_no_idnumber(): void {
|
| - |
|
140 |
global $DB;
|
| - |
|
141 |
|
| - |
|
142 |
$this->resetDebugging();
|
| - |
|
143 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| 122 |
*/
|
144 |
'New category', '', true, FORMAT_HTML, ''); // No idnumber passed as '' to match form data.
|
| 123 |
public function test_add_category_no_idnumber(): void {
|
145 |
$this->assertDebuggingCalled(
|
| 124 |
global $DB;
|
146 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| 125 |
|
147 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| 126 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
148 |
'Use \core_question\category_manager::add_category instead. ' .
|
| Línea 137... |
Línea 159... |
| 137 |
* @covers ::add_category
|
159 |
* @covers ::add_category
|
| 138 |
*/
|
160 |
*/
|
| 139 |
public function test_add_category_set_idnumber_0(): void {
|
161 |
public function test_add_category_set_idnumber_0(): void {
|
| 140 |
global $DB;
|
162 |
global $DB;
|
| Línea -... |
Línea 163... |
| - |
|
163 |
|
| 141 |
|
164 |
$this->resetDebugging();
|
| 142 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
165 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| - |
|
166 |
'New category', '', true, FORMAT_HTML, '0');
|
| - |
|
167 |
$this->assertDebuggingCalled(
|
| - |
|
168 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
169 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
170 |
'Use \core_question\category_manager::add_category instead. ' .
|
| 143 |
'New category', '', true, FORMAT_HTML, '0');
|
171 |
'See MDL-72397 for more information.',
|
| 144 |
|
172 |
);
|
| 145 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
173 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
| 146 |
$this->assertSame('New category', $newcat->name);
|
174 |
$this->assertSame('New category', $newcat->name);
|
| 147 |
$this->assertSame('0', $newcat->idnumber);
|
175 |
$this->assertSame('0', $newcat->idnumber);
|
| Línea 154... |
Línea 182... |
| 154 |
* @covers ::add_category
|
182 |
* @covers ::add_category
|
| 155 |
*/
|
183 |
*/
|
| 156 |
public function test_add_category_try_to_set_duplicate_idnumber(): void {
|
184 |
public function test_add_category_try_to_set_duplicate_idnumber(): void {
|
| 157 |
global $DB;
|
185 |
global $DB;
|
| Línea -... |
Línea 186... |
| - |
|
186 |
|
| 158 |
|
187 |
$this->resetDebugging();
|
| 159 |
$this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
188 |
$this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| Línea 160... |
Línea 189... |
| 160 |
'Existing category', '', true, FORMAT_HTML, 'frog');
|
189 |
'Existing category', '', true, FORMAT_HTML, 'frog');
|
| 161 |
|
190 |
|
| - |
|
191 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| - |
|
192 |
'New category', '', true, FORMAT_HTML, 'frog');
|
| - |
|
193 |
$deprecationmessage =
|
| - |
|
194 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
195 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
196 |
'Use \core_question\category_manager::add_category instead. ' .
|
| 162 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
- |
|
| 163 |
'New category', '', true, FORMAT_HTML, 'frog');
|
197 |
'See MDL-72397 for more information.';
|
| 164 |
|
198 |
$this->assertdebuggingcalledcount(2, [$deprecationmessage, $deprecationmessage]);
|
| 165 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
199 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
| 166 |
$this->assertSame('New category', $newcat->name);
|
200 |
$this->assertSame('New category', $newcat->name);
|
| Línea 172... |
Línea 206... |
| 172 |
*
|
206 |
*
|
| 173 |
* @covers ::update_category
|
207 |
* @covers ::update_category
|
| 174 |
*/
|
208 |
*/
|
| 175 |
public function test_update_category(): void {
|
209 |
public function test_update_category(): void {
|
| 176 |
global $DB;
|
210 |
global $DB;
|
| 177 |
|
- |
|
| - |
|
211 |
$this->resetDebugging();
|
| 178 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
212 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| 179 |
'Old name', 'Description', true, FORMAT_HTML, 'frog');
|
213 |
'Old name', 'Description', true, FORMAT_HTML, 'frog');
|
| Línea 180... |
Línea 214... |
| 180 |
|
214 |
|
| 181 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
215 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
| - |
|
216 |
'New name', 'New description', FORMAT_HTML, '0', false);
|
| - |
|
217 |
$this->assertdebuggingcalledcount(
|
| - |
|
218 |
3,
|
| - |
|
219 |
[
|
| - |
|
220 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
221 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
222 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
223 |
'See MDL-72397 for more information.',
|
| - |
|
224 |
'Deprecation: qbank_managecategories\question_category_object::update_category has been deprecated since 4.5. ' .
|
| - |
|
225 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
226 |
'Use \core_question\category_manager::update_category instead. ' .
|
| - |
|
227 |
'See MDL-72397 for more information.',
|
| - |
|
228 |
'Deprecation: qbank_managecategories\helper::question_is_only_child_of_top_category_in_context ' .
|
| - |
|
229 |
'has been deprecated since 4.5. Moved to core namespace. ' .
|
| - |
|
230 |
'Use core_question\category_manager::is_only_child_of_top_category_in_context instead. ' .
|
| - |
|
231 |
'See MDL-72397 for more information.',
|
| - |
|
232 |
],
|
| Línea 182... |
Línea 233... |
| 182 |
'New name', 'New description', FORMAT_HTML, '0', false);
|
233 |
);
|
| 183 |
|
234 |
|
| 184 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
235 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
| 185 |
$this->assertSame('New name', $newcat->name);
|
236 |
$this->assertSame('New name', $newcat->name);
|
| Línea 192... |
Línea 243... |
| 192 |
* @covers ::update_category
|
243 |
* @covers ::update_category
|
| 193 |
*/
|
244 |
*/
|
| 194 |
public function test_update_category_removing_idnumber(): void {
|
245 |
public function test_update_category_removing_idnumber(): void {
|
| 195 |
global $DB;
|
246 |
global $DB;
|
| Línea -... |
Línea 247... |
| - |
|
247 |
|
| 196 |
|
248 |
$this->resetDebugging();
|
| 197 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
249 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| Línea 198... |
Línea 250... |
| 198 |
'Old name', 'Description', true, FORMAT_HTML, 'frog');
|
250 |
'Old name', 'Description', true, FORMAT_HTML, 'frog');
|
| 199 |
|
251 |
|
| - |
|
252 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
| - |
|
253 |
'New name', 'New description', FORMAT_HTML, '', false);
|
| - |
|
254 |
$this->assertdebuggingcalledcount(
|
| - |
|
255 |
3,
|
| - |
|
256 |
[
|
| - |
|
257 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
258 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
259 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
260 |
'See MDL-72397 for more information.',
|
| - |
|
261 |
'Deprecation: qbank_managecategories\question_category_object::update_category has been deprecated since 4.5. ' .
|
| - |
|
262 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
263 |
'Use \core_question\category_manager::update_category instead. ' .
|
| - |
|
264 |
'See MDL-72397 for more information.',
|
| - |
|
265 |
'Deprecation: qbank_managecategories\helper::question_is_only_child_of_top_category_in_context ' .
|
| - |
|
266 |
'has been deprecated since 4.5. Moved to core namespace. ' .
|
| - |
|
267 |
'Use core_question\category_manager::is_only_child_of_top_category_in_context instead. ' .
|
| 200 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
268 |
'See MDL-72397 for more information.',
|
| 201 |
'New name', 'New description', FORMAT_HTML, '', false);
|
269 |
],
|
| 202 |
|
270 |
);
|
| 203 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
271 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
| 204 |
$this->assertSame('New name', $newcat->name);
|
272 |
$this->assertSame('New name', $newcat->name);
|
| Línea 211... |
Línea 279... |
| 211 |
* @covers ::update_category
|
279 |
* @covers ::update_category
|
| 212 |
*/
|
280 |
*/
|
| 213 |
public function test_update_category_dont_change_idnumber(): void {
|
281 |
public function test_update_category_dont_change_idnumber(): void {
|
| 214 |
global $DB;
|
282 |
global $DB;
|
| Línea -... |
Línea 283... |
| - |
|
283 |
|
| 215 |
|
284 |
$this->resetDebugging();
|
| 216 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
285 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| Línea 217... |
Línea 286... |
| 217 |
'Old name', 'Description', true, FORMAT_HTML, 'frog');
|
286 |
'Old name', 'Description', true, FORMAT_HTML, 'frog');
|
| 218 |
|
287 |
|
| - |
|
288 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
| - |
|
289 |
'New name', 'New description', FORMAT_HTML, 'frog', false);
|
| - |
|
290 |
$this->assertdebuggingcalledcount(
|
| - |
|
291 |
3,
|
| - |
|
292 |
[
|
| - |
|
293 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
294 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
295 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
296 |
'See MDL-72397 for more information.',
|
| - |
|
297 |
'Deprecation: qbank_managecategories\question_category_object::update_category has been deprecated since 4.5. ' .
|
| - |
|
298 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
299 |
'Use \core_question\category_manager::update_category instead. ' .
|
| - |
|
300 |
'See MDL-72397 for more information.',
|
| - |
|
301 |
'Deprecation: qbank_managecategories\helper::question_is_only_child_of_top_category_in_context ' .
|
| - |
|
302 |
'has been deprecated since 4.5. Moved to core namespace. ' .
|
| - |
|
303 |
'Use core_question\category_manager::is_only_child_of_top_category_in_context instead. ' .
|
| 219 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
304 |
'See MDL-72397 for more information.',
|
| 220 |
'New name', 'New description', FORMAT_HTML, 'frog', false);
|
305 |
],
|
| 221 |
|
306 |
);
|
| 222 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
307 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
| 223 |
$this->assertSame('New name', $newcat->name);
|
308 |
$this->assertSame('New name', $newcat->name);
|
| Línea 231... |
Línea 316... |
| 231 |
* @covers ::update_category
|
316 |
* @covers ::update_category
|
| 232 |
*/
|
317 |
*/
|
| 233 |
public function test_update_category_try_to_set_duplicate_idnumber(): void {
|
318 |
public function test_update_category_try_to_set_duplicate_idnumber(): void {
|
| 234 |
global $DB;
|
319 |
global $DB;
|
| Línea -... |
Línea 320... |
| - |
|
320 |
|
| 235 |
|
321 |
$this->resetDebugging();
|
| 236 |
$this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
322 |
$this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| 237 |
'Existing category', '', true, FORMAT_HTML, 'toad');
|
323 |
'Existing category', '', true, FORMAT_HTML, 'toad');
|
| 238 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
324 |
$id = $this->qcobject->add_category($this->topcat->id . ',' . $this->topcat->contextid,
|
| Línea 239... |
Línea 325... |
| 239 |
'old name', '', true, FORMAT_HTML, 'frog');
|
325 |
'old name', '', true, FORMAT_HTML, 'frog');
|
| 240 |
|
326 |
|
| - |
|
327 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
| - |
|
328 |
'New name', '', FORMAT_HTML, 'toad', false);
|
| - |
|
329 |
$addmsg = 'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
330 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
331 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
332 |
'See MDL-72397 for more information.';
|
| - |
|
333 |
$this->assertdebuggingcalledcount(
|
| - |
|
334 |
4,
|
| - |
|
335 |
[
|
| - |
|
336 |
$addmsg,
|
| - |
|
337 |
$addmsg,
|
| - |
|
338 |
'Deprecation: qbank_managecategories\question_category_object::update_category has been deprecated since 4.5. ' .
|
| - |
|
339 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
340 |
'Use \core_question\category_manager::update_category instead. ' .
|
| - |
|
341 |
'See MDL-72397 for more information.',
|
| - |
|
342 |
'Deprecation: qbank_managecategories\helper::question_is_only_child_of_top_category_in_context ' .
|
| - |
|
343 |
'has been deprecated since 4.5. Moved to core namespace. ' .
|
| - |
|
344 |
'Use core_question\category_manager::is_only_child_of_top_category_in_context instead. ' .
|
| - |
|
345 |
'See MDL-72397 for more information.',
|
| Línea 241... |
Línea 346... |
| 241 |
$this->qcobject->update_category($id, $this->topcat->id . ',' . $this->topcat->contextid,
|
346 |
],
|
| 242 |
'New name', '', FORMAT_HTML, 'toad', false);
|
347 |
);
|
| 243 |
|
348 |
|
| 244 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
349 |
$newcat = $DB->get_record('question_categories', ['id' => $id], '*', MUST_EXIST);
|
| Línea 252... |
Línea 357... |
| 252 |
* @covers ::add_category
|
357 |
* @covers ::add_category
|
| 253 |
*/
|
358 |
*/
|
| 254 |
public function test_question_category_created(): void {
|
359 |
public function test_question_category_created(): void {
|
| 255 |
// Trigger and capture the event.
|
360 |
// Trigger and capture the event.
|
| 256 |
$sink = $this->redirectEvents();
|
361 |
$sink = $this->redirectEvents();
|
| - |
|
362 |
$this->resetDebugging();
|
| 257 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
363 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
| - |
|
364 |
$this->assertDebuggingCalled(
|
| - |
|
365 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
366 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
367 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
368 |
'See MDL-72397 for more information.',
|
| - |
|
369 |
);
|
| 258 |
$events = $sink->get_events();
|
370 |
$events = $sink->get_events();
|
| 259 |
$event = reset($events);
|
371 |
$event = reset($events);
|
| Línea 260... |
Línea 372... |
| 260 |
|
372 |
|
| 261 |
// Check that the event data is valid.
|
373 |
// Check that the event data is valid.
|
| Línea 269... |
Línea 381... |
| 269 |
*
|
381 |
*
|
| 270 |
* @covers ::delete_category
|
382 |
* @covers ::delete_category
|
| 271 |
*/
|
383 |
*/
|
| 272 |
public function test_question_category_deleted(): void {
|
384 |
public function test_question_category_deleted(): void {
|
| 273 |
// Create the category.
|
385 |
// Create the category.
|
| - |
|
386 |
$this->resetDebugging();
|
| 274 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
387 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
| Línea 275... |
Línea 388... |
| 275 |
|
388 |
|
| 276 |
// Trigger and capture the event.
|
389 |
// Trigger and capture the event.
|
| 277 |
$sink = $this->redirectEvents();
|
390 |
$sink = $this->redirectEvents();
|
| - |
|
391 |
$this->qcobjectquiz->delete_category($categoryid);
|
| - |
|
392 |
$this->assertdebuggingcalledcount(
|
| - |
|
393 |
3,
|
| - |
|
394 |
[
|
| - |
|
395 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
396 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
397 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
398 |
'See MDL-72397 for more information.',
|
| - |
|
399 |
'Deprecation: qbank_managecategories\question_category_object::delete_category has been deprecated since 4.5. ' .
|
| - |
|
400 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
401 |
'Use \core_question\category_manager::delete_category instead. ' .
|
| - |
|
402 |
'See MDL-72397 for more information.',
|
| - |
|
403 |
'Deprecation: qbank_managecategories\helper::question_can_delete_cat has been deprecated since 4.5. ' .
|
| - |
|
404 |
'Moved to core namespace. Use core_question\category_manager::can_delete_category instead. ' .
|
| - |
|
405 |
'See MDL-72397 for more information.',
|
| - |
|
406 |
],
|
| 278 |
$this->qcobjectquiz->delete_category($categoryid);
|
407 |
);
|
| 279 |
$events = $sink->get_events();
|
408 |
$events = $sink->get_events();
|
| Línea 280... |
Línea 409... |
| 280 |
$event = reset($events);
|
409 |
$event = reset($events);
|
| 281 |
|
410 |
|
| 282 |
// Check that the event data is valid.
|
411 |
// Check that the event data is valid.
|
| 283 |
$this->assertInstanceOf('\core\event\question_category_deleted', $event);
|
412 |
$this->assertInstanceOf('\core\event\question_category_deleted', $event);
|
| 284 |
$this->assertEquals(context_module::instance($this->quiz->cmid), $event->get_context());
|
- |
|
| 285 |
$this->assertEquals($categoryid, $event->objectid);
|
413 |
$this->assertEquals(context_module::instance($this->quiz->cmid), $event->get_context());
|
| Línea 286... |
Línea 414... |
| 286 |
$this->assertDebuggingNotCalled();
|
414 |
$this->assertEquals($categoryid, $event->objectid);
|
| 287 |
}
|
415 |
}
|
| 288 |
|
416 |
|
| 289 |
/**
|
417 |
/**
|
| 290 |
* Test the question category updated event.
|
418 |
* Test the question category updated event.
|
| 291 |
*
|
419 |
*
|
| - |
|
420 |
* @covers ::update_category
|
| 292 |
* @covers ::update_category
|
421 |
*/
|
| 293 |
*/
|
422 |
public function test_question_category_updated(): void {
|
| Línea 294... |
Línea 423... |
| 294 |
public function test_question_category_updated(): void {
|
423 |
$this->resetDebugging();
|
| 295 |
// Create the category.
|
424 |
// Create the category.
|
| 296 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
425 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
| - |
|
426 |
|
| - |
|
427 |
// Trigger and capture the event.
|
| - |
|
428 |
$sink = $this->redirectEvents();
|
| - |
|
429 |
$this->qcobjectquiz->update_category($categoryid, $this->defaultcategory, 'updatedcategory', '', FORMAT_HTML, '', false);
|
| - |
|
430 |
$this->assertdebuggingcalledcount(
|
| - |
|
431 |
3,
|
| - |
|
432 |
[
|
| - |
|
433 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| - |
|
434 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
435 |
'Use \core_question\category_manager::add_category instead. ' .
|
| - |
|
436 |
'See MDL-72397 for more information.',
|
| - |
|
437 |
'Deprecation: qbank_managecategories\question_category_object::update_category has been deprecated since 4.5. ' .
|
| - |
|
438 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
439 |
'Use \core_question\category_manager::update_category instead. ' .
|
| - |
|
440 |
'See MDL-72397 for more information.',
|
| - |
|
441 |
'Deprecation: qbank_managecategories\helper::question_is_only_child_of_top_category_in_context ' .
|
| - |
|
442 |
'has been deprecated since 4.5. Moved to core namespace. ' .
|
| 297 |
|
443 |
'Use core_question\category_manager::is_only_child_of_top_category_in_context instead. ' .
|
| 298 |
// Trigger and capture the event.
|
444 |
'See MDL-72397 for more information.',
|
| Línea 299... |
Línea 445... |
| 299 |
$sink = $this->redirectEvents();
|
445 |
],
|
| 300 |
$this->qcobjectquiz->update_category($categoryid, $this->defaultcategory, 'updatedcategory', '', FORMAT_HTML, '', false);
|
446 |
);
|
| 301 |
$events = $sink->get_events();
|
447 |
$events = $sink->get_events();
|
| 302 |
$event = reset($events);
|
448 |
$event = reset($events);
|
| 303 |
|
- |
|
| 304 |
// Check that the event data is valid.
|
449 |
|
| Línea 305... |
Línea 450... |
| 305 |
$this->assertInstanceOf('\core\event\question_category_updated', $event);
|
450 |
// Check that the event data is valid.
|
| 306 |
$this->assertEquals(context_module::instance($this->quiz->cmid), $event->get_context());
|
451 |
$this->assertInstanceOf('\core\event\question_category_updated', $event);
|
| 307 |
$this->assertEquals($categoryid, $event->objectid);
|
452 |
$this->assertEquals(context_module::instance($this->quiz->cmid), $event->get_context());
|
| 308 |
$this->assertDebuggingNotCalled();
|
453 |
$this->assertEquals($categoryid, $event->objectid);
|
| 309 |
}
|
454 |
}
|
| 310 |
|
455 |
|
| 311 |
/**
|
456 |
/**
|
| 312 |
* Test the question category viewed event.
|
457 |
* Test the question category viewed event.
|
| - |
|
458 |
* There is no external API for viewing the category, so the unit test will simply
|
| 313 |
* There is no external API for viewing the category, so the unit test will simply
|
459 |
* create and trigger the event and ensure data is returned as expected.
|
| 314 |
* create and trigger the event and ensure data is returned as expected.
|
460 |
*
|
| - |
|
461 |
* @covers ::add_category
|
| - |
|
462 |
*/
|
| - |
|
463 |
public function test_question_category_viewed(): void {
|
| - |
|
464 |
$this->resetDebugging();
|
| - |
|
465 |
// Create the category.
|
| 315 |
*
|
466 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
| 316 |
* @covers ::add_category
|
467 |
$this->assertDebuggingCalled(
|
| 317 |
*/
|
468 |
'Deprecation: qbank_managecategories\question_category_object::add_category has been deprecated since 4.5. ' .
|
| 318 |
public function test_question_category_viewed(): void {
|
469 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| 319 |
// Create the category.
|
470 |
'Use \core_question\category_manager::add_category instead. ' .
|
| 320 |
$categoryid = $this->qcobjectquiz->add_category($this->defaultcategory, 'newcategory', '', true);
|
471 |
'See MDL-72397 for more information.',
|
| Línea 333... |
Línea 484... |
| 333 |
|
484 |
|
| 334 |
// Check that the event data is valid.
|
485 |
// Check that the event data is valid.
|
| 335 |
$this->assertInstanceOf('\core\event\question_category_viewed', $event);
|
486 |
$this->assertInstanceOf('\core\event\question_category_viewed', $event);
|
| 336 |
$this->assertEquals(context_module::instance($this->quiz->cmid), $event->get_context());
|
487 |
$this->assertEquals(context_module::instance($this->quiz->cmid), $event->get_context());
|
| 337 |
$this->assertEquals($categoryid, $event->objectid);
|
- |
|
| 338 |
$this->assertDebuggingNotCalled();
|
- |
|
| 339 |
|
488 |
$this->assertEquals($categoryid, $event->objectid);
|
| Línea 340... |
Línea 489... |
| 340 |
}
|
489 |
}
|
| 341 |
|
490 |
|
| 342 |
/**
|
491 |
/**
|
| Línea 349... |
Línea 498... |
| 349 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
498 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
| 350 |
$categoryid = $this->defaultcategoryobj->id;
|
499 |
$categoryid = $this->defaultcategoryobj->id;
|
| Línea 351... |
Línea 500... |
| 351 |
|
500 |
|
| 352 |
// Short answer question is made of one question.
|
501 |
// Short answer question is made of one question.
|
| - |
|
502 |
$shortanswer = $generator->create_question('shortanswer', null, ['category' => $categoryid]);
|
| 353 |
$shortanswer = $generator->create_question('shortanswer', null, ['category' => $categoryid]);
|
503 |
$this->resetDebugging();
|
| - |
|
504 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
| - |
|
505 |
$this->assertDebuggingCalled(
|
| - |
|
506 |
'Deprecation: qbank_managecategories\question_category_object::get_real_question_ids_in_category ' .
|
| - |
|
507 |
'has been deprecated since 4.5. ' .
|
| - |
|
508 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
509 |
'Use \core_question\category_manager::get_real_question_ids_in_category instead. ' .
|
| - |
|
510 |
'See MDL-72397 for more information.',
|
| 354 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
511 |
);
|
| 355 |
$this->assertCount(1, $questionids);
|
512 |
$this->assertCount(1, $questionids);
|
| 356 |
$this->assertContains($shortanswer->id, $questionids);
|
513 |
$this->assertContains($shortanswer->id, $questionids);
|
| Línea 357... |
Línea 514... |
| 357 |
}
|
514 |
}
|
| Línea 370... |
Línea 527... |
| 370 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
527 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
| 371 |
$categoryid = $this->defaultcategoryobj->id;
|
528 |
$categoryid = $this->defaultcategoryobj->id;
|
| Línea 372... |
Línea 529... |
| 372 |
|
529 |
|
| 373 |
// Multi answer question is made of one parent and two child questions.
|
530 |
// Multi answer question is made of one parent and two child questions.
|
| - |
|
531 |
$multianswer = $generator->create_question('multianswer', null, ['category' => $categoryid]);
|
| 374 |
$multianswer = $generator->create_question('multianswer', null, ['category' => $categoryid]);
|
532 |
$this->resetDebugging();
|
| - |
|
533 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
| - |
|
534 |
$this->assertDebuggingCalled(
|
| - |
|
535 |
'Deprecation: qbank_managecategories\question_category_object::get_real_question_ids_in_category ' .
|
| - |
|
536 |
'has been deprecated since 4.5. ' .
|
| - |
|
537 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
538 |
'Use \core_question\category_manager::get_real_question_ids_in_category instead. ' .
|
| - |
|
539 |
'See MDL-72397 for more information.',
|
| 375 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
540 |
);
|
| 376 |
$this->assertCount(1, $questionids);
|
541 |
$this->assertCount(1, $questionids);
|
| 377 |
$this->assertContains($multianswer->id, $questionids);
|
542 |
$this->assertContains($multianswer->id, $questionids);
|
| 378 |
$this->assertEquals(3, $DB->count_records('question') - $countq);
|
543 |
$this->assertEquals(3, $DB->count_records('question') - $countq);
|
| 379 |
$this->assertEquals(3, $DB->count_records('question_bank_entries') - $countqbe);
|
544 |
$this->assertEquals(3, $DB->count_records('question_bank_entries') - $countqbe);
|
| Línea 396... |
Línea 561... |
| 396 |
|
561 |
|
| 397 |
// Create two versions of a multianswer question which will lead to
|
562 |
// Create two versions of a multianswer question which will lead to
|
| 398 |
// 2 parents and 4 child questions in the question bank.
|
563 |
// 2 parents and 4 child questions in the question bank.
|
| 399 |
$multianswer = $generator->create_question('multianswer', null, ['category' => $categoryid]);
|
564 |
$multianswer = $generator->create_question('multianswer', null, ['category' => $categoryid]);
|
| - |
|
565 |
$multianswernew = $generator->update_question($multianswer, null, ['name' => 'This is a new version']);
|
| 400 |
$multianswernew = $generator->update_question($multianswer, null, ['name' => 'This is a new version']);
|
566 |
$this->resetDebugging();
|
| - |
|
567 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
| - |
|
568 |
$this->assertDebuggingCalled(
|
| - |
|
569 |
'Deprecation: qbank_managecategories\question_category_object::get_real_question_ids_in_category ' .
|
| - |
|
570 |
'has been deprecated since 4.5. ' .
|
| - |
|
571 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
572 |
'Use \core_question\category_manager::get_real_question_ids_in_category instead. ' .
|
| - |
|
573 |
'See MDL-72397 for more information.',
|
| 401 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
574 |
);
|
| 402 |
$this->assertCount(2, $questionids);
|
575 |
$this->assertCount(2, $questionids);
|
| 403 |
$this->assertContains($multianswer->id, $questionids);
|
576 |
$this->assertContains($multianswer->id, $questionids);
|
| 404 |
$this->assertContains($multianswernew->id, $questionids);
|
577 |
$this->assertContains($multianswernew->id, $questionids);
|
| 405 |
$this->assertEquals(6, $DB->count_records('question') - $countq);
|
578 |
$this->assertEquals(6, $DB->count_records('question') - $countq);
|
| Línea 427... |
Línea 600... |
| 427 |
|
600 |
|
| 428 |
// Update category id for child questions to a category that doesn't exist.
|
601 |
// Update category id for child questions to a category that doesn't exist.
|
| 429 |
$DB->set_field_select('question_bank_entries', 'questioncategoryid',
|
602 |
$DB->set_field_select('question_bank_entries', 'questioncategoryid',
|
| Línea -... |
Línea 603... |
| - |
|
603 |
123456, 'id <> :id', ['id' => $qversion->questionbankentryid]);
|
| 430 |
123456, 'id <> :id', ['id' => $qversion->questionbankentryid]);
|
604 |
|
| - |
|
605 |
$this->resetDebugging();
|
| - |
|
606 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
| - |
|
607 |
$this->assertDebuggingCalled(
|
| - |
|
608 |
'Deprecation: qbank_managecategories\question_category_object::get_real_question_ids_in_category ' .
|
| - |
|
609 |
'has been deprecated since 4.5. ' .
|
| - |
|
610 |
'API properly divided between qbank_managecategories and core_question. ' .
|
| - |
|
611 |
'Use \core_question\category_manager::get_real_question_ids_in_category instead. ' .
|
| 431 |
|
612 |
'See MDL-72397 for more information.',
|
| 432 |
$questionids = $this->qcobject->get_real_question_ids_in_category($categoryid);
|
613 |
);
|
| 433 |
$this->assertCount(1, $questionids);
|
614 |
$this->assertCount(1, $questionids);
|
| 434 |
$this->assertContains($multianswer->id, $questionids);
|
615 |
$this->assertContains($multianswer->id, $questionids);
|
| 435 |
$this->assertEquals(3, $DB->count_records('question_bank_entries') - $countqbe);
|
616 |
$this->assertEquals(3, $DB->count_records('question_bank_entries') - $countqbe);
|