Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-36977 Add more unit tests for moodle1 backup conversion
  • Loading branch information
mudrd8mz authored and danpoltawski committed Jan 8, 2013
1 parent 65d6ca2 commit 4a27bde
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions backup/converter/moodle1/simpletest/testlib.php
Expand Up @@ -260,6 +260,15 @@ public function test_migrate_file() {
$fileids = $fileman->get_fileids();
$this->assertIsA($fileids, 'array');
$this->assertEqual(0, count($fileids));
// try to migrate an invalid file
$fileman->itemid = 1;
$thrown = false;
try {
$fileman->migrate_file('/../../../../../../../../../../../../../../etc/passwd');
} catch (moodle1_convert_exception $e) {
$thrown = true;
}
$this->assertTrue($thrown);
// migrate a single file
$fileman->itemid = 4;
$fileman->migrate_file('moddata/unittest/4/icon.gif');
Expand Down Expand Up @@ -421,6 +430,8 @@ public function test_referenced_course_files() {

$text = 'This is a text containing links to file.php
as 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 />
<div><a href=\'$@FILEPHP@$/../../../../../../../../../../../../../../../etc/passwd\'>download passwords</a></div>
<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>
<br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />';

$files = moodle1_converter::find_referenced_files($text);
Expand All @@ -432,6 +443,8 @@ public function test_referenced_course_files() {
$text = moodle1_converter::rewrite_filephp_usage($text, array('/pics/news.gif', '/another/file/notused.txt'), $files);
$this->assertEqual($text, 'This is a text containing links to file.php
as 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 />
<div><a href=\'$@FILEPHP@$/../../../../../../../../../../../../../../../etc/passwd\'>download passwords</a></div>
<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>
<br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />');
}

Expand Down

0 comments on commit 4a27bde

Please sign in to comment.