diff options
Diffstat (limited to 'tests/upload')
| -rw-r--r-- | tests/upload/filespec_test.php | 11 | ||||
| -rw-r--r-- | tests/upload/fileupload_test.php | 22 | ||||
| -rw-r--r-- | tests/upload/fixture/bmp | bin | 0 -> 64 bytes | |||
| -rw-r--r-- | tests/upload/fixture/iff | bin | 0 -> 120 bytes | |||
| -rw-r--r-- | tests/upload/fixture/iff_maya | bin | 0 -> 88 bytes | |||
| -rw-r--r-- | tests/upload/fixture/jp2 | bin | 0 -> 528 bytes | |||
| -rw-r--r-- | tests/upload/fixture/jpx | bin | 0 -> 528 bytes | |||
| -rw-r--r-- | tests/upload/fixture/psd | bin | 0 -> 6374 bytes | |||
| -rw-r--r-- | tests/upload/fixture/tif_compressed | bin | 0 -> 236 bytes | |||
| -rw-r--r-- | tests/upload/fixture/tif_msb | bin | 0 -> 222 bytes | |||
| -rw-r--r-- | tests/upload/fixture/wbmp | bin | 0 -> 5 bytes | |||
| -rw-r--r-- | tests/upload/imagesize_test.php | 99 | 
12 files changed, 119 insertions, 13 deletions
| diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index ed28bcb38f..f953970f64 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -23,6 +23,7 @@ class phpbb_filespec_test extends phpbb_test_case  	const UPLOAD_MAX_FILESIZE = 1000;  	private $config; +	private $filesystem;  	public $path;  	protected function setUp() @@ -30,7 +31,7 @@ class phpbb_filespec_test extends phpbb_test_case  		// Global $config required by unique_id  		// Global $user required by filespec::additional_checks and  		// filespec::move_file -		global $config, $user; +		global $config, $user, $phpbb_filesystem;  		if (!is_array($config))  		{ @@ -75,6 +76,8 @@ class phpbb_filespec_test extends phpbb_test_case  		$guessers[2]->set_priority(-2);  		$guessers[3]->set_priority(-2);  		$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); + +		$this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem();  	}  	private function get_filespec($override = array()) @@ -88,7 +91,7 @@ class phpbb_filespec_test extends phpbb_test_case  			'error' => '',  		); -		return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser); +		return new filespec(array_merge($upload_ary, $override), null, $this->filesystem, $this->mimetype_guesser);  	}  	protected function tearDown() @@ -198,7 +201,7 @@ class phpbb_filespec_test extends phpbb_test_case  			$filespec = $this->get_filespec();  			$filespec->clean_filename('unique', self::PREFIX);  			$name = $filespec->realname; -			 +  			$this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));  			$this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));  			$this->assertFalse(isset($filenames[$name])); @@ -286,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/fileupload_test.php b/tests/upload/fileupload_test.php index fcfb84125d..9de384b64f 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -20,12 +20,14 @@ class phpbb_fileupload_test extends phpbb_test_case  {  	private $path; +	private $filesystem; +  	protected function setUp()  	{  		// Global $config required by unique_id  		// Global $user required by several functions dealing with translations  		// Global $request required by form_upload, local_upload and is_valid -		global $config, $user, $request; +		global $config, $user, $request, $phpbb_filesystem;  		if (!is_array($config))  		{ @@ -40,6 +42,8 @@ class phpbb_fileupload_test extends phpbb_test_case  		$request = new phpbb_mock_request(); +		$this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); +  		$this->path = __DIR__ . '/fixture/';  	} @@ -65,7 +69,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_invalid_extension()  	{ -		$upload = new fileupload('', array('png'), 100); +		$upload = new fileupload($this->filesystem, '', array('png'), 100);  		$file = $this->gen_valid_filespec();  		$upload->common_checks($file);  		$this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); @@ -73,7 +77,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_invalid_filename()  	{ -		$upload = new fileupload('', array('jpg'), 100); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 100);  		$file = $this->gen_valid_filespec();  		$file->realname = 'invalid?';  		$upload->common_checks($file); @@ -82,7 +86,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_too_large()  	{ -		$upload = new fileupload('', array('jpg'), 100); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 100);  		$file = $this->gen_valid_filespec();  		$file->filesize = 1000;  		$upload->common_checks($file); @@ -91,7 +95,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_common_checks_valid_file()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		$file = $this->gen_valid_filespec();  		$upload->common_checks($file);  		$this->assertEquals(0, sizeof($file->error)); @@ -99,7 +103,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_local_upload()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		copy($this->path . 'jpg', $this->path . 'jpg.jpg');  		$file = $upload->local_upload($this->path . 'jpg.jpg'); @@ -109,7 +113,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_move_existent_file()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		copy($this->path . 'jpg', $this->path . 'jpg.jpg');  		$file = $upload->local_upload($this->path . 'jpg.jpg'); @@ -121,7 +125,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_move_existent_file_overwrite()  	{ -		$upload = new fileupload('', array('jpg'), 1000); +		$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);  		copy($this->path . 'jpg', $this->path . 'jpg.jpg');  		copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg'); @@ -134,7 +138,7 @@ class phpbb_fileupload_test extends phpbb_test_case  	public function test_valid_dimensions()  	{ -		$upload = new fileupload('', false, false, 1, 1, 100, 100); +		$upload = new fileupload($this->filesystem, '', false, false, 1, 1, 100, 100);  		$file1 = $this->gen_valid_filespec();  		$file2 = $this->gen_valid_filespec(); diff --git a/tests/upload/fixture/bmp b/tests/upload/fixture/bmpBinary files differ new file mode 100644 index 0000000000..04bff561ab --- /dev/null +++ b/tests/upload/fixture/bmp diff --git a/tests/upload/fixture/iff b/tests/upload/fixture/iffBinary files differ new file mode 100644 index 0000000000..24eda8f593 --- /dev/null +++ b/tests/upload/fixture/iff diff --git a/tests/upload/fixture/iff_maya b/tests/upload/fixture/iff_mayaBinary files differ new file mode 100644 index 0000000000..b6fb85101b --- /dev/null +++ b/tests/upload/fixture/iff_maya diff --git a/tests/upload/fixture/jp2 b/tests/upload/fixture/jp2Binary files differ new file mode 100644 index 0000000000..adca6ecf0e --- /dev/null +++ b/tests/upload/fixture/jp2 diff --git a/tests/upload/fixture/jpx b/tests/upload/fixture/jpxBinary files differ new file mode 100644 index 0000000000..adca6ecf0e --- /dev/null +++ b/tests/upload/fixture/jpx diff --git a/tests/upload/fixture/psd b/tests/upload/fixture/psdBinary files differ new file mode 100644 index 0000000000..d1bc9a6a70 --- /dev/null +++ b/tests/upload/fixture/psd diff --git a/tests/upload/fixture/tif_compressed b/tests/upload/fixture/tif_compressedBinary files differ new file mode 100644 index 0000000000..133b50c4f0 --- /dev/null +++ b/tests/upload/fixture/tif_compressed diff --git a/tests/upload/fixture/tif_msb b/tests/upload/fixture/tif_msbBinary files differ new file mode 100644 index 0000000000..32eb8abfbb --- /dev/null +++ b/tests/upload/fixture/tif_msb diff --git a/tests/upload/fixture/wbmp b/tests/upload/fixture/wbmpBinary files differ new file mode 100644 index 0000000000..708c86ccee --- /dev/null +++ b/tests/upload/fixture/wbmp 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')); +	} +} | 
