mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-32471 adding preview generation unit tests
The test image is a public domain file from http://commons.wikimedia.org/wiki/File:Easter_eggs_-_onion_decoration.jpg
This commit is contained in:
parent
fe68aac7d9
commit
8f110835c1
80
lib/filestorage/tests/file_storage_test.php
Normal file
80
lib/filestorage/tests/file_storage_test.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for /lib/filestorage/file_storage.php
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2012 David Mudrak <david@moodle.com>
|
||||
* @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());
|
||||
}
|
||||
}
|
BIN
lib/filestorage/tests/fixtures/testimage.jpg
vendored
Normal file
BIN
lib/filestorage/tests/fixtures/testimage.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
@ -29,6 +29,9 @@
|
||||
<directory suffix="_test.php">lib/ajax/tests</directory>
|
||||
<directory suffix="_test.php">lib/form/tests</directory>
|
||||
</testsuite>
|
||||
<testsuite name="core_files">
|
||||
<directory suffix="_test.php">lib/filestorage/tests</directory>
|
||||
</testsuite>
|
||||
<testsuite name="core_grade">
|
||||
<directory suffix="_test.php">lib/grade/tests</directory>
|
||||
<directory suffix="_test.php">grade/tests</directory>
|
||||
|
Loading…
x
Reference in New Issue
Block a user