aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTristan Darricau <tristan.darricau@sensiolabs.com>2015-04-27 16:26:40 +0200
committerTristan Darricau <tristan.darricau@sensiolabs.com>2015-04-27 16:26:40 +0200
commit734b89e75cdb02ae436b03d3247cfa820e03f42c (patch)
tree8d348e342bce8db60211ec63deed795c7e5df64e /tests
parente7d297740117e644be18e2b9793471da5697c879 (diff)
parent9088f448633ff42d767afac674324d1e26911ab6 (diff)
downloadforums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar.gz
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar.bz2
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar.xz
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.zip
Merge pull request #3524 from marc1706/ticket/8672
[ticket/8672] Add class for retrieving imagesize without download
Diffstat (limited to 'tests')
-rw-r--r--tests/avatar/manager_test.php5
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php4
-rw-r--r--tests/upload/filespec_test.php2
-rw-r--r--tests/upload/fixture/bmpbin0 -> 64 bytes
-rw-r--r--tests/upload/fixture/iffbin0 -> 120 bytes
-rw-r--r--tests/upload/fixture/iff_mayabin0 -> 88 bytes
-rw-r--r--tests/upload/fixture/jp2bin0 -> 528 bytes
-rw-r--r--tests/upload/fixture/jpxbin0 -> 528 bytes
-rw-r--r--tests/upload/fixture/psdbin0 -> 6374 bytes
-rw-r--r--tests/upload/fixture/tif_compressedbin0 -> 236 bytes
-rw-r--r--tests/upload/fixture/tif_msbbin0 -> 222 bytes
-rw-r--r--tests/upload/fixture/wbmpbin0 -> 5 bytes
-rw-r--r--tests/upload/imagesize_test.php99
13 files changed, 107 insertions, 3 deletions
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index 4befbfc1fc..638ba0aaff 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -57,9 +57,10 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
new \phpbb\mimetype\content_guesser,
);
$guesser = new \phpbb\mimetype\guesser($guessers);
+ $imagesize = new \fastImageSize\fastImageSize();
// $this->avatar_foobar will be needed later on
- $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache));
$this->avatar_foobar->expects($this->any())
->method('get_name')
->will($this->returnValue('avatar.driver.foobar'));
@@ -74,7 +75,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
{
if ($driver !== 'upload')
{
- $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache));
}
else
{
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 09fec38013..0f9b049f44 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -458,6 +458,10 @@ class phpbb_test_case_helpers
{
$dispatcher = new phpbb_mock_event_dispatcher;
}
+ if (!isset($phpbb_dispatcher))
+ {
+ $phpbb_dispatcher = $dispatcher;
+ }
// Create and register the text_formatter.s9e.factory service
$factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer);
diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php
index 0ecc0ceece..f953970f64 100644
--- a/tests/upload/filespec_test.php
+++ b/tests/upload/filespec_test.php
@@ -289,7 +289,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),
);
}
diff --git a/tests/upload/fixture/bmp b/tests/upload/fixture/bmp
new file mode 100644
index 0000000000..04bff561ab
--- /dev/null
+++ b/tests/upload/fixture/bmp
Binary files differ
diff --git a/tests/upload/fixture/iff b/tests/upload/fixture/iff
new file mode 100644
index 0000000000..24eda8f593
--- /dev/null
+++ b/tests/upload/fixture/iff
Binary files differ
diff --git a/tests/upload/fixture/iff_maya b/tests/upload/fixture/iff_maya
new file mode 100644
index 0000000000..b6fb85101b
--- /dev/null
+++ b/tests/upload/fixture/iff_maya
Binary files differ
diff --git a/tests/upload/fixture/jp2 b/tests/upload/fixture/jp2
new file mode 100644
index 0000000000..adca6ecf0e
--- /dev/null
+++ b/tests/upload/fixture/jp2
Binary files differ
diff --git a/tests/upload/fixture/jpx b/tests/upload/fixture/jpx
new file mode 100644
index 0000000000..adca6ecf0e
--- /dev/null
+++ b/tests/upload/fixture/jpx
Binary files differ
diff --git a/tests/upload/fixture/psd b/tests/upload/fixture/psd
new file mode 100644
index 0000000000..d1bc9a6a70
--- /dev/null
+++ b/tests/upload/fixture/psd
Binary files differ
diff --git a/tests/upload/fixture/tif_compressed b/tests/upload/fixture/tif_compressed
new file mode 100644
index 0000000000..133b50c4f0
--- /dev/null
+++ b/tests/upload/fixture/tif_compressed
Binary files differ
diff --git a/tests/upload/fixture/tif_msb b/tests/upload/fixture/tif_msb
new file mode 100644
index 0000000000..32eb8abfbb
--- /dev/null
+++ b/tests/upload/fixture/tif_msb
Binary files differ
diff --git a/tests/upload/fixture/wbmp b/tests/upload/fixture/wbmp
new file mode 100644
index 0000000000..708c86ccee
--- /dev/null
+++ b/tests/upload/fixture/wbmp
Binary files differ
diff --git a/tests/upload/imagesize_test.php b/tests/upload/imagesize_test.php
new file mode 100644
index 0000000000..bfea4b819d
--- /dev/null
+++ b/tests/upload/imagesize_test.php
@@ -0,0 +1,99 @@
+<?php
+
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @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 \fastImageSize\fastImageSize */
+ protected $imagesize;
+
+ /** @var string Path to fixtures */
+ protected $path;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->imagesize = new \fastImageSize\fastImageSize();
+ $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->getImageSize($this->path . $file, $mime_type));
+ }
+
+ public function test_get_imagesize_remote()
+ {
+ $this->assertSame(array(
+ 'width' => 80,
+ 'height' => 80,
+ 'type' => IMAGETYPE_JPEG,
+ ),
+ $this->imagesize->getImageSize('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg'));
+ }
+}