diff options
author | Marc Alexander <admin@m-a-styles.de> | 2014-01-09 23:50:40 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2014-06-23 21:37:47 +0200 |
commit | 9bc6e641bfbe53c3920662ee8e24a723ac34e6a1 (patch) | |
tree | e988faa6aa56d42c40ac4121e90c01a9b1d55a8b /tests/upload/filespec_test.php | |
parent | 83326718132811d8b57ac8612ff50887ec0fa101 (diff) | |
download | forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar.gz forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar.bz2 forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.tar.xz forums-9bc6e641bfbe53c3920662ee8e24a723ac34e6a1.zip |
[ticket/11148] Add mimetype guesser to filespec and fileupload class
The mimetype guesser will be used to get the mimetype of uploaded files.
Until now, this was only used for files uploaded with plupload. If a file
doesn't have a mimetype supplied, we will now try to get the correct mimetype.
PHPBB3-11148
Diffstat (limited to 'tests/upload/filespec_test.php')
-rw-r--r-- | tests/upload/filespec_test.php | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 5e333213f4..d8fa82e2b5 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -65,6 +65,16 @@ class phpbb_filespec_test extends phpbb_test_case copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy_2'); } } + + $guessers = array( + new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), + new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(), + new \phpbb\mimetype\content_guesser(), + new \phpbb\mimetype\extension_guesser(), + ); + $guessers[2]->set_priority(-2); + $guessers[3]->set_priority(-2); + $this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); } private function get_filespec($override = array()) @@ -78,7 +88,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - return new filespec(array_merge($upload_ary, $override), null); + return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser); } protected function tearDown() @@ -222,6 +232,9 @@ class phpbb_filespec_test extends phpbb_test_case array('png', 'image/png', true), array('tif', 'image/tif', true), array('txt', 'text/plain', false), + array('jpg', 'application/octet-stream', false), + array('gif', 'application/octetstream', false), + array('png', 'application/mime', false), ); } @@ -234,6 +247,30 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $filespec->is_image()); } + public function is_image_get_mimetype() + { + return array( + array('gif', 'image/gif', true), + array('jpg', 'image/jpg', true), + array('png', 'image/png', true), + array('tif', 'image/tif', true), + array('txt', 'text/plain', false), + array('jpg', 'application/octet-stream', true), + array('gif', 'application/octetstream', true), + array('png', 'application/mime', true), + ); + } + + /** + * @dataProvider is_image_get_mimetype + */ + public function test_is_image_get_mimetype($filename, $mimetype, $expected) + { + $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); + $filespec->get_mimetype($this->path . $filename); + $this->assertEquals($expected, $filespec->is_image()); + } + public function move_file_variables() { return array( |