diff --git a/lib/filestorage/tests/file_storage_test.php b/lib/filestorage/tests/file_storage_test.php new file mode 100644 index 00000000000..ba31f8043a9 --- /dev/null +++ b/lib/filestorage/tests/file_storage_test.php @@ -0,0 +1,80 @@ +. + +/** + * Unit tests for /lib/filestorage/file_storage.php + * + * @package core + * @category test + * @copyright 2012 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->libdir . '/filelib.php'); + +class filestoragelib_testcase extends advanced_testcase { + + /** + * Local files can be added to the filepool + */ + public function test_create_file_from_pathname() { + global $CFG; + + $this->resetAfterTest(false); + + $filepath = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg'; + $syscontext = context_system::instance(); + $filerecord = array( + 'contextid' => $syscontext->id, + 'component' => 'core', + 'filearea' => 'unittest', + 'itemid' => 0, + 'filepath' => '/images/', + 'filename' => 'testimage.jpg', + ); + + $fs = get_file_storage(); + $fs->create_file_from_pathname($filerecord, $filepath); + + $this->assertTrue($fs->file_exists($syscontext->id, 'core', 'unittest', 0, '/images/', 'testimage.jpg')); + + return $fs->get_file($syscontext->id, 'core', 'unittest', 0, '/images/', 'testimage.jpg'); + } + + /** + * Local images can be added to the filepool and their preview can be obtained + * + * @depends test_create_file_from_pathname + */ + public function test_get_file_preview(stored_file $file) { + global $CFG; + + $this->resetAfterTest(true); + $fs = get_file_storage(); + + $previewtinyicon = $fs->get_file_preview($file, 'tinyicon'); + $this->assertInstanceOf('stored_file', $previewtinyicon); + $this->assertEquals('6b9864ae1536a8eeef54e097319175a8be12f07c', $previewtinyicon->get_filename()); + + $previewtinyicon = $fs->get_file_preview($file, 'thumb'); + $this->assertInstanceOf('stored_file', $previewtinyicon); + $this->assertEquals('6b9864ae1536a8eeef54e097319175a8be12f07c', $previewtinyicon->get_filename()); + } +} diff --git a/lib/filestorage/tests/fixtures/testimage.jpg b/lib/filestorage/tests/fixtures/testimage.jpg new file mode 100644 index 00000000000..15e05d1c32d Binary files /dev/null and b/lib/filestorage/tests/fixtures/testimage.jpg differ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f0838ee6ba8..be46f6bf505 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,6 +29,9 @@ lib/ajax/tests lib/form/tests + + lib/filestorage/tests + lib/grade/tests grade/tests