Línea 19... |
Línea 19... |
19 |
* @package qformat_xml
|
19 |
* @package qformat_xml
|
20 |
* @copyright 2014 Nikita Nikitsky, Volgograd State Technical University
|
20 |
* @copyright 2014 Nikita Nikitsky, Volgograd State Technical University
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
22 |
*/
|
22 |
*/
|
Línea 23... |
Línea -... |
23 |
|
- |
|
Línea 24... |
Línea 23... |
24 |
use core_question\local\bank\question_edit_contexts;
|
23 |
|
25 |
|
24 |
|
26 |
defined('MOODLE_INTERNAL') || die();
|
25 |
defined('MOODLE_INTERNAL') || die();
|
27 |
global $CFG;
|
26 |
global $CFG;
|
Línea 34... |
Línea 33... |
34 |
/**
|
33 |
/**
|
35 |
* Unit tests for the XML question format import and export.
|
34 |
* Unit tests for the XML question format import and export.
|
36 |
*
|
35 |
*
|
37 |
* @copyright 2014 Nikita Nikitsky, Volgograd State Technical University
|
36 |
* @copyright 2014 Nikita Nikitsky, Volgograd State Technical University
|
38 |
* @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 |
* @covers \qformat_xml
|
39 |
*/
|
39 |
*/
|
40 |
class qformat_xml_import_export_test extends advanced_testcase {
|
40 |
final class qformat_xml_import_export_test extends advanced_testcase {
|
- |
|
41 |
/** @var stdClass mod_qbank instance */
|
- |
|
42 |
private stdClass $qbank;
|
- |
|
43 |
|
41 |
/**
|
44 |
/**
|
42 |
* Create object qformat_xml for test.
|
45 |
* Create object qformat_xml for test.
|
43 |
* @param string $filename with name for testing file.
|
46 |
* @param string $filename with name for testing file.
|
44 |
* @param stdClass $course
|
- |
|
45 |
* @return qformat_xml XML question format object.
|
47 |
* @return qformat_xml XML question format object.
|
46 |
*/
|
48 |
*/
|
47 |
public function create_qformat($filename, $course) {
|
49 |
public function create_qformat($filename) {
|
- |
|
50 |
$course = self::getDataGenerator()->create_course();
|
- |
|
51 |
$qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
- |
|
52 |
|
48 |
$qformat = new qformat_xml();
|
53 |
$qformat = new qformat_xml();
|
49 |
$qformat->setContexts((new question_edit_contexts(context_course::instance($course->id)))->all());
|
54 |
$qformat->setContexts([context_module::instance($qbank->cmid)]);
|
50 |
$qformat->setCourse($course);
|
55 |
$qformat->setCourse($course);
|
51 |
$qformat->setFilename(__DIR__ . '/fixtures/' . $filename);
|
56 |
$qformat->setFilename(__DIR__ . '/fixtures/' . $filename);
|
52 |
$qformat->setRealfilename($filename);
|
57 |
$qformat->setRealfilename($filename);
|
53 |
$qformat->setMatchgrades('error');
|
58 |
$qformat->setMatchgrades('error');
|
54 |
$qformat->setCatfromfile(1);
|
59 |
$qformat->setCatfromfile(1);
|
Línea 56... |
Línea 61... |
56 |
$qformat->setStoponerror(1);
|
61 |
$qformat->setStoponerror(1);
|
57 |
$qformat->setCattofile(1);
|
62 |
$qformat->setCattofile(1);
|
58 |
$qformat->setContexttofile(1);
|
63 |
$qformat->setContexttofile(1);
|
59 |
$qformat->set_display_progress(false);
|
64 |
$qformat->set_display_progress(false);
|
Línea -... |
Línea 65... |
- |
|
65 |
|
- |
|
66 |
$this->qbank = $qbank;
|
60 |
|
67 |
|
61 |
return $qformat;
|
68 |
return $qformat;
|
Línea 62... |
Línea 69... |
62 |
}
|
69 |
}
|
63 |
|
70 |
|
Línea 83... |
Línea 90... |
83 |
|
90 |
|
84 |
// Replace all numbers in question id comments with 0.
|
91 |
// Replace all numbers in question id comments with 0.
|
Línea 85... |
Línea 92... |
85 |
$xml = preg_replace('~(?<=<!-- question: )([0-9]+)(?= -->)~', '0', $xml);
|
92 |
$xml = preg_replace('~(?<=<!-- question: )([0-9]+)(?= -->)~', '0', $xml);
|
86 |
|
93 |
|
87 |
// Deal with how different databases output numbers. Only match when only thing in a tag.
|
94 |
// Deal with how different databases output numbers. Only match when only thing in a tag.
|
88 |
$xml = preg_replace("~>.0000000<~", '>0<', $xml); // How Oracle outputs 0.0000000.
|
95 |
$xml = preg_replace("~>.0000000<~", '>0<', $xml); // Needed by MS SQL Server database.
|
Línea 89... |
Línea 96... |
89 |
$xml = preg_replace("~(\.(:?[0-9]*[1-9])?)0*<~", '$1<', $xml); // Other cases of trailing 0s
|
96 |
$xml = preg_replace("~(\.(:?[0-9]*[1-9])?)0*<~", '$1<', $xml); // Other cases of trailing 0s
|
90 |
$xml = preg_replace("~([0-9]).<~", '$1<', $xml); // Stray . in 1. after last step.
|
97 |
$xml = preg_replace("~([0-9]).<~", '$1<', $xml); // Stray . in 1. after last step.
|
Línea 147... |
Línea 154... |
147 |
*/
|
154 |
*/
|
148 |
public function test_import_category(): void {
|
155 |
public function test_import_category(): void {
|
149 |
$this->resetAfterTest();
|
156 |
$this->resetAfterTest();
|
150 |
$course = $this->getDataGenerator()->create_course();
|
157 |
$course = $this->getDataGenerator()->create_course();
|
151 |
$this->setAdminUser();
|
158 |
$this->setAdminUser();
|
152 |
$qformat = $this->create_qformat('category_with_description.xml', $course);
|
159 |
$qformat = $this->create_qformat('category_with_description.xml');
|
153 |
$imported = $qformat->importprocess();
|
160 |
$imported = $qformat->importprocess();
|
154 |
$this->assertTrue($imported);
|
161 |
$this->assertTrue($imported);
|
155 |
$this->assert_category_imported('Alpha',
|
162 |
$this->assert_category_imported('Alpha',
|
156 |
'This is Alpha category for test', FORMAT_MOODLE, 'alpha-idnumber');
|
163 |
'This is Alpha category for test', FORMAT_MOODLE, 'alpha-idnumber');
|
157 |
$this->assert_category_has_parent('Alpha', 'top');
|
164 |
$this->assert_category_has_parent('Alpha', 'top');
|
158 |
}
|
165 |
}
|
Línea 159... |
Línea 166... |
159 |
|
166 |
|
- |
|
167 |
/**
|
- |
|
168 |
* Check importing categories that were in a now deprecated context.
|
- |
|
169 |
*
|
- |
|
170 |
* @return void
|
- |
|
171 |
* @covers \qformat_default::importprocess()
|
- |
|
172 |
*/
|
- |
|
173 |
public function test_deprecated_category_import(): void {
|
- |
|
174 |
$this->resetAfterTest();
|
- |
|
175 |
self::setAdminUser();
|
- |
|
176 |
|
- |
|
177 |
$qformat = $this->create_qformat('deprecated_category.xml');
|
- |
|
178 |
$cat = question_get_default_category($qformat->contexts[0]->id, true);
|
- |
|
179 |
$qformat->setCategory($cat);
|
- |
|
180 |
$imported = $qformat->importprocess();
|
- |
|
181 |
$this->assertTrue($imported);
|
- |
|
182 |
$this->assert_category_imported('Alpha', 'This is Alpha category for test', FORMAT_MOODLE, 'alpha-idnumber');
|
- |
|
183 |
$this->assert_category_has_parent('Alpha', 'top');
|
- |
|
184 |
}
|
- |
|
185 |
|
160 |
/**
|
186 |
/**
|
161 |
* Check importing nested categories.
|
187 |
* Check importing nested categories.
|
162 |
*/
|
188 |
*/
|
163 |
public function test_import_nested_categories(): void {
|
189 |
public function test_import_nested_categories(): void {
|
164 |
$this->resetAfterTest();
|
- |
|
165 |
$course = $this->getDataGenerator()->create_course();
|
190 |
$this->resetAfterTest();
|
166 |
$this->setAdminUser();
|
191 |
$this->setAdminUser();
|
167 |
$qformat = $this->create_qformat('nested_categories.xml', $course);
|
192 |
$qformat = $this->create_qformat('nested_categories.xml');
|
168 |
$imported = $qformat->importprocess();
|
193 |
$imported = $qformat->importprocess();
|
169 |
$this->assertTrue($imported);
|
194 |
$this->assertTrue($imported);
|
170 |
$this->assert_category_imported('Delta', 'This is Delta category for test', FORMAT_PLAIN);
|
195 |
$this->assert_category_imported('Delta', 'This is Delta category for test', FORMAT_PLAIN);
|
171 |
$this->assert_category_imported('Epsilon', 'This is Epsilon category for test', FORMAT_MARKDOWN);
|
196 |
$this->assert_category_imported('Epsilon', 'This is Epsilon category for test', FORMAT_MARKDOWN);
|
Línea 178... |
Línea 203... |
178 |
/**
|
203 |
/**
|
179 |
* Check importing nested categories contain the right questions.
|
204 |
* Check importing nested categories contain the right questions.
|
180 |
*/
|
205 |
*/
|
181 |
public function test_import_nested_categories_with_questions(): void {
|
206 |
public function test_import_nested_categories_with_questions(): void {
|
182 |
$this->resetAfterTest();
|
207 |
$this->resetAfterTest();
|
183 |
$course = $this->getDataGenerator()->create_course();
|
- |
|
184 |
$this->setAdminUser();
|
208 |
$this->setAdminUser();
|
185 |
$qformat = $this->create_qformat('nested_categories_with_questions.xml', $course);
|
209 |
$qformat = $this->create_qformat('nested_categories_with_questions.xml');
|
186 |
$imported = $qformat->importprocess();
|
210 |
$imported = $qformat->importprocess();
|
187 |
$this->assertTrue($imported);
|
211 |
$this->assertTrue($imported);
|
188 |
$this->assert_category_imported('Iota', 'This is Iota category for test', FORMAT_PLAIN);
|
212 |
$this->assert_category_imported('Iota', 'This is Iota category for test', FORMAT_PLAIN);
|
189 |
$this->assert_category_imported('Kappa', 'This is Kappa category for test', FORMAT_MARKDOWN);
|
213 |
$this->assert_category_imported('Kappa', 'This is Kappa category for test', FORMAT_MARKDOWN);
|
190 |
$this->assert_category_imported('Lambda', 'This is Lambda category for test', FORMAT_MOODLE);
|
214 |
$this->assert_category_imported('Lambda', 'This is Lambda category for test', FORMAT_MOODLE);
|
Línea 202... |
Línea 226... |
202 |
/**
|
226 |
/**
|
203 |
* Check import of an old file (without format), for backward compatability.
|
227 |
* Check import of an old file (without format), for backward compatability.
|
204 |
*/
|
228 |
*/
|
205 |
public function test_import_old_format(): void {
|
229 |
public function test_import_old_format(): void {
|
206 |
$this->resetAfterTest();
|
230 |
$this->resetAfterTest();
|
207 |
$course = $this->getDataGenerator()->create_course();
|
- |
|
208 |
$this->setAdminUser();
|
231 |
$this->setAdminUser();
|
209 |
$qformat = $this->create_qformat('old_format_file.xml', $course);
|
232 |
$qformat = $this->create_qformat('old_format_file.xml');
|
210 |
$imported = $qformat->importprocess();
|
233 |
$imported = $qformat->importprocess();
|
211 |
$this->assertTrue($imported);
|
234 |
$this->assertTrue($imported);
|
212 |
$this->assert_category_imported('Pi', '', FORMAT_MOODLE);
|
235 |
$this->assert_category_imported('Pi', '', FORMAT_MOODLE);
|
213 |
$this->assert_category_imported('Rho', '', FORMAT_MOODLE);
|
236 |
$this->assert_category_imported('Rho', '', FORMAT_MOODLE);
|
214 |
$this->assert_question_in_category('Pi Question', 'Pi');
|
237 |
$this->assert_question_in_category('Pi Question', 'Pi');
|
Línea 220... |
Línea 243... |
220 |
/**
|
243 |
/**
|
221 |
* Check the import of an xml file where the child category exists before the parent category.
|
244 |
* Check the import of an xml file where the child category exists before the parent category.
|
222 |
*/
|
245 |
*/
|
223 |
public function test_import_categories_in_reverse_order(): void {
|
246 |
public function test_import_categories_in_reverse_order(): void {
|
224 |
$this->resetAfterTest();
|
247 |
$this->resetAfterTest();
|
225 |
$course = $this->getDataGenerator()->create_course();
|
- |
|
226 |
$this->setAdminUser();
|
248 |
$this->setAdminUser();
|
227 |
$qformat = $this->create_qformat('categories_reverse_order.xml', $course);
|
249 |
$qformat = $this->create_qformat('categories_reverse_order.xml');
|
228 |
$imported = $qformat->importprocess();
|
250 |
$imported = $qformat->importprocess();
|
229 |
$this->assertTrue($imported);
|
251 |
$this->assertTrue($imported);
|
230 |
$this->assert_category_imported('Sigma', 'This is Sigma category for test', FORMAT_HTML);
|
252 |
$this->assert_category_imported('Sigma', 'This is Sigma category for test', FORMAT_HTML);
|
231 |
$this->assert_category_imported('Tau', 'This is Tau category for test', FORMAT_HTML);
|
253 |
$this->assert_category_imported('Tau', 'This is Tau category for test', FORMAT_HTML);
|
232 |
$this->assert_question_in_category('Sigma Question', 'Sigma');
|
254 |
$this->assert_question_in_category('Sigma Question', 'Sigma');
|
Línea 242... |
Línea 264... |
242 |
*/
|
264 |
*/
|
243 |
public function test_import_invalid_grades(): void {
|
265 |
public function test_import_invalid_grades(): void {
|
244 |
global $OUTPUT;
|
266 |
global $OUTPUT;
|
Línea 245... |
Línea 267... |
245 |
|
267 |
|
246 |
$this->resetAfterTest(true);
|
- |
|
247 |
$course = $this->getDataGenerator()->create_course();
|
268 |
$this->resetAfterTest(true);
|
248 |
$this->setAdminUser();
|
269 |
$this->setAdminUser();
|
Línea 249... |
Línea 270... |
249 |
$qformat = $this->create_qformat('error_invalid_grades.xml', $course);
|
270 |
$qformat = $this->create_qformat('error_invalid_grades.xml');
|
250 |
|
271 |
|
251 |
ob_start();
|
272 |
ob_start();
|
Línea 270... |
Línea 291... |
270 |
$this->resetAfterTest();
|
291 |
$this->resetAfterTest();
|
271 |
$this->setAdminUser();
|
292 |
$this->setAdminUser();
|
272 |
// Note while this loads $qformat with all the 'right' data from the xml file,
|
293 |
// Note while this loads $qformat with all the 'right' data from the xml file,
|
273 |
// the call to setCategory, followed by exportprocess will actually only export data
|
294 |
// the call to setCategory, followed by exportprocess will actually only export data
|
274 |
// from the database (created by the generator).
|
295 |
// from the database (created by the generator).
|
275 |
$qformat = $this->create_qformat('export_category.xml', $SITE);
|
296 |
$qformat = $this->create_qformat('export_category.xml');
|
Línea 276... |
Línea 297... |
276 |
|
297 |
|
277 |
$category = $generator->create_question_category([
|
298 |
$category = $generator->create_question_category([
|
278 |
'name' => 'Alpha',
|
299 |
'name' => 'Alpha',
|
279 |
'contextid' => context_course::instance($SITE->id)->id,
|
300 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
280 |
'info' => 'This is Alpha category for test',
|
301 |
'info' => 'This is Alpha category for test',
|
281 |
'infoformat' => '0',
|
302 |
'infoformat' => '0',
|
282 |
'idnumber' => 'alpha-idnumber',
|
303 |
'idnumber' => 'alpha-idnumber',
|
283 |
'stamp' => make_unique_id_code(),
|
304 |
'stamp' => make_unique_id_code(),
|
Línea 292... |
Línea 313... |
292 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
313 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
293 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
314 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
294 |
'penalty' => '1']);
|
315 |
'penalty' => '1']);
|
295 |
$qformat->setCategory($category);
|
316 |
$qformat->setCategory($category);
|
Línea 296... |
Línea 317... |
296 |
|
317 |
|
297 |
$expectedxml = file_get_contents(__DIR__ . '/fixtures/export_category.xml');
|
318 |
$expectedxml = file_get_contents(self::get_fixture_path('qformat_xml', 'export_category.xml'));
|
298 |
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
|
319 |
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
|
Línea 299... |
Línea 320... |
299 |
}
|
320 |
}
|
300 |
|
321 |
|
Línea 305... |
Línea 326... |
305 |
global $SITE;
|
326 |
global $SITE;
|
Línea 306... |
Línea 327... |
306 |
|
327 |
|
307 |
$this->resetAfterTest();
|
328 |
$this->resetAfterTest();
|
308 |
$this->setAdminUser();
|
329 |
$this->setAdminUser();
|
309 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
330 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
Línea 310... |
Línea 331... |
310 |
$qformat = $this->create_qformat('nested_categories.zml', $SITE);
|
331 |
$qformat = $this->create_qformat('nested_categories.xml');
|
311 |
|
332 |
|
312 |
$categorydelta = $generator->create_question_category([
|
333 |
$categorydelta = $generator->create_question_category([
|
313 |
'name' => 'Delta',
|
334 |
'name' => 'Delta',
|
314 |
'contextid' => context_course::instance($SITE->id)->id,
|
335 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
315 |
'info' => 'This is Delta category for test',
|
336 |
'info' => 'This is Delta category for test',
|
316 |
'infoformat' => '2',
|
337 |
'infoformat' => '2',
|
317 |
'stamp' => make_unique_id_code(),
|
338 |
'stamp' => make_unique_id_code(),
|
318 |
'parent' => '0',
|
339 |
'parent' => '0',
|
319 |
'sortorder' => '999']);
|
340 |
'sortorder' => '999']);
|
320 |
$categoryepsilon = $generator->create_question_category([
|
341 |
$categoryepsilon = $generator->create_question_category([
|
321 |
'name' => 'Epsilon',
|
342 |
'name' => 'Epsilon',
|
322 |
'contextid' => context_course::instance($SITE->id)->id,
|
343 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
323 |
'info' => 'This is Epsilon category for test',
|
344 |
'info' => 'This is Epsilon category for test',
|
324 |
'infoformat' => '4',
|
345 |
'infoformat' => '4',
|
325 |
'stamp' => make_unique_id_code(),
|
346 |
'stamp' => make_unique_id_code(),
|
326 |
'parent' => $categorydelta->id,
|
347 |
'parent' => $categorydelta->id,
|
327 |
'sortorder' => '999']);
|
348 |
'sortorder' => '999']);
|
328 |
$categoryzeta = $generator->create_question_category([
|
349 |
$categoryzeta = $generator->create_question_category([
|
329 |
'name' => 'Zeta',
|
350 |
'name' => 'Zeta',
|
330 |
'contextid' => context_course::instance($SITE->id)->id,
|
351 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
331 |
'info' => 'This is Zeta category for test',
|
352 |
'info' => 'This is Zeta category for test',
|
332 |
'infoformat' => '0',
|
353 |
'infoformat' => '0',
|
333 |
'stamp' => make_unique_id_code(),
|
354 |
'stamp' => make_unique_id_code(),
|
Línea 359... |
Línea 380... |
359 |
global $SITE;
|
380 |
global $SITE;
|
Línea 360... |
Línea 381... |
360 |
|
381 |
|
361 |
$this->resetAfterTest();
|
382 |
$this->resetAfterTest();
|
362 |
$this->setAdminUser();
|
383 |
$this->setAdminUser();
|
363 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
384 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
Línea 364... |
Línea 385... |
364 |
$qformat = $this->create_qformat('nested_categories_with_questions.xml', $SITE);
|
385 |
$qformat = $this->create_qformat('nested_categories_with_questions.xml');
|
365 |
|
386 |
|
366 |
$categoryiota = $generator->create_question_category([
|
387 |
$categoryiota = $generator->create_question_category([
|
367 |
'name' => 'Iota',
|
388 |
'name' => 'Iota',
|
368 |
'contextid' => context_course::instance($SITE->id)->id,
|
389 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
369 |
'info' => 'This is Iota category for test',
|
390 |
'info' => 'This is Iota category for test',
|
370 |
'infoformat' => '2',
|
391 |
'infoformat' => '2',
|
371 |
'stamp' => make_unique_id_code(),
|
392 |
'stamp' => make_unique_id_code(),
|
Línea 382... |
Línea 403... |
382 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
403 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
383 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
404 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
384 |
'penalty' => '1']);
|
405 |
'penalty' => '1']);
|
385 |
$categorykappa = $generator->create_question_category([
|
406 |
$categorykappa = $generator->create_question_category([
|
386 |
'name' => 'Kappa',
|
407 |
'name' => 'Kappa',
|
387 |
'contextid' => context_course::instance($SITE->id)->id,
|
408 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
388 |
'info' => 'This is Kappa category for test',
|
409 |
'info' => 'This is Kappa category for test',
|
389 |
'infoformat' => '4',
|
410 |
'infoformat' => '4',
|
390 |
'stamp' => make_unique_id_code(),
|
411 |
'stamp' => make_unique_id_code(),
|
391 |
'parent' => $categoryiota->id,
|
412 |
'parent' => $categoryiota->id,
|
392 |
'sortorder' => '999']);
|
413 |
'sortorder' => '999']);
|
393 |
$kappaquestion = $generator->create_question('essay', null, [
|
414 |
$kappaquestion = $generator->create_question('essay', null, [
|
394 |
'category' => $categorykappa->id,
|
415 |
'category' => $categorykappa->id,
|
395 |
'name' => 'Kappa Essay Question',
|
416 |
'name' => 'Kappa Essay Question',
|
- |
|
417 |
'questiontext' => [
|
- |
|
418 |
'format' => '0',
|
396 |
'questiontext' => ['text' => 'Testing Kappa Essay Question'],
|
419 |
'text' => 'Testing Kappa Essay Question',
|
- |
|
420 |
],
|
397 |
'generalfeedback' => '',
|
421 |
'generalfeedback' => '',
|
398 |
'responseformat' => 'editor',
|
422 |
'responseformat' => 'editor',
|
399 |
'responserequired' => 1,
|
423 |
'responserequired' => 1,
|
400 |
'responsefieldlines' => 10,
|
424 |
'responsefieldlines' => 10,
|
401 |
'attachments' => 0,
|
425 |
'attachments' => 0,
|
Línea 415... |
Línea 439... |
415 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
439 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
416 |
'penalty' => '1',
|
440 |
'penalty' => '1',
|
417 |
'idnumber' => '']);
|
441 |
'idnumber' => '']);
|
418 |
$categorylambda = $generator->create_question_category([
|
442 |
$categorylambda = $generator->create_question_category([
|
419 |
'name' => 'Lambda',
|
443 |
'name' => 'Lambda',
|
420 |
'contextid' => context_course::instance($SITE->id)->id,
|
444 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
421 |
'info' => 'This is Lambda category for test',
|
445 |
'info' => 'This is Lambda category for test',
|
422 |
'infoformat' => '0',
|
446 |
'infoformat' => '0',
|
423 |
'stamp' => make_unique_id_code(),
|
447 |
'stamp' => make_unique_id_code(),
|
424 |
'parent' => $categorykappa->id,
|
448 |
'parent' => $categorykappa->id,
|
425 |
'sortorder' => '999']);
|
449 |
'sortorder' => '999']);
|
Línea 434... |
Línea 458... |
434 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
458 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
435 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
459 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
436 |
'penalty' => '1']);
|
460 |
'penalty' => '1']);
|
437 |
$categorymu = $generator->create_question_category([
|
461 |
$categorymu = $generator->create_question_category([
|
438 |
'name' => 'Mu',
|
462 |
'name' => 'Mu',
|
439 |
'contextid' => context_course::instance($SITE->id)->id,
|
463 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
440 |
'info' => 'This is Mu category for test',
|
464 |
'info' => 'This is Mu category for test',
|
441 |
'infoformat' => '0',
|
465 |
'infoformat' => '0',
|
442 |
'stamp' => make_unique_id_code(),
|
466 |
'stamp' => make_unique_id_code(),
|
443 |
'parent' => $categoryiota->id,
|
467 |
'parent' => $categoryiota->id,
|
444 |
'sortorder' => '999']);
|
468 |
'sortorder' => '999']);
|
Línea 453... |
Línea 477... |
453 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
477 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
454 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
478 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
455 |
'penalty' => '1']);
|
479 |
'penalty' => '1']);
|
456 |
$qformat->setCategory($categoryiota);
|
480 |
$qformat->setCategory($categoryiota);
|
Línea 457... |
Línea 481... |
457 |
|
481 |
|
458 |
$expectedxml = file_get_contents(__DIR__ . '/fixtures/nested_categories_with_questions.xml');
|
482 |
$expectedxml = file_get_contents(self::get_fixture_path('qformat_xml', 'nested_categories_with_questions.xml'));
|
459 |
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
|
483 |
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
|
Línea 460... |
Línea 484... |
460 |
}
|
484 |
}
|
461 |
|
485 |
|
Línea 469... |
Línea 493... |
469 |
$this->resetAfterTest();
|
493 |
$this->resetAfterTest();
|
470 |
$this->setAdminUser();
|
494 |
$this->setAdminUser();
|
471 |
// Note while this loads $qformat with all the 'right' data from the xml file,
|
495 |
// Note while this loads $qformat with all the 'right' data from the xml file,
|
472 |
// the call to setCategory, followed by exportprocess will actually only export data
|
496 |
// the call to setCategory, followed by exportprocess will actually only export data
|
473 |
// from the database (created by the generator).
|
497 |
// from the database (created by the generator).
|
474 |
$qformat = $this->create_qformat('export_category.xml', $SITE);
|
498 |
$qformat = $this->create_qformat('export_category.xml');
|
Línea 475... |
Línea 499... |
475 |
|
499 |
|
476 |
$category = $generator->create_question_category([
|
500 |
$category = $generator->create_question_category([
|
477 |
'name' => 'Alpha',
|
501 |
'name' => 'Alpha',
|
478 |
'contextid' => context_course::instance($SITE->id)->id,
|
502 |
'contextid' => context_module::instance($this->qbank->cmid)->id,
|
479 |
'info' => 'This is Alpha category for test',
|
503 |
'info' => 'This is Alpha category for test',
|
480 |
'infoformat' => '0',
|
504 |
'infoformat' => '0',
|
481 |
'idnumber' => 'The inequalities < & >',
|
505 |
'idnumber' => 'The inequalities < & >',
|
482 |
'stamp' => make_unique_id_code(),
|
506 |
'stamp' => make_unique_id_code(),
|
Línea 492... |
Línea 516... |
492 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
516 |
'feedbacktrue' => ['format' => '1', 'text' => ''],
|
493 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
517 |
'feedbackfalse' => ['format' => '1', 'text' => ''],
|
494 |
'penalty' => '1']);
|
518 |
'penalty' => '1']);
|
495 |
$qformat->setCategory($category);
|
519 |
$qformat->setCategory($category);
|
Línea 496... |
Línea 520... |
496 |
|
520 |
|
497 |
$expectedxml = file_get_contents(__DIR__ . '/fixtures/html_chars_in_idnumbers.xml');
|
521 |
$expectedxml = file_get_contents(self::get_fixture_path('qformat_xml', 'html_chars_in_idnumbers.xml'));
|
498 |
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
|
522 |
$this->assert_same_xml($expectedxml, $qformat->exportprocess());
|
Línea 499... |
Línea 523... |
499 |
}
|
523 |
}
|
500 |
|
524 |
|
501 |
/**
|
525 |
/**
|
502 |
* Test that bad multianswer questions are not imported.
|
526 |
* Test that bad multianswer questions are not imported.
|
503 |
*/
|
527 |
*/
|
504 |
public function test_import_broken_multianswer_questions(): void {
|
528 |
public function test_import_broken_multianswer_questions(): void {
|
Línea 505... |
Línea 529... |
505 |
$lines = file(__DIR__ . '/fixtures/broken_cloze_questions.xml');
|
529 |
$lines = file(self::get_fixture_path('qformat_xml', 'broken_cloze_questions.xml'));
|
506 |
$importer = $qformat = new qformat_xml();
|
530 |
$importer = $qformat = new qformat_xml();
|
507 |
|
531 |
|