From 2fa99602c6f6431e99468ca13f4a58344a401c24 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 8 Feb 2015 20:46:14 +0100 Subject: [ticket/8672] Add class for retrieving imagesize without download getimagesize() always downloads the complete file before checking the actual image dimensions. This class will be able to do the same without having to download possibly large files. PHPBB3-8672 --- tests/upload/fixture/bmp | Bin 0 -> 64 bytes tests/upload/fixture/iff | Bin 0 -> 120 bytes tests/upload/fixture/iff_maya | Bin 0 -> 88 bytes tests/upload/fixture/jp2 | Bin 0 -> 528 bytes tests/upload/fixture/jpx | Bin 0 -> 528 bytes tests/upload/fixture/psd | Bin 0 -> 6374 bytes tests/upload/fixture/tif_compressed | Bin 0 -> 236 bytes tests/upload/fixture/tif_msb | Bin 0 -> 222 bytes tests/upload/fixture/wbmp | Bin 0 -> 5 bytes tests/upload/imagesize_test.php | 99 ++++++++++++++++++++++++++++++++++++ 10 files changed, 99 insertions(+) create mode 100644 tests/upload/fixture/bmp create mode 100644 tests/upload/fixture/iff create mode 100644 tests/upload/fixture/iff_maya create mode 100644 tests/upload/fixture/jp2 create mode 100644 tests/upload/fixture/jpx create mode 100644 tests/upload/fixture/psd create mode 100644 tests/upload/fixture/tif_compressed create mode 100644 tests/upload/fixture/tif_msb create mode 100644 tests/upload/fixture/wbmp create mode 100644 tests/upload/imagesize_test.php (limited to 'tests/upload') diff --git a/tests/upload/fixture/bmp b/tests/upload/fixture/bmp new file mode 100644 index 0000000000..04bff561ab Binary files /dev/null and b/tests/upload/fixture/bmp differ diff --git a/tests/upload/fixture/iff b/tests/upload/fixture/iff new file mode 100644 index 0000000000..24eda8f593 Binary files /dev/null and b/tests/upload/fixture/iff differ diff --git a/tests/upload/fixture/iff_maya b/tests/upload/fixture/iff_maya new file mode 100644 index 0000000000..b6fb85101b Binary files /dev/null and b/tests/upload/fixture/iff_maya differ diff --git a/tests/upload/fixture/jp2 b/tests/upload/fixture/jp2 new file mode 100644 index 0000000000..adca6ecf0e Binary files /dev/null and b/tests/upload/fixture/jp2 differ diff --git a/tests/upload/fixture/jpx b/tests/upload/fixture/jpx new file mode 100644 index 0000000000..adca6ecf0e Binary files /dev/null and b/tests/upload/fixture/jpx differ diff --git a/tests/upload/fixture/psd b/tests/upload/fixture/psd new file mode 100644 index 0000000000..d1bc9a6a70 Binary files /dev/null and b/tests/upload/fixture/psd differ diff --git a/tests/upload/fixture/tif_compressed b/tests/upload/fixture/tif_compressed new file mode 100644 index 0000000000..133b50c4f0 Binary files /dev/null and b/tests/upload/fixture/tif_compressed differ diff --git a/tests/upload/fixture/tif_msb b/tests/upload/fixture/tif_msb new file mode 100644 index 0000000000..32eb8abfbb Binary files /dev/null and b/tests/upload/fixture/tif_msb differ diff --git a/tests/upload/fixture/wbmp b/tests/upload/fixture/wbmp new file mode 100644 index 0000000000..708c86ccee Binary files /dev/null and b/tests/upload/fixture/wbmp differ diff --git a/tests/upload/imagesize_test.php b/tests/upload/imagesize_test.php new file mode 100644 index 0000000000..2ce712e5c1 --- /dev/null +++ b/tests/upload/imagesize_test.php @@ -0,0 +1,99 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once(__DIR__ . '/../../phpBB/includes/functions.php'); + +class phpbb_upload_imagesize_test extends \phpbb_test_case +{ + /** @var \phpbb\upload\imagesize */ + protected $imagesize; + + /** @var string Path to fixtures */ + protected $path; + + public function setUp() + { + parent::setUp(); + $this->imagesize = new \phpbb\upload\imagesize(); + $this->path = __DIR__ . '/fixture/'; + } + + public function data_get_imagesize() + { + return array( + array('foobar', 'image/bmp', false), + array('png', 'image/png', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_PNG)), + array('gif', 'image/png', false), + array('png', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_PNG)), + array('gif', 'image/gif', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_GIF)), + array('jpg', 'image/gif', false), + array('gif', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_GIF)), + array('jpg', 'image/jpg', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)), + array('jpg', 'image/jpeg', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)), + array('png', 'image/jpg', false), + array('jpg', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)), + array('psd', 'image/psd', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)), + array('psd', 'image/photoshop', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)), + array('jpg', 'image/psd', false), + array('psd', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)), + array('bmp', 'image/bmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_BMP)), + array('png', 'image/bmp', false), + array('bmp', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_BMP)), + array('tif', 'image/tif', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), + array('png', 'image/tif', false), + array('tif', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), + array('tif_compressed', 'image/tif', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), + array('png', 'image/tiff', false), + array('tif_compressed', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)), + array('tif_msb', 'image/tif', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_MM)), + array('tif_msb', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_MM)), + array('wbmp', 'image/wbmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)), + array('wbmp', 'image/vnd.wap.wbmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)), + array('png', 'image/vnd.wap.wbmp', false), + array('wbmp', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)), + array('iff', 'image/iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), + array('iff', 'image/x-iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), + array('iff_maya', 'iamge/iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), + array('png', 'image/iff', false), + array('png', 'image/x-iff', false), + array('iff', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), + array('iff_maya', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)), + array('jp2', 'image/jp2', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), + array('jp2', 'image/jpx', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), + array('jp2', 'image/jpm', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), + array('jpg', 'image/jp2', false), + array('jpx', 'image/jpx', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), + array('jp2', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), + array('jpx', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)), + ); + } + + /** + * @dataProvider data_get_imagesize + */ + public function test_get_imagesize($file, $mime_type, $expected) + { + $this->assertEquals($expected, $this->imagesize->get_imagesize($this->path . $file, $mime_type)); + } + + public function test_get_imagesize_remote() + { + $this->assertSame(array( + 'width' => 80, + 'height' => 80, + 'type' => IMAGETYPE_JPEG, + ), + $this->imagesize->get_imagesize('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg')); + } +} -- cgit v1.2.1 From 39d6180c6814996dde84cfcd8c0150bba37354ac Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 7 Apr 2015 16:19:36 +0200 Subject: [ticket/8672] Use fastImageSize in classes PHPBB3-8672 --- tests/upload/imagesize_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/upload') diff --git a/tests/upload/imagesize_test.php b/tests/upload/imagesize_test.php index 2ce712e5c1..bfea4b819d 100644 --- a/tests/upload/imagesize_test.php +++ b/tests/upload/imagesize_test.php @@ -16,7 +16,7 @@ require_once(__DIR__ . '/../../phpBB/includes/functions.php'); class phpbb_upload_imagesize_test extends \phpbb_test_case { - /** @var \phpbb\upload\imagesize */ + /** @var \fastImageSize\fastImageSize */ protected $imagesize; /** @var string Path to fixtures */ @@ -25,7 +25,7 @@ class phpbb_upload_imagesize_test extends \phpbb_test_case public function setUp() { parent::setUp(); - $this->imagesize = new \phpbb\upload\imagesize(); + $this->imagesize = new \fastImageSize\fastImageSize(); $this->path = __DIR__ . '/fixture/'; } @@ -84,7 +84,7 @@ class phpbb_upload_imagesize_test extends \phpbb_test_case */ public function test_get_imagesize($file, $mime_type, $expected) { - $this->assertEquals($expected, $this->imagesize->get_imagesize($this->path . $file, $mime_type)); + $this->assertEquals($expected, $this->imagesize->getImageSize($this->path . $file, $mime_type)); } public function test_get_imagesize_remote() @@ -94,6 +94,6 @@ class phpbb_upload_imagesize_test extends \phpbb_test_case 'height' => 80, 'type' => IMAGETYPE_JPEG, ), - $this->imagesize->get_imagesize('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg')); + $this->imagesize->getImageSize('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg')); } } -- cgit v1.2.1 From 55c5bc126decffeaa74abdb853eb010cc3dcda8c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 18 Apr 2015 14:01:21 +0200 Subject: [ticket/8672] User $user->lang() instead of sprintf PHPBB3-8672 --- tests/upload/filespec_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/upload') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 8fbb437ef0..f6deb242a2 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -287,7 +287,7 @@ class phpbb_filespec_test extends phpbb_test_case array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true), array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), - array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), + array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH png jpg', true), ); } -- cgit v1.2.1