MDL-36977 Add more unit tests for moodle1 backup conversion
[moodle.git] / backup / converter / moodle1 / tests / lib_test.php
CommitLineData
dbf5a447
PS
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 * Unit tests for the moodle1 converter
19 *
20 * @package core_backup
21 * @subpackage backup-convert
22 * @category phpunit
23 * @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30require_once($CFG->dirroot . '/backup/converter/moodle1/lib.php');
31
32
4b027431 33class moodle1_converter_testcase extends advanced_testcase {
dbf5a447
PS
34
35 /** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
36 protected $tempdir;
37
1d09e129
AB
38 /** @var string saved hash of an icon file used during testing */
39 protected $iconhash;
40
1cbf2a20 41 protected function setUp() {
dbf5a447
PS
42 global $CFG;
43
4ca04fb5 44 $this->tempdir = convert_helper::generate_id('unittest');
dbf5a447
PS
45 check_dir_exists("$CFG->tempdir/backup/$this->tempdir/course_files/sub1");
46 check_dir_exists("$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7");
47 copy(
bb7898c6 48 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/moodle.xml",
dbf5a447
PS
49 "$CFG->tempdir/backup/$this->tempdir/moodle.xml"
50 );
51 copy(
bb7898c6 52 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
dbf5a447
PS
53 "$CFG->tempdir/backup/$this->tempdir/course_files/file1.gif"
54 );
55 copy(
bb7898c6 56 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
dbf5a447
PS
57 "$CFG->tempdir/backup/$this->tempdir/course_files/sub1/file2.gif"
58 );
59 copy(
bb7898c6 60 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
dbf5a447
PS
61 "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/file1.gif"
62 );
63 copy(
bb7898c6 64 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
dbf5a447
PS
65 "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
66 );
1d09e129 67 $this->iconhash = sha1_file($CFG->tempdir.'/backup/'.$this->tempdir.'/moddata/unittest/4/icon.gif');
dbf5a447 68 copy(
bb7898c6 69 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
dbf5a447
PS
70 "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
71 );
72 }
73
1cbf2a20 74 protected function tearDown() {
dbf5a447
PS
75 global $CFG;
76 if (empty($CFG->keeptempdirectoriesonbackup)) {
77 fulldelete("$CFG->tempdir/backup/$this->tempdir");
78 }
79 }
80
81 public function test_detect_format() {
82 $detected = moodle1_converter::detect_format($this->tempdir);
83 $this->assertEquals(backup::FORMAT_MOODLE1, $detected);
84 }
85
86 public function test_convert_factory() {
87 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
88 $this->assertInstanceOf('moodle1_converter', $converter);
89 }
90
91 public function test_stash_storage_not_created() {
92 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
93 $this->setExpectedException('moodle1_convert_storage_exception');
94 $converter->set_stash('tempinfo', 12);
95 }
96
97 public function test_stash_requiring_empty_stash() {
98 $this->resetAfterTest(true);
99 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
100 $converter->create_stash_storage();
101 $converter->set_stash('tempinfo', 12);
102 $this->setExpectedException('moodle1_convert_empty_storage_exception');
103 try {
104 $converter->get_stash('anothertempinfo');
105
106 } catch (moodle1_convert_empty_storage_exception $e) {
107 // we must drop the storage here so we are able to re-create it in the next test
108 $converter->drop_stash_storage();
109 throw new moodle1_convert_empty_storage_exception('rethrowing');
110 }
111 }
112
113 public function test_stash_storage() {
114 $this->resetAfterTest(true);
115 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
116 $converter->create_stash_storage();
117
118 // no implicit stashes
119 $stashes = $converter->get_stash_names();
120 $this->assertEquals(gettype($stashes), 'array');
121 $this->assertTrue(empty($stashes));
122
123 // test stashes without itemid
124 $converter->set_stash('tempinfo1', 12);
125 $converter->set_stash('tempinfo2', array('a' => 2, 'b' => 3));
126 $stashes = $converter->get_stash_names();
127 $this->assertEquals('array', gettype($stashes));
128 $this->assertEquals(2, count($stashes));
129 $this->assertTrue(in_array('tempinfo1', $stashes));
130 $this->assertTrue(in_array('tempinfo2', $stashes));
131 $this->assertEquals(12, $converter->get_stash('tempinfo1'));
132 $this->assertEquals(array('a' => 2, 'b' => 3), $converter->get_stash('tempinfo2'));
133
134 // overwriting a stashed value is allowed
135 $converter->set_stash('tempinfo1', '13');
136 $this->assertNotSame(13, $converter->get_stash('tempinfo1'));
137 $this->assertSame('13', $converter->get_stash('tempinfo1'));
138
139 // repeated reading is allowed
140 $this->assertEquals('13', $converter->get_stash('tempinfo1'));
141
142 // storing empty array
143 $converter->set_stash('empty_array_stash', array());
144 $restored = $converter->get_stash('empty_array_stash');
145 //$this->assertEquals(gettype($restored), 'array'); // todo return null now, this needs MDL-27713 to be fixed, then uncomment
146 $this->assertTrue(empty($restored));
147
148 // test stashes with itemid
149 $converter->set_stash('tempinfo', 'Hello', 1);
150 $converter->set_stash('tempinfo', 'World', 2);
151 $this->assertSame('Hello', $converter->get_stash('tempinfo', 1));
152 $this->assertSame('World', $converter->get_stash('tempinfo', 2));
153
154 // test get_stash_itemids()
155 $ids = $converter->get_stash_itemids('course_fileref');
156 $this->assertEquals(gettype($ids), 'array');
157 $this->assertTrue(empty($ids));
158
159 $converter->set_stash('course_fileref', null, 34);
160 $converter->set_stash('course_fileref', null, 52);
161 $ids = $converter->get_stash_itemids('course_fileref');
162 $this->assertEquals(2, count($ids));
163 $this->assertTrue(in_array(34, $ids));
164 $this->assertTrue(in_array(52, $ids));
165
166 $converter->drop_stash_storage();
167 }
168
169 public function test_get_stash_or_default() {
170 $this->resetAfterTest(true);
171 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
172 $converter->create_stash_storage();
173
174 $this->assertTrue(is_null($converter->get_stash_or_default('stashname')));
175 $this->assertTrue(is_null($converter->get_stash_or_default('stashname', 7)));
176 $this->assertTrue('default' === $converter->get_stash_or_default('stashname', 0, 'default'));
177 $this->assertTrue(array('foo', 'bar') === $converter->get_stash_or_default('stashname', 42, array('foo', 'bar')));
178
179 //$converter->set_stash('stashname', 0);
180 //$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
181
182 //$converter->set_stash('stashname', '');
183 //$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
184
185 //$converter->set_stash('stashname', array());
186 //$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
187
188 $converter->set_stash('stashname', 42);
189 $this->assertTrue(42 === $converter->get_stash_or_default('stashname'));
190 $this->assertTrue(is_null($converter->get_stash_or_default('stashname', 1)));
191 $this->assertTrue(42 === $converter->get_stash_or_default('stashname', 0, 61));
192
193 $converter->set_stash('stashname', array(42 => (object)array('id' => 42)), 18);
194 $stashed = $converter->get_stash_or_default('stashname', 18, 1984);
195 $this->assertEquals(gettype($stashed), 'array');
196 $this->assertTrue(is_object($stashed[42]));
197 $this->assertTrue($stashed[42]->id === 42);
198
199 $converter->drop_stash_storage();
200 }
201
202 public function test_get_contextid() {
203 $this->resetAfterTest(true);
204
205 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
206
207 // stash storage must be created in advance
208 $converter->create_stash_storage();
209
210 // ids are generated on the first call
211 $id1 = $converter->get_contextid(CONTEXT_BLOCK, 10);
212 $id2 = $converter->get_contextid(CONTEXT_BLOCK, 11);
213 $id3 = $converter->get_contextid(CONTEXT_MODULE, 10);
214
215 $this->assertNotEquals($id1, $id2);
216 $this->assertNotEquals($id1, $id3);
217 $this->assertNotEquals($id2, $id3);
218
219 // and then re-used if called with the same params
220 $this->assertEquals($id1, $converter->get_contextid(CONTEXT_BLOCK, 10));
221 $this->assertEquals($id2, $converter->get_contextid(CONTEXT_BLOCK, 11));
222 $this->assertEquals($id3, $converter->get_contextid(CONTEXT_MODULE, 10));
223
224 // for system and course level, the instance is irrelevant
225 // as we need only one system and one course
226 $id1 = $converter->get_contextid(CONTEXT_COURSE);
227 $id2 = $converter->get_contextid(CONTEXT_COURSE, 10);
228 $id3 = $converter->get_contextid(CONTEXT_COURSE, 14);
229
230 $this->assertEquals($id1, $id2);
231 $this->assertEquals($id1, $id3);
232
233 $id1 = $converter->get_contextid(CONTEXT_SYSTEM);
234 $id2 = $converter->get_contextid(CONTEXT_SYSTEM, 11);
235 $id3 = $converter->get_contextid(CONTEXT_SYSTEM, 15);
236
237 $this->assertEquals($id1, $id2);
238 $this->assertEquals($id1, $id3);
239
240 $converter->drop_stash_storage();
241 }
242
243 public function test_get_nextid() {
244 $this->resetAfterTest(true);
245
246 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
247
248 $id1 = $converter->get_nextid();
249 $id2 = $converter->get_nextid();
250 $id3 = $converter->get_nextid();
251
252 $this->assertTrue(0 < $id1);
253 $this->assertTrue($id1 < $id2);
254 $this->assertTrue($id2 < $id3);
255 }
256
257 public function test_migrate_file() {
258 $this->resetAfterTest(true);
259
260 // set-up the file manager
261 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
262 $converter->create_stash_storage();
263 $contextid = $converter->get_contextid(CONTEXT_MODULE, 32);
264 $fileman = $converter->get_file_manager($contextid, 'mod_unittest', 'testarea');
265 // this fileman has not converted anything yet
266 $fileids = $fileman->get_fileids();
267 $this->assertEquals(gettype($fileids), 'array');
268 $this->assertEquals(0, count($fileids));
269 // try to migrate a non-existing directory
270 $returned = $fileman->migrate_directory('not/existing/directory');
271 $this->assertEquals(gettype($returned), 'array');
272 $this->assertEquals(0, count($returned));
273 $fileids = $fileman->get_fileids();
274 $this->assertEquals(gettype($fileids), 'array');
275 $this->assertEquals(0, count($fileids));
02a6f3b0
DM
276 // try to migrate an invalid file
277 $fileman->itemid = 1;
278 $thrown = false;
279 try {
280 $fileman->migrate_file('/../../../../../../../../../../../../../../etc/passwd');
281 } catch (moodle1_convert_exception $e) {
282 $thrown = true;
283 }
284 $this->assertTrue($thrown);
dbf5a447
PS
285 // migrate a single file
286 $fileman->itemid = 4;
287 $fileman->migrate_file('moddata/unittest/4/icon.gif');
1d09e129
AB
288 $subdir = substr($this->iconhash, 0, 2);
289 $this->assertTrue(is_file($converter->get_workdir_path().'/files/'.$subdir.'/'.$this->iconhash));
dbf5a447
PS
290 // get the file id
291 $fileids = $fileman->get_fileids();
292 $this->assertEquals(gettype($fileids), 'array');
293 $this->assertEquals(1, count($fileids));
294 // migrate another single file into another file area
295 $fileman->filearea = 'anotherarea';
296 $fileman->itemid = 7;
297 $fileman->migrate_file('moddata/unittest/4/7/icon.gif', '/', 'renamed.gif');
298 // get the file records
299 $filerecordids = $converter->get_stash_itemids('files');
300 foreach ($filerecordids as $filerecordid) {
301 $filerecord = $converter->get_stash('files', $filerecordid);
1d09e129 302 $this->assertEquals($this->iconhash, $filerecord['contenthash']);
dbf5a447
PS
303 $this->assertEquals($contextid, $filerecord['contextid']);
304 $this->assertEquals('mod_unittest', $filerecord['component']);
305 if ($filerecord['filearea'] === 'testarea') {
306 $this->assertEquals(4, $filerecord['itemid']);
307 $this->assertEquals('icon.gif', $filerecord['filename']);
308 }
309 }
310 // explicitly clear the list of migrated files
311 $this->assertTrue(count($fileman->get_fileids()) > 0);
312 $fileman->reset_fileids();
313 $this->assertTrue(count($fileman->get_fileids()) == 0);
314 $converter->drop_stash_storage();
315 }
316
317 public function test_convert_path() {
318 $path = new convert_path('foo_bar', '/ROOT/THINGS/FOO/BAR');
319 $this->assertEquals('foo_bar', $path->get_name());
320 $this->assertEquals('/ROOT/THINGS/FOO/BAR', $path->get_path());
321 $this->assertEquals('process_foo_bar', $path->get_processing_method());
322 $this->assertEquals('on_foo_bar_start', $path->get_start_method());
323 $this->assertEquals('on_foo_bar_end', $path->get_end_method());
324 }
325
326 public function test_convert_path_implicit_recipes() {
327 $path = new convert_path('foo_bar', '/ROOT/THINGS/FOO/BAR');
328 $data = array(
329 'ID' => 76,
330 'ELOY' => 'stronk7',
331 'MARTIN' => 'moodler',
332 'EMPTY' => null,
333 );
334 // apply default recipes (converting keys to lowercase)
335 $data = $path->apply_recipes($data);
336 $this->assertEquals(4, count($data));
337 $this->assertEquals(76, $data['id']);
338 $this->assertEquals('stronk7', $data['eloy']);
339 $this->assertEquals('moodler', $data['martin']);
340 $this->assertSame(null, $data['empty']);
341 }
342
343 public function test_convert_path_explicit_recipes() {
344 $path = new convert_path(
345 'foo_bar', '/ROOT/THINGS/FOO/BAR',
346 array(
347 'newfields' => array(
348 'david' => 'mudrd8mz',
349 'petr' => 'skodak',
350 ),
351 'renamefields' => array(
352 'empty' => 'nothing',
353 ),
354 'dropfields' => array(
355 'id'
356 ),
357 )
358 );
359 $data = array(
360 'ID' => 76,
361 'ELOY' => 'stronk7',
362 'MARTIN' => 'moodler',
363 'EMPTY' => null,
364 );
365 $data = $path->apply_recipes($data);
366
367 $this->assertEquals(5, count($data));
368 $this->assertFalse(array_key_exists('id', $data));
369 $this->assertEquals('stronk7', $data['eloy']);
370 $this->assertEquals('moodler', $data['martin']);
371 $this->assertEquals('mudrd8mz', $data['david']);
372 $this->assertEquals('skodak', $data['petr']);
373 $this->assertSame(null, $data['nothing']);
374 }
375
376 public function test_grouped_data_on_nongrouped_convert_path() {
377 // prepare some grouped data
378 $data = array(
379 'ID' => 77,
380 'NAME' => 'Pale lagers',
381 'BEERS' => array(
382 array(
383 'BEER' => array(
384 'ID' => 67,
385 'NAME' => 'Pilsner Urquell',
386 )
387 ),
388 array(
389 'BEER' => array(
390 'ID' => 34,
391 'NAME' => 'Heineken',
392 )
393 ),
394 )
395 );
396
397 // declare a non-grouped path
398 $path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE');
399
400 // an attempt to apply recipes throws exception because we do not expect grouped data
401 $this->setExpectedException('convert_path_exception');
402 $data = $path->apply_recipes($data);
403 }
404
405 public function test_grouped_convert_path_with_recipes() {
406 // prepare some grouped data
407 $data = array(
408 'ID' => 77,
409 'NAME' => 'Pale lagers',
410 'BEERS' => array(
411 array(
412 'BEER' => array(
413 'ID' => 67,
414 'NAME' => 'Pilsner Urquell',
415 )
416 ),
417 array(
418 'BEER' => array(
419 'ID' => 34,
420 'NAME' => 'Heineken',
421 )
422 ),
423 )
424 );
425
426 // implict recipes work for grouped data if the path is declared as grouped
427 $path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE', array(), true);
428 $data = $path->apply_recipes($data);
429 $this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);
430
431 // an attempt to provide explicit recipes on grouped elements throws exception
432 $this->setExpectedException('convert_path_exception');
433 $path = new convert_path(
434 'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
435 array(
436 'renamefields' => array(
437 'name' => 'beername', // note this is confusing recipe because the 'name' is used for both
438 // beer-style name ('Pale lagers') and beer name ('Pilsner Urquell')
439 )
440 ), true);
441 }
442
443 public function test_referenced_course_files() {
444
445 $text = 'This is a text containing links to file.php
446as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif" /><a href="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif$@FORCEDOWNLOAD@$">download image</a><br />
02a6f3b0
DM
447 <div><a href=\'$@FILEPHP@$/../../../../../../../../../../../../../../../etc/passwd\'>download passwords</a></div>
448 <div><a href=\'$@FILEPHP@$$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$etc$@SLASH@$shadow\'>download shadows</a></div>
dbf5a447
PS
449 <br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />';
450
451 $files = moodle1_converter::find_referenced_files($text);
452 $this->assertEquals(gettype($files), 'array');
453 $this->assertEquals(2, count($files));
454 $this->assertTrue(in_array('/pics/news.gif', $files));
455 $this->assertTrue(in_array('/MANUAL.DOC', $files));
456
045053f6 457 $text = moodle1_converter::rewrite_filephp_usage($text, array('/pics/news.gif', '/another/file/notused.txt'));
dbf5a447
PS
458 $this->assertEquals($text, 'This is a text containing links to file.php
459as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="@@PLUGINFILE@@/pics/news.gif" /><a href="@@PLUGINFILE@@/pics/news.gif?forcedownload=1">download image</a><br />
02a6f3b0
DM
460 <div><a href=\'$@FILEPHP@$/../../../../../../../../../../../../../../../etc/passwd\'>download passwords</a></div>
461 <div><a href=\'$@FILEPHP@$$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$..$@SLASH@$etc$@SLASH@$shadow\'>download shadows</a></div>
dbf5a447
PS
462 <br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />');
463 }
464
bdc69570 465 public function test_referenced_files_urlencoded() {
045053f6 466
bdc69570
PN
467 $text = 'This is a text containing links to file.php
468as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif" /><a href="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif$@FORCEDOWNLOAD@$">no space</a><br />
045053f6
DM
469 <br /><a href=\'$@FILEPHP@$$@SLASH@$pics$@SLASH@$news%20with%20spaces.gif$@FORCEDOWNLOAD@$\'>with urlencoded spaces</a><br />
470<a href="$@FILEPHP@$$@SLASH@$illegal%20pics%2Bmovies$@SLASH@$romeo%2Bjuliet.avi">Download the full AVI for free! (space and plus encoded)</a>
471<a href="$@FILEPHP@$$@SLASH@$illegal pics+movies$@SLASH@$romeo+juliet.avi">Download the full AVI for free! (none encoded)</a>
472<a href="$@FILEPHP@$$@SLASH@$illegal%20pics+movies$@SLASH@$romeo+juliet.avi">Download the full AVI for free! (only space encoded)</a>
473<a href="$@FILEPHP@$$@SLASH@$illegal pics%2Bmovies$@SLASH@$romeo%2Bjuliet.avi">Download the full AVI for free! (only plus)</a>';
bdc69570
PN
474
475 $files = moodle1_converter::find_referenced_files($text);
476 $this->assertEquals(gettype($files), 'array');
045053f6 477 $this->assertEquals(3, count($files));
bdc69570
PN
478 $this->assertTrue(in_array('/pics/news.gif', $files));
479 $this->assertTrue(in_array('/pics/news with spaces.gif', $files));
045053f6
DM
480 $this->assertTrue(in_array('/illegal pics+movies/romeo+juliet.avi', $files));
481
482 $text = moodle1_converter::rewrite_filephp_usage($text, $files);
483 $this->assertEquals('This is a text containing links to file.php
484as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="@@PLUGINFILE@@/pics/news.gif" /><a href="@@PLUGINFILE@@/pics/news.gif?forcedownload=1">no space</a><br />
485 <br /><a href=\'@@PLUGINFILE@@/pics/news%20with%20spaces.gif?forcedownload=1\'>with urlencoded spaces</a><br />
486<a href="@@PLUGINFILE@@/illegal%20pics%2Bmovies/romeo%2Bjuliet.avi">Download the full AVI for free! (space and plus encoded)</a>
487<a href="@@PLUGINFILE@@/illegal%20pics%2Bmovies/romeo%2Bjuliet.avi">Download the full AVI for free! (none encoded)</a>
488<a href="$@FILEPHP@$$@SLASH@$illegal%20pics+movies$@SLASH@$romeo+juliet.avi">Download the full AVI for free! (only space encoded)</a>
489<a href="$@FILEPHP@$$@SLASH@$illegal pics%2Bmovies$@SLASH@$romeo%2Bjuliet.avi">Download the full AVI for free! (only plus)</a>', $text);
bdc69570
PN
490 }
491
dbf5a447
PS
492 public function test_question_bank_conversion() {
493 global $CFG;
494
495 $this->resetAfterTest(true);
496
497 copy(
bb7898c6 498 "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/questions.xml",
dbf5a447
PS
499 "$CFG->tempdir/backup/$this->tempdir/moodle.xml"
500 );
501 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
502 $converter->convert();
503 }
504
505 public function test_convert_run_convert() {
506 $this->resetAfterTest(true);
507 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
508 $converter->convert();
509 }
510
511 public function test_inforef_manager() {
512 $converter = convert_factory::get_converter('moodle1', $this->tempdir);
513 $inforef = $converter->get_inforef_manager('unittest');
514 $inforef->add_ref('file', 45);
515 $inforef->add_refs('file', array(46, 47));
516 // todo test the write_refs() via some dummy xml_writer
517 $this->setExpectedException('coding_exception');
518 $inforef->add_ref('unknown_referenced_item_name', 76);
519 }
520}