From 57de89628622a80fcb386c0d95724fe4c6148929 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 14 Aug 2015 09:10:05 +0200 Subject: [ticket/13904] Remove unneeded parameters from avatars and fix tests PHPBB3-13904 --- tests/avatar/manager_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 9804869c81..faf6976028 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -73,6 +73,8 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case ->will($this->returnValue('avatar.driver.barfoo')); $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo); + $files_factory = new \phpbb\files\factory($phpbb_container); + foreach ($this->avatar_drivers() as $driver) { if ($driver !== 'upload') @@ -81,7 +83,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case } else { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $filesystem, $path_helper, $guesser, $dispatcher, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $dispatcher, $files_factory, $cache)); } $cur_avatar->expects($this->any()) ->method('get_name') -- cgit v1.2.1 From 2915647a546b4c0733a0e1a0cdc924272e41615b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 00:29:03 +0200 Subject: [ticket/13904] Fix filespec tests PHPBB3-13904 --- tests/upload/filespec_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index f953970f64..f3260bf1a9 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -91,7 +91,8 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - return new filespec(array_merge($upload_ary, $override), null, $this->filesystem, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->mimetype_guesser); + return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } protected function tearDown() @@ -226,7 +227,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_get_extension($filename, $expected) { - $this->assertEquals($expected, filespec::get_extension($filename)); + $this->assertEquals($expected, \phpbb\files\filespec::get_extension($filename)); } public function is_image_variables() -- cgit v1.2.1 From dbfdb61f829166989149ac26bda36bbb4642e1af Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 00:45:56 +0200 Subject: [ticket/13904] Fix fileupload tests PHPBB3-13904 --- tests/upload/fileupload_test.php | 42 +++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 9de384b64f..fe6096aebf 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -27,7 +27,7 @@ class phpbb_fileupload_test extends phpbb_test_case // 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, $phpbb_filesystem; + global $config, $user, $request, $phpbb_filesystem, $phpbb_container; if (!is_array($config)) { @@ -44,6 +44,13 @@ class phpbb_fileupload_test extends phpbb_test_case $this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_container = new phpbb_mock_container_builder($this->phpbb_root_path, $this->phpEx); + $phpbb_container->set('files.filespec', new \phpbb\files\filespec( + $this->filesystem, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + )))); + $this->path = __DIR__ . '/fixture/'; } @@ -69,7 +76,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new fileupload($this->filesystem, '', array('png'), 100); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('png')) + ->set_max_filesize(100); $file = $this->gen_valid_filespec(); $upload->common_checks($file); $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); @@ -77,7 +86,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 100); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(100); $file = $this->gen_valid_filespec(); $file->realname = 'invalid?'; $upload->common_checks($file); @@ -86,7 +97,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 100); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(100); $file = $this->gen_valid_filespec(); $file->filesize = 1000; $upload->common_checks($file); @@ -95,7 +108,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 1000); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); $upload->common_checks($file); $this->assertEquals(0, sizeof($file->error)); @@ -103,7 +118,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 1000); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); $file = $upload->local_upload($this->path . 'jpg.jpg'); @@ -113,7 +130,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 1000); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); $file = $upload->local_upload($this->path . 'jpg.jpg'); @@ -125,7 +144,9 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 1000); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg'); @@ -138,7 +159,10 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new fileupload($this->filesystem, '', false, false, 1, 1, 100, 100); + $upload = new \phpbb\files\upload($this->filesystem); + $upload->set_allowed_extensions(false) + ->set_max_filesize(false) + ->set_allowed_dimensions(1, 1, 100, 100); $file1 = $this->gen_valid_filespec(); $file2 = $this->gen_valid_filespec(); -- cgit v1.2.1 From f32a94ae5d5df156cc33e34a98d9a2e92385c393 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 14 Aug 2015 09:12:43 +0200 Subject: [ticket/13904] Pass filesystem to upload avatar again PHPBB3-13904 --- tests/avatar/manager_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index faf6976028..9003f72de2 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -83,7 +83,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case } else { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $dispatcher, $files_factory, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $filesystem, $path_helper, $dispatcher, $files_factory, $cache)); } $cur_avatar->expects($this->any()) ->method('get_name') -- cgit v1.2.1 From a53825ad760cc8437d8c26eb1f947622c0fcf229 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 11:48:55 +0200 Subject: [ticket/13904] No longer use fileerror class for extending filespec class PHPBB3-13904 --- tests/upload/fileupload_test.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index fe6096aebf..d4785c782c 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -22,6 +22,12 @@ class phpbb_fileupload_test extends phpbb_test_case private $filesystem; + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \phpbb\files\factory */ + protected $factory; + protected function setUp() { // Global $config required by unique_id @@ -44,12 +50,13 @@ class phpbb_fileupload_test extends phpbb_test_case $this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); - $phpbb_container = new phpbb_mock_container_builder($this->phpbb_root_path, $this->phpEx); - $phpbb_container->set('files.filespec', new \phpbb\files\filespec( + $this->container = new phpbb_mock_container_builder($this->phpbb_root_path, $this->phpEx); + $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), )))); + $this->factory = new \phpbb\files\factory($this->container); $this->path = __DIR__ . '/fixture/'; } @@ -76,7 +83,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('png')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -86,7 +93,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -97,7 +104,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -108,7 +115,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); @@ -118,7 +125,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -130,7 +137,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -144,7 +151,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -159,7 +166,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new \phpbb\files\upload($this->filesystem); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); $upload->set_allowed_extensions(false) ->set_max_filesize(false) ->set_allowed_dimensions(1, 1, 100, 100); -- cgit v1.2.1 From c34fd1e7c030860169bcbde9ac3c4f75d610cd60 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 12:22:14 +0200 Subject: [ticket/13904] Fix fileupload functional tests PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 35 ++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 4aa1a83b30..34e9ca2b05 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -11,15 +11,17 @@ * */ -require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; - /** * @group functional */ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case { + /** @var \phpbb\filesystem\filesystem_interface */ protected $filesystem; + /** @var \phpbb\files\factory */ + protected $factory; + public function setUp() { parent::setUp(); @@ -41,6 +43,11 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); $this->filesystem = new \phpbb\filesystem\filesystem(); + + $container = new phpbb_mock_container_builder(); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem)); + $this->factory = new \phpbb\files\factory($container); + $container->set('files.factory', $this->factory); } public function tearDown() @@ -52,21 +59,33 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 100); + /** @var \phpbb\files\upload $upload */ + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload->set_error_prefix('') + ->set_allowed_extensions(array('jpg')) + ->set_max_filesize(100); $file = $upload->remote_upload(self::$root_url . 'develop/blank.gif'); $this->assertEquals('URL_INVALID', $file->error[0]); } public function test_empty_file() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 100); + /** @var \phpbb\files\upload $upload */ + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload->set_error_prefix('') + ->set_allowed_extensions(array('jpg')) + ->set_max_filesize(100); $file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg'); $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); } public function test_successful_upload() { - $upload = new fileupload($this->filesystem, '', array('gif'), 1000); + /** @var \phpbb\files\upload $upload */ + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload->set_error_prefix('') + ->set_allowed_extensions(array('gif')) + ->set_max_filesize(1000); $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->filename)); @@ -74,7 +93,11 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { - $upload = new fileupload($this->filesystem, '', array('gif'), 100); + /** @var \phpbb\files\upload $upload */ + $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload->set_error_prefix('') + ->set_allowed_extensions(array('gif')) + ->set_max_filesize(100); $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(1, sizeof($file->error)); $this->assertEquals('WRONG_FILESIZE', $file->error[0]); -- cgit v1.2.1 From 25df7f814920a67b1d9b1e65e797c44960026585 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 12:24:31 +0200 Subject: [ticket/13904] Remove functions_fileupload.php PHPBB3-13904 --- tests/upload/filespec_test.php | 1 - tests/upload/fileupload_test.php | 1 - 2 files changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index f3260bf1a9..10577ec8f3 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -13,7 +13,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; -require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; class phpbb_filespec_test extends phpbb_test_case { diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index d4785c782c..8b7056e9cf 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -13,7 +13,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; -require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; require_once __DIR__ . '/../mock/filespec.php'; class phpbb_fileupload_test extends phpbb_test_case -- cgit v1.2.1 From ef59e0228a993bcaf7bf59c7cb24511f3cbe1b78 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 13:42:58 +0200 Subject: [ticket/13904] Fix tests again PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 15 ++++++++++----- tests/upload/fileupload_test.php | 25 +++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 34e9ca2b05..7301297096 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -22,6 +22,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case /** @var \phpbb\files\factory */ protected $factory; + /** @var \phpbb\language\language */ + protected $language; + public function setUp() { parent::setUp(); @@ -30,7 +33,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case // Global $config required by unique_id // Global $user required by fileupload::remote_upload - global $config, $user; + global $config, $user, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -48,6 +51,8 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); + + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); } public function tearDown() @@ -60,7 +65,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -71,7 +76,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_empty_file() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -82,7 +87,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_successful_upload() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); @@ -94,7 +99,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 8b7056e9cf..87e10ac954 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -27,12 +27,15 @@ class phpbb_fileupload_test extends phpbb_test_case /** @var \phpbb\files\factory */ protected $factory; + /** @var \phpbb\language\language */ + protected $language; + 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, $phpbb_filesystem, $phpbb_container; + global $config, $user, $request, $phpbb_filesystem, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -49,7 +52,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); - $this->container = new phpbb_mock_container_builder($this->phpbb_root_path, $this->phpEx); + $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, new \phpbb\mimetype\guesser(array( @@ -57,6 +60,8 @@ class phpbb_fileupload_test extends phpbb_test_case )))); $this->factory = new \phpbb\files\factory($this->container); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->path = __DIR__ . '/fixture/'; } @@ -82,7 +87,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('png')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -92,7 +97,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -103,7 +108,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -114,7 +119,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); @@ -124,7 +129,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -136,7 +141,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -150,7 +155,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -165,7 +170,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); $upload->set_allowed_extensions(false) ->set_max_filesize(false) ->set_allowed_dimensions(1, 1, 100, 100); -- cgit v1.2.1 From 697ac5f4aa151b06ed65f8352652443bf297682a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 15:06:24 +0200 Subject: [ticket/13904] Use language class instead of global user in filespec PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 10 +++------- tests/upload/filespec_test.php | 19 ++++++++----------- tests/upload/fileupload_test.php | 12 ++++-------- 3 files changed, 15 insertions(+), 26 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 7301297096..ae4de26df4 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -32,8 +32,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case // URL // Global $config required by unique_id - // Global $user required by fileupload::remote_upload - global $config, $user, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -43,16 +42,13 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; - $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $container = new phpbb_mock_container_builder(); - $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem)); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); - - $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); } public function tearDown() diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 10577ec8f3..b28adc3f28 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -25,12 +25,13 @@ class phpbb_filespec_test extends phpbb_test_case private $filesystem; public $path; + /** @var \phpbb\language\language */ + protected $language; + protected function setUp() { // Global $config required by unique_id - // Global $user required by filespec::additional_checks and - // filespec::move_file - global $config, $user, $phpbb_filesystem; + global $config, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -44,9 +45,6 @@ class phpbb_filespec_test extends phpbb_test_case // See: phpBB/install/schemas/schema_data.sql $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; - $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); - $this->config = &$config; $this->path = __DIR__ . '/fixture/'; @@ -75,8 +73,9 @@ 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->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); - $this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(); } private function get_filespec($override = array()) @@ -90,15 +89,13 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } protected function tearDown() { - global $user; $this->config = array(); - $user = null; $iterator = new DirectoryIterator($this->path . 'copies'); foreach ($iterator as $fileinfo) @@ -289,7 +286,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 png jpg', true), + array('png_copy', 'png_moved', 'image/png', 'jpg', 'Image file type mismatch: expected extension png but extension jpg given.', true), ); } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 87e10ac954..56e29a3ac2 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -33,9 +33,8 @@ class phpbb_fileupload_test extends phpbb_test_case 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, $phpbb_filesystem, $phpbb_root_path, $phpEx; + global $config, $request, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -45,23 +44,20 @@ class phpbb_fileupload_test extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; - $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); - $request = new phpbb_mock_request(); - $this->filesystem = $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, + $this->language, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), )))); $this->factory = new \phpbb\files\factory($this->container); - $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); - $this->path = __DIR__ . '/fixture/'; } -- cgit v1.2.1 From 47f8f2cc88bdcd40087c8e391be1d33d36a2d308 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 15:24:38 +0200 Subject: [ticket/13904] Pass request service to upload instead of using global PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 12 ++++++++---- tests/upload/fileupload_test.php | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index ae4de26df4..4754153cbf 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -25,6 +25,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case /** @var \phpbb\language\language */ protected $language; + /** @var \phpbb\request\request_interface */ + protected $request; + public function setUp() { parent::setUp(); @@ -44,6 +47,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->request = $this->getMock('\phpbb\request\request'); $container = new phpbb_mock_container_builder(); $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language)); @@ -61,7 +65,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -72,7 +76,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_empty_file() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -83,7 +87,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_successful_upload() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); @@ -95,7 +99,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 56e29a3ac2..deb4404585 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -30,11 +30,13 @@ class phpbb_fileupload_test extends phpbb_test_case /** @var \phpbb\language\language */ protected $language; + /** @var \phpbb\request\request_interface */ + protected $request; + protected function setUp() { // Global $config required by unique_id - // Global $request required by form_upload, local_upload and is_valid - global $config, $request, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -44,7 +46,7 @@ class phpbb_fileupload_test extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; - $request = new phpbb_mock_request(); + $this->request = $this->getMock('\phpbb\request\request'); $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); @@ -83,7 +85,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('png')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -93,7 +95,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -104,7 +106,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -115,7 +117,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); @@ -125,7 +127,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -137,7 +139,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -151,7 +153,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -166,7 +168,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); $upload->set_allowed_extensions(false) ->set_max_filesize(false) ->set_allowed_dimensions(1, 1, 100, 100); -- cgit v1.2.1 From 52652ca1824e91ecfe7549167aebd92c314af678 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 15:29:32 +0200 Subject: [ticket/13904] Remove phpbb_root_path global from upload class PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 12 ++++++++---- tests/upload/fileupload_test.php | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 4754153cbf..a32c339afa 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -28,6 +28,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case /** @var \phpbb\request\request_interface */ protected $request; + /** @var string phpBB root path */ + protected $phpbb_root_path; + public function setUp() { parent::setUp(); @@ -53,6 +56,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); + $this->phpbb_root_path = $phpbb_root_path; } public function tearDown() @@ -65,7 +69,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -76,7 +80,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_empty_file() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -87,7 +91,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_successful_upload() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); @@ -99,7 +103,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index deb4404585..0832f269cb 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -33,6 +33,9 @@ class phpbb_fileupload_test extends phpbb_test_case /** @var \phpbb\request\request_interface */ protected $request; + /** @var string phpBB root path */ + protected $phpbb_root_path; + protected function setUp() { // Global $config required by unique_id @@ -61,6 +64,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->factory = new \phpbb\files\factory($this->container); $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; } private function gen_valid_filespec() @@ -85,7 +89,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -95,7 +99,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -106,7 +110,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -117,7 +121,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); @@ -127,7 +131,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -139,7 +143,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -153,7 +157,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -168,7 +172,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(false) ->set_max_filesize(false) ->set_allowed_dimensions(1, 1, 100, 100); -- cgit v1.2.1 From b871dbcf1f2d0483cbe19cddf94a5bdc9659ab00 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 15:46:41 +0200 Subject: [ticket/13904] Remove phpbb_root_path global from filespec class PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 2 +- tests/upload/filespec_test.php | 11 +++++++---- tests/upload/fileupload_test.php | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index a32c339afa..f69ba9f122 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -53,7 +53,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->request = $this->getMock('\phpbb\request\request'); $container = new phpbb_mock_container_builder(); - $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language)); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); $this->phpbb_root_path = $phpbb_root_path; diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index b28adc3f28..b0df72a6ff 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -28,6 +28,9 @@ class phpbb_filespec_test extends phpbb_test_case /** @var \phpbb\language\language */ protected $language; + /** @var string phpBB root path */ + protected $phpbb_root_path; + protected function setUp() { // Global $config required by unique_id @@ -76,6 +79,7 @@ class phpbb_filespec_test extends phpbb_test_case $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->phpbb_root_path = $phpbb_root_path; } private function get_filespec($override = array()) @@ -89,7 +93,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } @@ -297,8 +301,7 @@ class phpbb_filespec_test extends phpbb_test_case { // Global $phpbb_root_path and $phpEx are required by phpbb_chmod global $phpbb_root_path, $phpEx; - $phpbb_root_path = ''; - $phpEx = 'php'; + $this->phpbb_root_path = ''; $upload = new phpbb_mock_fileupload(); $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; @@ -319,7 +322,7 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($error, $filespec->error[0]); } - $phpEx = ''; + $this->phpbb_root_path = $phpbb_root_path; } /** diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 0832f269cb..c62e9a1947 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -58,6 +58,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, $this->language, + $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), )))); -- cgit v1.2.1 From c65f0d748ae3cef90e08ce2c700e65734392da45 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Jun 2015 15:58:57 +0200 Subject: [ticket/13904] Add more tests for upload class PHPBB3-13904 --- tests/files/upload_test.php | 96 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/files/upload_test.php (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php new file mode 100644 index 0000000000..4323f6cc92 --- /dev/null +++ b/tests/files/upload_test.php @@ -0,0 +1,96 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_files_upload_test extends phpbb_test_case +{ + private $path; + + private $filesystem; + + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \phpbb\files\factory */ + protected $factory; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\request\request_interface */ + protected $request; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + + protected function setUp() + { + // Global $config required by unique_id + global $config, $phpbb_root_path, $phpEx; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + $this->request = $this->getMock('\phpbb\request\request'); + + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + + $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); + $this->container->set('files.filespec', new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + )))); + $this->factory = new \phpbb\files\factory($this->container); + + $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; + } + + public function test_reset_vars() + { + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload->set_max_filesize(500); + $this->assertEquals(500, $upload->max_filesize); + $upload->reset_vars(); + $this->assertEquals(0, $upload->max_filesize); + } + + public function test_set_disallowed_content() + { + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload->set_disallowed_content(array('foo')); + $this->assertEquals(array('foo'), $upload->disallowed_content); + $upload->set_disallowed_content(array('foo', 'bar', 'meh')); + $this->assertEquals(array('foo', 'bar', 'meh'), $upload->disallowed_content); + $upload->set_disallowed_content(''); + $this->assertEquals(array('foo', 'bar', 'meh'), $upload->disallowed_content); + $this->assertINstanceOf('\phpbb\files\upload', $upload->set_disallowed_content(array())); + $this->assertEquals(array(), $upload->disallowed_content); + $upload->reset_vars(); + $this->assertEquals(array(), $upload->disallowed_content); + } + + public function test_is_valid() + { + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $this->assertFalse($upload->is_valid('foobar')); + } +} -- cgit v1.2.1 From adcc901af181b6727dd7af89a3926c9923a58471 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 15 Jul 2015 16:08:20 +0200 Subject: [ticket/13904] Fix minor issues and move local_upload to its own class PHPBB3-13904 --- tests/upload/fileupload_test.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index c62e9a1947..7a84b34473 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -43,7 +43,7 @@ class phpbb_fileupload_test extends phpbb_test_case if (!is_array($config)) { - $config = array(); + $config = new \phpbb\config\config(array()); } $config['rand_seed'] = ''; @@ -53,6 +53,15 @@ class phpbb_fileupload_test extends phpbb_test_case $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $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); $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( @@ -63,6 +72,18 @@ class phpbb_fileupload_test extends phpbb_test_case 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), )))); $this->factory = new \phpbb\files\factory($this->container); + $plupload = new \phpbb\plupload\plupload($phpbb_root_path, $config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), new \phpbb\php\ini(), $this->mimetype_guesser); + $this->container->set('files.types.form', new \phpbb\files\types\form( + $this->factory, + $this->language, + $plupload, + $this->request + ), phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $this->container->set('files.types.local', new \phpbb\files\types\local( + $this->factory, + $this->language, + $this->request + ), phpbb_mock_container_builder::SCOPE_PROTOTYPE); $this->path = __DIR__ . '/fixture/'; $this->phpbb_root_path = $phpbb_root_path; @@ -137,7 +158,7 @@ class phpbb_fileupload_test extends phpbb_test_case ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); - $file = $upload->local_upload($this->path . 'jpg.jpg'); + $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); unlink($this->path . 'jpg.jpg'); } @@ -149,7 +170,7 @@ class phpbb_fileupload_test extends phpbb_test_case ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); - $file = $upload->local_upload($this->path . 'jpg.jpg'); + $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); $this->assertFalse($file->move_file('../tests/upload/fixture')); $this->assertFalse($file->file_moved); @@ -164,7 +185,7 @@ class phpbb_fileupload_test extends phpbb_test_case copy($this->path . 'jpg', $this->path . 'jpg.jpg'); copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg'); - $file = $upload->local_upload($this->path . 'jpg.jpg'); + $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); $file->move_file('../tests/upload/fixture/copies', true); $this->assertEquals(0, sizeof($file->error)); -- cgit v1.2.1 From 57ccfe0c483254e54b7b40bc1906ef946daf4f55 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 15 Jul 2015 18:00:52 +0200 Subject: [ticket/13904] Move remote upload to its own type class PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index f69ba9f122..0f1e4d6e59 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -73,7 +73,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); - $file = $upload->remote_upload(self::$root_url . 'develop/blank.gif'); + $file = $upload->handle_upload('remote', self::$root_url . 'develop/blank.gif'); $this->assertEquals('URL_INVALID', $file->error[0]); } @@ -84,7 +84,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); - $file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg'); + $file = $upload->handle_upload('remote', self::$root_url . 'develop/blank.jpg'); $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); } @@ -95,7 +95,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); - $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->filename)); } @@ -107,7 +107,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); - $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(1, sizeof($file->error)); $this->assertEquals('WRONG_FILESIZE', $file->error[0]); } -- cgit v1.2.1 From 759a1a09fae5147afe346729764f050ecc67076b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 15 Jul 2015 21:30:42 +0200 Subject: [ticket/13904] Fix remote upload functional tests PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 0f1e4d6e59..1bb63719c6 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -56,6 +56,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); + $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request)); $this->phpbb_root_path = $phpbb_root_path; } -- cgit v1.2.1 From a09c6d1fb760151b1a6c654b597b4578c3136be1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 15 Jul 2015 23:10:23 +0200 Subject: [ticket/13904] Split code up and pass root path to remote upload type PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 1bb63719c6..a754d8c91d 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -56,7 +56,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); - $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request)); + $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request, $phpbb_root_path)); $this->phpbb_root_path = $phpbb_root_path; } -- cgit v1.2.1 From 845233fc626b0d5e6d9e61039fde8e31b4dd28aa Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 16 Jul 2015 00:21:23 +0200 Subject: [ticket/13904] Improve test coverage and use constants instead of magic numbers PHPBB3-13904 --- tests/files/upload_test.php | 23 +++++++++++++++++++++++ tests/upload/fileupload_test.php | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index 4323f6cc92..057bb8a4f2 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -93,4 +93,27 @@ class phpbb_files_upload_test extends phpbb_test_case $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); $this->assertFalse($upload->is_valid('foobar')); } + + public function data_internal_error() + { + return array( + array(UPLOAD_ERR_INI_SIZE, 'PHP_SIZE_OVERRUN'), + array(UPLOAD_ERR_FORM_SIZE, 'WRONG_FILESIZE'), + array(UPLOAD_ERR_PARTIAL, 'PARTIAL_UPLOAD'), + array(UPLOAD_ERR_NO_FILE, 'NOT_UPLOADED'), + array(UPLOAD_ERR_NO_TMP_DIR, 'Temporary folder could not be found. Please check your PHP installation.'), + array(UPLOAD_ERR_CANT_WRITE, 'Can’t write to temporary folder.'), + array(UPLOAD_ERR_EXTENSION, 'A PHP extension has stopped the file upload.'), + array(9, false), + ); + } + + /** + * @dataProvider data_internal_error + */ + public function test_assign_internal_error($error_code, $expected) + { + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $this->assertSame($expected, $upload->assign_internal_error($error_code)); + } } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 7a84b34473..ab42a4a153 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -119,6 +119,25 @@ class phpbb_fileupload_test extends phpbb_test_case $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); } + public function test_common_checks_disallowed_content() + { + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('jpg')) + ->set_max_filesize(1000); + $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path); + $file->set_upload_ary(array( + 'size' => 50, + 'tmp_name' => dirname(__FILE__) . '/fixture/disallowed', + 'name' => 'disallowed.jpg', + 'type' => 'image/jpg' + )) + ->set_upload_namespace($upload); + file_put_contents(dirname(__FILE__) . '/fixture/disallowed', '' . file_get_contents(dirname(__FILE__) . '/fixture/jpg')); + $upload->common_checks($file); + $this->assertEquals('DISALLOWED_CONTENT', $file->error[0]); + unlink(dirname(__FILE__) . '/fixture/disallowed'); + } + public function test_common_checks_invalid_filename() { $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); -- cgit v1.2.1 From 3e99816fa2f184b859d47308254aa8f07d68f1dd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 16 Jul 2015 12:06:23 +0200 Subject: [ticket/13904] Set visibility in files and improve test coverage PHPBB3-13904 --- tests/files/upload_test.php | 13 ++++--- tests/functional/fileupload_remote_test.php | 2 +- tests/upload/filespec_test.php | 60 ++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index 057bb8a4f2..dc0080d25c 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -76,16 +76,19 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_set_disallowed_content() { $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $disallowed_content = new ReflectionProperty($upload, 'disallowed_content'); + $disallowed_content->setAccessible(true); + $upload->set_disallowed_content(array('foo')); - $this->assertEquals(array('foo'), $upload->disallowed_content); + $this->assertEquals(array('foo'), $disallowed_content->getValue($upload)); $upload->set_disallowed_content(array('foo', 'bar', 'meh')); - $this->assertEquals(array('foo', 'bar', 'meh'), $upload->disallowed_content); + $this->assertEquals(array('foo', 'bar', 'meh'), $disallowed_content->getValue($upload)); $upload->set_disallowed_content(''); - $this->assertEquals(array('foo', 'bar', 'meh'), $upload->disallowed_content); + $this->assertEquals(array('foo', 'bar', 'meh'), $disallowed_content->getValue($upload)); $this->assertINstanceOf('\phpbb\files\upload', $upload->set_disallowed_content(array())); - $this->assertEquals(array(), $upload->disallowed_content); + $this->assertEquals(array(), $disallowed_content->getValue($upload)); $upload->reset_vars(); - $this->assertEquals(array(), $upload->disallowed_content); + $this->assertEquals(array(), $disallowed_content->getValue($upload)); } public function test_is_valid() diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index a754d8c91d..a6aa233aaf 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -98,7 +98,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case ->set_max_filesize(1000); $file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); - $this->assertTrue(file_exists($file->filename)); + $this->assertTrue(file_exists($file->get('filename'))); } public function test_too_large() diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index b0df72a6ff..f885b1acfc 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -133,7 +133,7 @@ class phpbb_filespec_test extends phpbb_test_case { $upload = new phpbb_mock_fileupload(); $filespec = $this->get_filespec(); - $filespec->upload = $upload; + $filespec->set_upload_namespace($upload); $filespec->file_moved = true; $filespec->filesize = $filespec->get_filesize($this->path . $filename); @@ -174,6 +174,7 @@ class phpbb_filespec_test extends phpbb_test_case array($chunks[2] . $chunks[9]), array($chunks[3] . $chunks[4]), array($chunks[5] . $chunks[6]), + array('foobar.png'), ); } @@ -185,7 +186,7 @@ class phpbb_filespec_test extends phpbb_test_case $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); $filespec = $this->get_filespec(array('name' => $filename)); $filespec->clean_filename('real', self::PREFIX); - $name = $filespec->realname; + $name = $filespec->get('realname'); $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); foreach ($bad_chars as $char) @@ -201,7 +202,7 @@ class phpbb_filespec_test extends phpbb_test_case { $filespec = $this->get_filespec(); $filespec->clean_filename('unique', self::PREFIX); - $name = $filespec->realname; + $name = $filespec->get('realname'); $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); @@ -210,6 +211,55 @@ class phpbb_filespec_test extends phpbb_test_case } } + public function test_clean_filename_unique_ext() + { + $filenames = array(); + for ($tests = 0; $tests < self::TEST_COUNT; $tests++) + { + $filespec = $this->get_filespec(array('name' => 'foobar.jpg')); + $filespec->clean_filename('unique_ext', self::PREFIX); + $name = $filespec->get('realname'); + + $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX) + strlen('.jpg')); + $this->assertRegExp('#^[A-Za-z0-9]+\.jpg$#', substr($name, strlen(self::PREFIX))); + $this->assertFalse(isset($filenames[$name])); + $filenames[$name] = true; + } + } + + public function data_clean_filename_avatar() + { + return array( + array(false, false, ''), + array('foobar.png', 'u5.png', 'avatar', 'u', 5), + array('foobar.png', 'g9.png', 'avatar', 'g', 9), + + ); + } + + /** + * @dataProvider data_clean_filename_avatar + */ + public function test_clean_filename_avatar($filename, $expected, $mode, $prefix = '', $user_id = '') + { + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + + if ($filename) + { + $upload_ary = array( + 'name' => $filename, + 'type' => '', + 'size' => '', + 'tmp_name' => '', + 'error' => '', + ); + $filespec->set_upload_ary($upload_ary); + } + $filespec->clean_filename($mode, $prefix, $user_id); + + $this->assertSame($expected, $filespec->get('realname')); + } + public function get_extension_variables() { return array( @@ -312,7 +362,7 @@ class phpbb_filespec_test extends phpbb_test_case 'type' => $mime_type, )); $filespec->extension = $extension; - $filespec->upload = $upload; + $filespec->set_upload_namespace($upload); $filespec->local = true; $this->assertEquals($expected, $filespec->move_file($this->path . 'copies')); @@ -336,6 +386,6 @@ class phpbb_filespec_test extends phpbb_test_case $type_cast_helper->set_var($upload_name, $filename, 'string', true, true); $filespec = $this->get_filespec(array('name'=> $upload_name)); - $this->assertSame(trim(utf8_basename(htmlspecialchars($filename))), $filespec->uploadname); + $this->assertSame(trim(utf8_basename(htmlspecialchars($filename))), $filespec->get('uploadname')); } } -- cgit v1.2.1 From 46e3d8219671e996677be1943a7e3c80f1039693 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 16 Jul 2015 16:30:59 +0200 Subject: [ticket/13904] Add more tests and test cases PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 1 + tests/mock/fileupload.php | 3 +- tests/upload/filespec_test.php | 43 +++++++++++++++++++++++++++++ tests/upload/fileupload_test.php | 4 ++- 4 files changed, 49 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index a6aa233aaf..1a74b3b498 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -99,6 +99,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->get('filename'))); + $this->assertTrue($file->is_uploaded()); } public function test_too_large() diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php index 8cc4d77ea1..5a0afc6cd3 100644 --- a/tests/mock/fileupload.php +++ b/tests/mock/fileupload.php @@ -19,9 +19,10 @@ class phpbb_mock_fileupload { public $max_filesize = 100; public $error_prefix = ''; + public $valid_dimensions = true; public function valid_dimensions($filespec) { - return true; + return $this->valid_dimensions; } } diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index f885b1acfc..a6ea850763 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -112,6 +112,13 @@ class phpbb_filespec_test extends phpbb_test_case } } + public function test_empty_upload_ary() + { + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array())); + $this->assertTrue($filespec->init_error()); + } + public function additional_checks_variables() { // False here just indicates the file is too large and fails the @@ -140,6 +147,19 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $filespec->additional_checks()); } + public function test_additional_checks_dimensions() + { + $upload = new phpbb_mock_fileupload(); + $filespec = $this->get_filespec(); + $filespec->set_upload_namespace($upload); + $upload->valid_dimensions = false; + $filespec->file_moved = true; + $upload->max_filesize = 0; + + $this->assertEquals(false, $filespec->additional_checks()); + $this->assertSame(array('WRONG_SIZE'), $filespec->error); + } + public function check_content_variables() { // False here indicates that a file is non-binary and contains @@ -388,4 +408,27 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertSame(trim(utf8_basename(htmlspecialchars($filename))), $filespec->get('uploadname')); } + + public function test_is_uploaded() + { + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, null); + $reflection_filespec = new ReflectionClass($filespec); + $plupload_property = $reflection_filespec->getProperty('plupload'); + $plupload_property->setAccessible(true); + $plupload_mock = $this->getMockBuilder('\phpbb\plupload\plupload') + ->disableOriginalConstructor() + ->getMock(); + $plupload_mock->expects($this->any()) + ->method('is_active') + ->will($this->returnValue(true)); + $plupload_property->setValue($filespec, $plupload_mock); + $is_uploaded = $reflection_filespec->getMethod('is_uploaded'); + + // Plupload is active and file does not exist + $this->assertFalse($is_uploaded->invoke($filespec)); + + // Plupload is not active and file was not uploaded + $plupload_property->setValue($filespec, null); + $this->assertFalse($is_uploaded->invoke($filespec)); + } } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index ab42a4a153..d1d8b55ff3 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -179,7 +179,9 @@ class phpbb_fileupload_test extends phpbb_test_case copy($this->path . 'jpg', $this->path . 'jpg.jpg'); $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); - unlink($this->path . 'jpg.jpg'); + $this->assertFalse($file->additional_checks()); + $this->assertTrue($file->move_file('../tests/upload/fixture/copies', true)); + $file->remove(); } public function test_move_existent_file() -- cgit v1.2.1 From 7ba0fe47a8610b1bd882f00cd1e158c7b29d248c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 17 Jul 2015 09:29:09 +0200 Subject: [ticket/13904] Test move file on existing error PHPBB3-13904 --- tests/upload/filespec_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index a6ea850763..1ba473555f 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -395,6 +395,14 @@ class phpbb_filespec_test extends phpbb_test_case $this->phpbb_root_path = $phpbb_root_path; } + public function test_move_file_error() + { + $filespec = $this->get_filespec(); + $this->assertFalse($filespec->move_file('foobar')); + $filespec->error[] = 'foo'; + $this->assertFalse($filespec->move_file('foo')); + } + /** * @dataProvider clean_filename_variables */ -- cgit v1.2.1 From cdde86ce7e0c594fad5992789b3fae466bd526cc Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 26 Aug 2015 13:57:42 +0200 Subject: [ticket/13904] Use \phpbb\php\ini class for ini_get() PHPBB3-13904 --- tests/files/upload_test.php | 13 +++++++++---- tests/functional/fileupload_remote_test.php | 14 +++++++++----- tests/upload/filespec_test.php | 8 ++++---- tests/upload/fileupload_test.php | 27 ++++++++++++++++----------- 4 files changed, 38 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index dc0080d25c..d11ebc742b 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -23,6 +23,9 @@ class phpbb_files_upload_test extends phpbb_test_case /** @var \phpbb\files\factory */ protected $factory; + /** @var \phpbb\php\ini */ + protected $php_ini; + /** @var \phpbb\language\language */ protected $language; @@ -49,10 +52,12 @@ class phpbb_files_upload_test extends phpbb_test_case $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->php_ini = new \phpbb\php\ini; $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, + $this->php_ini, $this->language, $phpbb_root_path, new \phpbb\mimetype\guesser(array( @@ -66,7 +71,7 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_reset_vars() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_max_filesize(500); $this->assertEquals(500, $upload->max_filesize); $upload->reset_vars(); @@ -75,7 +80,7 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_set_disallowed_content() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $disallowed_content = new ReflectionProperty($upload, 'disallowed_content'); $disallowed_content->setAccessible(true); @@ -93,7 +98,7 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_is_valid() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $this->assertFalse($upload->is_valid('foobar')); } @@ -116,7 +121,7 @@ class phpbb_files_upload_test extends phpbb_test_case */ public function test_assign_internal_error($error_code, $expected) { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $this->assertSame($expected, $upload->assign_internal_error($error_code)); } } diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 1a74b3b498..45c1e914c2 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -22,6 +22,9 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case /** @var \phpbb\files\factory */ protected $factory; + /** @var \phpbb\php\ini */ + protected $php_ini; + /** @var \phpbb\language\language */ protected $language; @@ -51,9 +54,10 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->request = $this->getMock('\phpbb\request\request'); + $this->php_ini = new \phpbb\php\ini; $container = new phpbb_mock_container_builder(); - $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path)); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->php_ini, $this->language, $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request, $phpbb_root_path)); @@ -70,7 +74,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -81,7 +85,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_empty_file() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -92,7 +96,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_successful_upload() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); @@ -105,7 +109,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 1ba473555f..8a9e53f30b 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -93,7 +93,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } @@ -114,7 +114,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_empty_upload_ary() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); $this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array())); $this->assertTrue($filespec->init_error()); } @@ -262,7 +262,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_clean_filename_avatar($filename, $expected, $mode, $prefix = '', $user_id = '') { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); if ($filename) { @@ -419,7 +419,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_is_uploaded() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path, null); + $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, null); $reflection_filespec = new ReflectionClass($filespec); $plupload_property = $reflection_filespec->getProperty('plupload'); $plupload_property->setAccessible(true); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index d1d8b55ff3..957fb47755 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -27,6 +27,9 @@ class phpbb_fileupload_test extends phpbb_test_case /** @var \phpbb\files\factory */ protected $factory; + /** @var \phpbb\php\ini */ + protected $php_ini; + /** @var \phpbb\language\language */ protected $language; @@ -50,6 +53,7 @@ class phpbb_fileupload_test extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; $this->request = $this->getMock('\phpbb\request\request'); + $this->php_ini = new \phpbb\php\ini; $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); @@ -66,13 +70,14 @@ class phpbb_fileupload_test extends phpbb_test_case $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, + $this->php_ini, $this->language, $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), )))); $this->factory = new \phpbb\files\factory($this->container); - $plupload = new \phpbb\plupload\plupload($phpbb_root_path, $config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), new \phpbb\php\ini(), $this->mimetype_guesser); + $plupload = new \phpbb\plupload\plupload($phpbb_root_path, $config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), $this->php_ini, $this->mimetype_guesser); $this->container->set('files.types.form', new \phpbb\files\types\form( $this->factory, $this->language, @@ -111,7 +116,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -121,10 +126,10 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_disallowed_content() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); - $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->phpbb_root_path); + $file = new \phpbb\files\filespec($this->filesystem, $this->php_ini, $this->language, $this->phpbb_root_path); $file->set_upload_ary(array( 'size' => 50, 'tmp_name' => dirname(__FILE__) . '/fixture/disallowed', @@ -140,7 +145,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -151,7 +156,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -162,7 +167,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); @@ -172,7 +177,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -186,7 +191,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -200,7 +205,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -215,7 +220,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(false) ->set_max_filesize(false) ->set_allowed_dimensions(1, 1, 100, 100); -- cgit v1.2.1 From 36545d5cbe7188efbedf2e1f44b1a7b9617b50c1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 26 Aug 2015 16:18:10 +0200 Subject: [ticket/13904] Switch around constructor arguments PHPBB3-13904 --- tests/files/upload_test.php | 10 +++++----- tests/functional/fileupload_remote_test.php | 10 +++++----- tests/upload/filespec_test.php | 8 ++++---- tests/upload/fileupload_test.php | 22 +++++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index d11ebc742b..6f4a10e6aa 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -57,8 +57,8 @@ class phpbb_files_upload_test extends phpbb_test_case $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, - $this->php_ini, $this->language, + $this->php_ini, $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), @@ -71,7 +71,7 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_reset_vars() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_max_filesize(500); $this->assertEquals(500, $upload->max_filesize); $upload->reset_vars(); @@ -80,7 +80,7 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_set_disallowed_content() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $disallowed_content = new ReflectionProperty($upload, 'disallowed_content'); $disallowed_content->setAccessible(true); @@ -98,7 +98,7 @@ class phpbb_files_upload_test extends phpbb_test_case public function test_is_valid() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $this->assertFalse($upload->is_valid('foobar')); } @@ -121,7 +121,7 @@ class phpbb_files_upload_test extends phpbb_test_case */ public function test_assign_internal_error($error_code, $expected) { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $this->assertSame($expected, $upload->assign_internal_error($error_code)); } } diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 45c1e914c2..4fd8ae1f19 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -57,7 +57,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->php_ini = new \phpbb\php\ini; $container = new phpbb_mock_container_builder(); - $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->php_ini, $this->language, $this->phpbb_root_path)); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request, $phpbb_root_path)); @@ -74,7 +74,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -85,7 +85,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_empty_file() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); @@ -96,7 +96,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_successful_upload() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); @@ -109,7 +109,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { /** @var \phpbb\files\upload $upload */ - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 8a9e53f30b..595439c917 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -93,7 +93,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } @@ -114,7 +114,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_empty_upload_ary() { - $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, $this->mimetype_guesser); $this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array())); $this->assertTrue($filespec->init_error()); } @@ -262,7 +262,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_clean_filename_avatar($filename, $expected, $mode, $prefix = '', $user_id = '') { - $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, $this->mimetype_guesser); if ($filename) { @@ -419,7 +419,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_is_uploaded() { - $filespec = new \phpbb\files\filespec($this->filesystem, new \phpbb\php\ini, $this->language, $this->phpbb_root_path, null); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, null); $reflection_filespec = new ReflectionClass($filespec); $plupload_property = $reflection_filespec->getProperty('plupload'); $plupload_property->setAccessible(true); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 957fb47755..40f8704271 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -70,8 +70,8 @@ class phpbb_fileupload_test extends phpbb_test_case $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( $this->filesystem, - $this->php_ini, $this->language, + $this->php_ini, $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), @@ -116,7 +116,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_extension() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -126,10 +126,10 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_disallowed_content() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); - $file = new \phpbb\files\filespec($this->filesystem, $this->php_ini, $this->language, $this->phpbb_root_path); + $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path); $file->set_upload_ary(array( 'size' => 50, 'tmp_name' => dirname(__FILE__) . '/fixture/disallowed', @@ -145,7 +145,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_invalid_filename() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -156,7 +156,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_too_large() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); $file = $this->gen_valid_filespec(); @@ -167,7 +167,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks_valid_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); $file = $this->gen_valid_filespec(); @@ -177,7 +177,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_local_upload() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -191,7 +191,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -205,7 +205,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_move_existent_file_overwrite() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); @@ -220,7 +220,7 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_valid_dimensions() { - $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->php_ini, $this->language, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(false) ->set_max_filesize(false) ->set_allowed_dimensions(1, 1, 100, 100); -- cgit v1.2.1 From 16f3b8c2b9de388223cbe8ace9e1d9bcf0ba5e11 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Aug 2015 10:51:10 +0200 Subject: [ticket/13904] Modify files for changes in ini wrapper PHPBB3-13904 --- tests/cache/apc_driver_test.php | 6 ++-- tests/files/upload_test.php | 4 +-- tests/functional/fileupload_remote_test.php | 4 +-- tests/installer/installer_config_test.php | 6 ++-- tests/installer/module_base_test.php | 2 +- tests/plupload/plupload_test.php | 2 +- tests/upload/filespec_test.php | 8 ++--- tests/upload/fileupload_test.php | 4 +-- tests/wrapper/phpbb_php_ini_fake.php | 2 +- tests/wrapper/phpbb_php_ini_test.php | 46 +++++++++++++---------------- 10 files changed, 39 insertions(+), 45 deletions(-) (limited to 'tests') diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index 10130b465b..706f274448 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -34,14 +34,14 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case self::markTestSkipped('APC extension is not loaded'); } - $php_ini = new \phpbb\php\ini; + $php_ini = new \bantu\IniGetWrapper\IniGetWrapper; - if (!$php_ini->get_bool('apc.enabled')) + if (!$php_ini->getBool('apc.enabled')) { self::markTestSkipped('APC is not enabled. Make sure apc.enabled=1 in php.ini'); } - if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli')) + if (PHP_SAPI == 'cli' && !$php_ini->getBool('apc.enable_cli')) { self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini'); } diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index 6f4a10e6aa..da9d78afbc 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -23,7 +23,7 @@ class phpbb_files_upload_test extends phpbb_test_case /** @var \phpbb\files\factory */ protected $factory; - /** @var \phpbb\php\ini */ + /** @var \bantu\IniGetWrapper\IniGetWrapper */ protected $php_ini; /** @var \phpbb\language\language */ @@ -52,7 +52,7 @@ class phpbb_files_upload_test extends phpbb_test_case $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); - $this->php_ini = new \phpbb\php\ini; + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); $this->container->set('files.filespec', new \phpbb\files\filespec( diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 4fd8ae1f19..6752ff01f4 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -22,7 +22,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case /** @var \phpbb\files\factory */ protected $factory; - /** @var \phpbb\php\ini */ + /** @var \bantu\IniGetWrapper\IniGetWrapper */ protected $php_ini; /** @var \phpbb\language\language */ @@ -54,7 +54,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->request = $this->getMock('\phpbb\request\request'); - $this->php_ini = new \phpbb\php\ini; + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $container = new phpbb_mock_container_builder(); $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path)); diff --git a/tests/installer/installer_config_test.php b/tests/installer/installer_config_test.php index c7334ebd93..7de23aea36 100644 --- a/tests/installer/installer_config_test.php +++ b/tests/installer/installer_config_test.php @@ -24,11 +24,11 @@ class phpbb_installer_config_test extends phpbb_test_case { $phpbb_root_path = __DIR__ . './../../phpBB/'; $filesystem = $this->getMock('\phpbb\filesystem\filesystem'); - $php_ini = $this->getMockBuilder('\phpbb\php\ini') + $php_ini = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper') ->getMock(); - $php_ini->method('get_int') + $php_ini->method('getInt') ->willReturn(-1); - $php_ini->method('get_bytes') + $php_ini->method('getBytes') ->willReturn(-1); $this->config = new config($filesystem, $php_ini, $phpbb_root_path); diff --git a/tests/installer/module_base_test.php b/tests/installer/module_base_test.php index fd92c9b674..9578010047 100644 --- a/tests/installer/module_base_test.php +++ b/tests/installer/module_base_test.php @@ -43,7 +43,7 @@ class module_base_test extends phpbb_test_case $this->module = new test_installer_module($module_collection, true, false); $iohandler = $this->getMock('\phpbb\install\helper\iohandler\iohandler_interface'); - $config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(), new \phpbb\php\ini(), '', 'php'); + $config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(), new \bantu\IniGetWrapper\IniGetWrapper(), '', 'php'); $this->module->setup($config, $iohandler); } diff --git a/tests/plupload/plupload_test.php b/tests/plupload/plupload_test.php index aa7793567d..3312f4d0a0 100644 --- a/tests/plupload/plupload_test.php +++ b/tests/plupload/plupload_test.php @@ -48,7 +48,7 @@ class phpbb_plupload_test extends phpbb_test_case $config, new phpbb_mock_request, new \phpbb\user($lang, '\phpbb\datetime'), - new \phpbb\php\ini, + new \bantu\IniGetWrapper\IniGetWrapper, new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)) ); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 595439c917..a53c27f045 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -93,7 +93,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } @@ -114,7 +114,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_empty_upload_ary() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, $this->mimetype_guesser); $this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array())); $this->assertTrue($filespec->init_error()); } @@ -262,7 +262,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_clean_filename_avatar($filename, $expected, $mode, $prefix = '', $user_id = '') { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, $this->mimetype_guesser); if ($filename) { @@ -419,7 +419,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_is_uploaded() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \phpbb\php\ini, $this->phpbb_root_path, null); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, null); $reflection_filespec = new ReflectionClass($filespec); $plupload_property = $reflection_filespec->getProperty('plupload'); $plupload_property->setAccessible(true); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 40f8704271..43106599e4 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -27,7 +27,7 @@ class phpbb_fileupload_test extends phpbb_test_case /** @var \phpbb\files\factory */ protected $factory; - /** @var \phpbb\php\ini */ + /** @var \bantu\IniGetWrapper\IniGetWrapper */ protected $php_ini; /** @var \phpbb\language\language */ @@ -53,7 +53,7 @@ class phpbb_fileupload_test extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; $this->request = $this->getMock('\phpbb\request\request'); - $this->php_ini = new \phpbb\php\ini; + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $this->filesystem = new \phpbb\filesystem\filesystem(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php index f218ff6d03..300ce30cfe 100644 --- a/tests/wrapper/phpbb_php_ini_fake.php +++ b/tests/wrapper/phpbb_php_ini_fake.php @@ -11,7 +11,7 @@ * */ -class phpbb_php_ini_fake extends \phpbb\php\ini +class phpbb_php_ini_fake extends \bantu\IniGetWrapper\IniGetWrapper { function get($varname) { diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 27c2487f0a..8ef63757a5 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -16,6 +16,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case { + /** @var \phpbb_php_ini_fake php_ini */ protected $php_ini; public function setUp() @@ -25,44 +26,37 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case public function test_get_string() { - $this->assertSame(false, $this->php_ini->get_string(false)); - $this->assertSame('phpbb', $this->php_ini->get_string(' phpbb ')); + $this->assertSame('', $this->php_ini->getString(false)); + $this->assertSame('phpbb', $this->php_ini->getString(' phpbb ')); } public function test_get_bool() { - $this->assertSame(true, $this->php_ini->get_bool('ON')); - $this->assertSame(true, $this->php_ini->get_bool('on')); - $this->assertSame(true, $this->php_ini->get_bool('1')); + $this->assertSame(true, $this->php_ini->getBool('ON')); + $this->assertSame(true, $this->php_ini->getBool('on')); + $this->assertSame(true, $this->php_ini->getBool('1')); - $this->assertSame(false, $this->php_ini->get_bool('OFF')); - $this->assertSame(false, $this->php_ini->get_bool('off')); - $this->assertSame(false, $this->php_ini->get_bool('0')); - $this->assertSame(false, $this->php_ini->get_bool('')); + $this->assertSame(false, $this->php_ini->getBool('OFF')); + $this->assertSame(false, $this->php_ini->getBool('off')); + $this->assertSame(false, $this->php_ini->getBool('0')); + $this->assertSame(false, $this->php_ini->getBool('')); } public function test_get_int() { - $this->assertSame(1234, $this->php_ini->get_int('1234')); - $this->assertSame(-12345, $this->php_ini->get_int('-12345')); - $this->assertSame(false, $this->php_ini->get_int('phpBB')); - } - - public function test_get_float() - { - $this->assertSame(1234.0, $this->php_ini->get_float('1234')); - $this->assertSame(-12345.0, $this->php_ini->get_float('-12345')); - $this->assertSame(false, $this->php_ini->get_float('phpBB')); + $this->assertSame(1234, $this->php_ini->getNumeric('1234')); + $this->assertSame(-12345, $this->php_ini->getNumeric('-12345')); + $this->assertSame(null, $this->php_ini->getNumeric('phpBB')); } public function test_get_bytes_invalid() { - $this->assertSame(false, $this->php_ini->get_bytes(false)); - $this->assertSame(false, $this->php_ini->get_bytes('phpBB')); - $this->assertSame(false, $this->php_ini->get_bytes('k')); - $this->assertSame(false, $this->php_ini->get_bytes('-k')); - $this->assertSame(false, $this->php_ini->get_bytes('M')); - $this->assertSame(false, $this->php_ini->get_bytes('-M')); + $this->assertSame(null, $this->php_ini->getBytes(false)); + $this->assertSame(null, $this->php_ini->getBytes('phpBB')); + $this->assertSame(null, $this->php_ini->getBytes('k')); + $this->assertSame(null, $this->php_ini->getBytes('-k')); + $this->assertSame(null, $this->php_ini->getBytes('M')); + $this->assertSame(null, $this->php_ini->getBytes('-M')); } /** @@ -70,7 +64,7 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case */ public function test_get_bytes($expected, $value) { - $actual = $this->php_ini->get_bytes($value); + $actual = $this->php_ini->getBytes($value); $this->assertTrue(is_float($actual) || is_int($actual)); $this->assertEquals($expected, $actual); -- cgit v1.2.1 From b29b62debe4077ec688ebee9e9363db2c8614dd5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 27 Aug 2015 12:48:06 +0200 Subject: [ticket/13904] Use ini_get() wrapper in file upload types PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 2 +- tests/upload/fileupload_test.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 6752ff01f4..29701e072a 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -60,7 +60,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); - $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->request, $phpbb_root_path)); + $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $phpbb_root_path)); $this->phpbb_root_path = $phpbb_root_path; } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 43106599e4..8675567e22 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -81,12 +81,14 @@ class phpbb_fileupload_test extends phpbb_test_case $this->container->set('files.types.form', new \phpbb\files\types\form( $this->factory, $this->language, + $this->php_ini, $plupload, $this->request ), phpbb_mock_container_builder::SCOPE_PROTOTYPE); $this->container->set('files.types.local', new \phpbb\files\types\local( $this->factory, $this->language, + $this->php_ini, $this->request ), phpbb_mock_container_builder::SCOPE_PROTOTYPE); -- cgit v1.2.1 From c3ccd423d2a6f3aab1183b22177df6f605f33371 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 1 Sep 2015 10:58:35 +0200 Subject: [ticket/13904] Add back tests for retrieving floats PHPBB3-13904 --- tests/wrapper/phpbb_php_ini_test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 8ef63757a5..9f46a78d5b 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -49,6 +49,13 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case $this->assertSame(null, $this->php_ini->getNumeric('phpBB')); } + public function test_get_float() + { + $this->assertSame(1234.0, $this->php_ini->getNumeric('1234.0')); + $this->assertSame(-12345.0, $this->php_ini->getNumeric('-12345.0')); + $this->assertSame(null, $this->php_ini->getNumeric('phpBB')); + } + public function test_get_bytes_invalid() { $this->assertSame(null, $this->php_ini->getBytes(false)); -- cgit v1.2.1 From 591995267a3f1931131fa630bd3ff120476f881f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Sep 2015 17:20:54 +0200 Subject: [ticket/13904] Improve test coverage of filespec class PHPBB3-13904 --- tests/files/upload_test.php | 1 + tests/functional/fileupload_remote_test.php | 2 +- tests/upload/filespec_test.php | 119 +++++++++++++++++++++++++++- tests/upload/fileupload_test.php | 3 +- 4 files changed, 119 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index da9d78afbc..0d02926702 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -59,6 +59,7 @@ class phpbb_files_upload_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, + new \fastImageSize\fastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 29701e072a..1484acc4d5 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -57,7 +57,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $container = new phpbb_mock_container_builder(); - $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path)); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \fastImageSize\fastImageSize(), $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $phpbb_root_path)); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index a53c27f045..10a442cd1d 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -93,7 +93,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } @@ -114,7 +114,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_empty_upload_ary() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); $this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array())); $this->assertTrue($filespec->init_error()); } @@ -262,7 +262,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_clean_filename_avatar($filename, $expected, $mode, $prefix = '', $user_id = '') { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); if ($filename) { @@ -403,6 +403,117 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertFalse($filespec->move_file('foo')); } + public function data_move_file_copy() + { + return array( + array('gif_copy', true, false, array()), + array('gif_copy', true, true, array()), + array('foo_bar', false, false, array('GENERAL_UPLOAD_ERROR')), + array('foo_bar', false, true, array('GENERAL_UPLOAD_ERROR')), + ); + } + + /** + * @dataProvider data_move_file_copy + */ + public function test_move_file_copy($tmp_name, $move_success, $safe_mode_on, $expected_error) + { + // Initialise a blank filespec object for use with trivial methods + $upload_ary = array( + 'name' => 'gif_moved', + 'type' => 'image/gif', + 'size' => '', + 'tmp_name' => $this->path . 'copies/' . $tmp_name, + 'error' => '', + ); + + $php_ini = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper') + ->getMock(); + $php_ini->expects($this->any()) + ->method('getBool') + ->with($this->anything()) + ->willReturn($safe_mode_on); + $upload = new phpbb_mock_fileupload(); + $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $php_ini, new \fastImageSize\fastImagesize, '', $this->mimetype_guesser); + $filespec->set_upload_ary($upload_ary); + $filespec->local = false; + $filespec->extension = 'gif'; + $filespec->set_upload_namespace($upload); + + $this->assertEquals($move_success, $filespec->move_file($this->path . 'copies')); + $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/gif_moved')); + $this->assertSame($expected_error, $filespec->error); + } + + public function data_move_file_imagesize() + { + return array( + array( + array( + 'width' => 2, + 'height' => 2, + 'type' => IMAGETYPE_GIF, + ), + array() + ), + array( + array( + 'width' => 2, + 'height' => 2, + 'type' => -1, + ), + array('Image file type -1 for mimetype image/gif not supported.') + ), + array( + array( + 'width' => 0, + 'height' => 0, + 'type' => IMAGETYPE_GIF, + ), + array('The image file you tried to attach is invalid.') + ), + array( + false, + array('It was not possible to determine the dimensions of the image. Please verify that the URL you entered is correct.') + ) + ); + } + + /** + * @dataProvider data_move_file_imagesize + */ + public function test_move_file_imagesize($imagesize_return, $expected_error) + { + // Initialise a blank filespec object for use with trivial methods + $upload_ary = array( + 'name' => 'gif_moved', + 'type' => 'image/gif', + 'size' => '', + 'tmp_name' => $this->path . 'copies/gif_copy', + 'error' => '', + ); + + $imagesize = $this->getMockBuilder('\fastImageSize\fastImageSize') + ->getMock(); + $imagesize->expects($this->any()) + ->method('getImageSize') + ->with($this->anything()) + ->willReturn($imagesize_return); + + $upload = new phpbb_mock_fileupload(); + $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $imagesize, '', $this->mimetype_guesser); + $filespec->set_upload_ary($upload_ary); + $filespec->local = false; + $filespec->extension = 'gif'; + $filespec->set_upload_namespace($upload); + + $this->assertEquals(true, $filespec->move_file($this->path . 'copies')); + $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/gif_moved')); + $this->assertSame($expected_error, $filespec->error); + } + /** * @dataProvider clean_filename_variables */ @@ -419,7 +530,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_is_uploaded() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $this->phpbb_root_path, null); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, null); $reflection_filespec = new ReflectionClass($filespec); $plupload_property = $reflection_filespec->getProperty('plupload'); $plupload_property->setAccessible(true); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 8675567e22..bb3092528b 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -72,6 +72,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, + new \fastImageSize\fastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), @@ -131,7 +132,7 @@ class phpbb_fileupload_test extends phpbb_test_case $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); - $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, $this->phpbb_root_path); + $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \fastImageSize\fastImageSize(), $this->phpbb_root_path); $file->set_upload_ary(array( 'size' => 50, 'tmp_name' => dirname(__FILE__) . '/fixture/disallowed', -- cgit v1.2.1 From 1b9e6e352fd4a78e195d22a7dad6cd4f8f11d97c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Sep 2015 11:34:42 +0200 Subject: [ticket/13904] Improve test coverage of form upload type PHPBB3-13904 --- tests/files/types_form_test.php | 174 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 tests/files/types_form_test.php (limited to 'tests') diff --git a/tests/files/types_form_test.php b/tests/files/types_form_test.php new file mode 100644 index 0000000000..51219f7b4e --- /dev/null +++ b/tests/files/types_form_test.php @@ -0,0 +1,174 @@ + + * @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 dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_files_types_form_test extends phpbb_test_case +{ + private $path; + + private $filesystem; + + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \phpbb\files\factory */ + protected $factory; + + /** @var \bantu\IniGetWrapper\IniGetWrapper */ + protected $php_ini; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\request\request_interface */ + protected $request; + + /** @var \phpbb\plupload\plupload */ + protected $plupload; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + + protected function setUp() + { + global $phpbb_root_path, $phpEx; + + $this->request = $this->getMock('\phpbb\request\request'); + $this->request->expects($this->any()) + ->method('file') + ->willReturn(array()); + + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; + + $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); + $this->container->set('files.filespec', new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $this->php_ini, + new \fastImageSize\fastImageSize(), + $phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + )))); + $this->factory = new \phpbb\files\factory($this->container); + $this->plupload = $this->getMockBuilder('\phpbb\plupload\plupload') + ->disableOriginalConstructor() + ->getMock(); + $this->plupload->expects($this->any()) + ->method('handle_upload') + ->willReturn(array()); + + $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; + } + + public function data_upload_form() + { + return array( + array( + array(), + array(''), + ), + array( + array( + 'tmp_name' => 'foo', + 'name' => 'foo', + 'size' => 500, + 'type' => 'image/png', + 'error' => UPLOAD_ERR_PARTIAL, + ), + array('PARTIAL_UPLOAD'), + ), + array( + array( + 'tmp_name' => 'foo', + 'name' => 'foo', + 'size' => 500, + 'type' => 'image/png', + 'error' => -9, + ), + array('NOT_UPLOADED'), + ), + array( + array( + 'tmp_name' => 'foo', + 'name' => 'foo', + 'size' => 0, + 'type' => 'image/png', + ), + array('EMPTY_FILEUPLOAD'), + ), + array( + array( + 'tmp_name' => 'none', + 'name' => 'none', + 'size' => 50, + 'type' => 'image/png', + ), + array('PHP_SIZE_OVERRUN'), + ), + array( + array( + 'tmp_name' => 'tests/upload/fixture/png', + 'name' => 'foo.png', + 'size' => 500, + 'type' => 'image/png', + 'local_mode' => true, + ), + array(), + array('local_mode' => true), + ), + ); + } + + /** + * @dataProvider data_upload_form + */ + public function test_upload_form($upload, $expected, $plupload = array()) + { + $this->request = $this->getMock('\phpbb\request\request'); + $this->request->expects($this->any()) + ->method('file') + ->willReturn($upload); + $filespec = new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $this->php_ini, + new \fastImageSize\fastImageSize(), + $this->phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + ))); + $this->container->set('files.filespec', $filespec); + $this->factory = new \phpbb\files\factory($this->container); + $this->plupload = $this->getMockBuilder('\phpbb\plupload\plupload') + ->disableOriginalConstructor() + ->getMock(); + $this->plupload->expects($this->any()) + ->method('handle_upload') + ->willReturn($plupload); + + $type_form = new \phpbb\files\types\form($this->factory, $this->language, $this->php_ini, $this->plupload, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('png')); + $type_form->set_upload($upload); + + + $file = $type_form->upload('foobar'); + $this->assertSame($expected, $file->error); + $this->assertInstanceOf('\phpbb\files\filespec', $file); + } +} -- cgit v1.2.1 From 82bca32015b94b140b7c810fc5d7e721e8ee341f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Sep 2015 11:35:12 +0200 Subject: [ticket/13904] Improve test coverage of remote upload type PHPBB3-13904 --- tests/files/types_remote_test.php | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/files/types_remote_test.php (limited to 'tests') diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php new file mode 100644 index 0000000000..405a8c4104 --- /dev/null +++ b/tests/files/types_remote_test.php @@ -0,0 +1,77 @@ + + * @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 dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_files_types_remote_test extends phpbb_test_case +{ + private $path; + + private $filesystem; + + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \phpbb\files\factory */ + protected $factory; + + /** @var \bantu\IniGetWrapper\IniGetWrapper */ + protected $php_ini; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\request\request_interface */ + protected $request; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + + protected function setUp() + { + global $phpbb_root_path, $phpEx; + + $this->request = $this->getMock('\phpbb\request\request'); + + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; + + $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); + $this->container->set('files.filespec', new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $this->php_ini, + new \fastImageSize\fastImageSize(), + $phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + )))); + $this->factory = new \phpbb\files\factory($this->container); + + $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; + } + + public function test_upload_fsock_fail() + { + $type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('png')); + $type_remote->set_upload($upload); + + $file = $type_remote->upload('https://bärföö.com/foo.png'); + + $this->assertSame(array('NOT_UPLOADED'), $file->error); + } +} -- cgit v1.2.1 From e5bffbf40ff59614cea1b5f3f662d91cf8e63323 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Sep 2015 11:35:31 +0200 Subject: [ticket/13904] Improve test coverage of base upload type class PHPBB3-13904 --- tests/files/types_base_test.php | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/files/types_base_test.php (limited to 'tests') diff --git a/tests/files/types_base_test.php b/tests/files/types_base_test.php new file mode 100644 index 0000000000..dc82ee2639 --- /dev/null +++ b/tests/files/types_base_test.php @@ -0,0 +1,93 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_files_types_base_test extends phpbb_test_case +{ + private $path; + + private $filesystem; + + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \phpbb\files\factory */ + protected $factory; + + /** @var \bantu\IniGetWrapper\IniGetWrapper */ + protected $php_ini; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\request\request_interface */ + protected $request; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + + protected function setUp() + { + global $phpbb_root_path, $phpEx; + + $this->request = $this->getMock('\phpbb\request\request'); + + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; + + $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); + $this->container->set('files.filespec', new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $this->php_ini, + new \fastImageSize\fastImageSize(), + $phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + )))); + $this->factory = new \phpbb\files\factory($this->container); + + $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; + } + + public function data_check_upload_size() + { + return array( + array('foo', '500KB', array()), + array('none', '500KB', array('PHP_SIZE_OVERRUN')), + array('none', '', array('PHP_SIZE_NA')), + ); + } + + /** + * @dataProvider data_check_upload_size + */ + public function test_check_upload_size($filename, $max_filesize, $expected) + { + $php_ini = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper'); + $php_ini->expects($this->any()) + ->method('getString') + ->willReturn($max_filesize); + $type_form = new \phpbb\files\types\local($this->factory, $this->language, $php_ini, $this->request); + $file = $this->getMockBuilder('\phpbb\files\filespec') + ->disableOriginalConstructor() + ->getMock(); + $file->expects($this->any()) + ->method('get') + ->willReturn($filename); + $type_form->check_upload_size($file); + + $this->assertSame($expected, $file->error); + } +} -- cgit v1.2.1 From 00e5ff9e2e9c0dd7325f33a22888d6888af4b197 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Sep 2015 22:51:44 +0200 Subject: [ticket/13904] Add unit tests for local upload type PHPBB3-13904 --- tests/files/types_local_test.php | 161 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tests/files/types_local_test.php (limited to 'tests') diff --git a/tests/files/types_local_test.php b/tests/files/types_local_test.php new file mode 100644 index 0000000000..8712c9cd5a --- /dev/null +++ b/tests/files/types_local_test.php @@ -0,0 +1,161 @@ + + * @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 dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_files_types_local_test extends phpbb_test_case +{ + private $path; + + private $filesystem; + + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \phpbb\files\factory */ + protected $factory; + + /** @var \bantu\IniGetWrapper\IniGetWrapper */ + protected $php_ini; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\request\request_interface */ + protected $request; + + /** @var \phpbb\plupload\plupload */ + protected $plupload; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + + protected function setUp() + { + global $phpbb_root_path, $phpEx; + + $this->request = $this->getMock('\phpbb\request\request'); + $this->request->expects($this->any()) + ->method('file') + ->willReturn(array()); + + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; + + $this->container = new phpbb_mock_container_builder($phpbb_root_path, $phpEx); + $this->container->set('files.filespec', new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $this->php_ini, + new \fastImageSize\fastImageSize(), + $phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + )))); + $this->factory = new \phpbb\files\factory($this->container); + $this->plupload = $this->getMockBuilder('\phpbb\plupload\plupload') + ->disableOriginalConstructor() + ->getMock(); + $this->plupload->expects($this->any()) + ->method('handle_upload') + ->willReturn(array()); + + $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; + } + + public function test_upload_init_error() + { + $filespec = $this->getMockBuilder('\phpbb\files\filespec') + ->disableOriginalConstructor() + ->getMock(); + $filespec->expects($this->any()) + ->method('init_error') + ->willReturn(true); + $filespec->expects($this->any()) + ->method('set_upload_ary') + ->willReturnSelf(); + $filespec->expects($this->any()) + ->method('set_upload_namespace') + ->willReturnSelf(); + $this->container->set('files.filespec', $filespec); + $this->factory = new \phpbb\files\factory($this->container); + + $type_local = new \phpbb\files\types\local($this->factory, $this->language, $this->php_ini, $this->request); + + + $file = $type_local->upload('foo', false); + $this->assertSame(array(''), $file->error); + $this->assertInstanceOf('\phpbb\files\filespec', $file); + } + + public function data_upload_form() + { + return array( + array( + 'foo', + array( + 'tmp_name' => 'foo', + 'size' => 500, + 'type' => 'image/png', + ), + array('NOT_UPLOADED'), + ), + array( + 'none', + false, + array('PHP_SIZE_OVERRUN'), + ), + array( + 'tests/upload/fixture/png', + array( + 'realname' => 'foo.png', + 'size' => 500, + 'type' => 'image/png', + 'local_mode' => true, + ), + array(), + ), + ); + } + + /** + * @dataProvider data_upload_form + */ + public function test_upload_form($filename, $upload_ary, $expected) + { + $filespec = new \phpbb\files\filespec( + $this->filesystem, + $this->language, + $this->php_ini, + new \fastImageSize\fastImageSize(), + $this->phpbb_root_path, + new \phpbb\mimetype\guesser(array( + 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), + ))); + $filespec->local = true; + $this->container->set('files.filespec', $filespec); + $this->factory = new \phpbb\files\factory($this->container); + + $type_local = new \phpbb\files\types\local($this->factory, $this->language, $this->php_ini, $this->request); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('png')); + $type_local->set_upload($upload); + + + $file = $type_local->upload($filename, $upload_ary); + $this->assertSame($expected, $file->error); + $this->assertInstanceOf('\phpbb\files\filespec', $file); + } +} -- cgit v1.2.1 From e60c8a5a8bfa1aa500c096ea90cd32fda9465f9a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 7 Sep 2015 22:52:20 +0200 Subject: [ticket/13904] Improve code coverage PHPBB3-13904 --- tests/files/type_foo.php | 31 ++++++++++++++++++ tests/files/types_remote_test.php | 66 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/files/type_foo.php (limited to 'tests') diff --git a/tests/files/type_foo.php b/tests/files/type_foo.php new file mode 100644 index 0000000000..20eddfcbc4 --- /dev/null +++ b/tests/files/type_foo.php @@ -0,0 +1,31 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\files\types; + +class foo extends \phpbb\files\types\remote +{ + static public $tempnam_path; +} + +function tempnam($one, $two) +{ + if (empty(foo::$tempnam_path)) + { + return \tempnam($one, $two); + } + else + { + return foo::$tempnam_path; + } +} diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php index 405a8c4104..6d513ac5c0 100644 --- a/tests/files/types_remote_test.php +++ b/tests/files/types_remote_test.php @@ -12,6 +12,7 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/type_foo.php'; class phpbb_files_types_remote_test extends phpbb_test_case { @@ -39,8 +40,9 @@ class phpbb_files_types_remote_test extends phpbb_test_case protected function setUp() { - global $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx; + $config = new \phpbb\config\config(array()); $this->request = $this->getMock('\phpbb\request\request'); $this->filesystem = new \phpbb\filesystem\filesystem(); @@ -74,4 +76,66 @@ class phpbb_files_types_remote_test extends phpbb_test_case $this->assertSame(array('NOT_UPLOADED'), $file->error); } + + public function data_get_max_file_size() + { + return array( + array('', 'http://example.com/foo/bar.png'), + array('2k', 'http://example.com/foo/bar.png'), + array('500k', 'http://example.com/foo/bar.png'), + array('500M', 'http://example.com/foo/bar.png'), + array('500m', 'http://example.com/foo/bar.png'), + array('500k', 'http://google.com/.png', 'DISALLOWED_CONTENT'), + array('1', 'http://google.com/.png', 'WRONG_FILESIZE'), + array('500g', 'http://example.com/foo/bar.png'), + array('foobar', 'http://example.com/foo/bar.png'), + array('-5k', 'http://example.com/foo/bar.png'), + ); + } + + /** + * @dataProvider data_get_max_file_size + */ + public function test_get_max_file_size($max_file_size, $link, $expected = 'URL_NOT_FOUND') + { + $php_ini = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper', array('getString')); + $php_ini->expects($this->any()) + ->method('getString') + ->willReturn($max_file_size); + $type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $php_ini, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('png')); + $type_remote->set_upload($upload); + + $file = $type_remote->upload($link); + + $this->assertSame(array($expected), $file->error); + } + + public function test_upload_timeout() + { + $type_remote = new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('png')); + $type_remote->set_upload($upload); + $upload->upload_timeout = -5; + + $file = $type_remote->upload('http://google.com/.png'); + + $this->assertSame(array('REMOTE_UPLOAD_TIMEOUT'), $file->error); + } + + public function test_upload_wrong_path() + { + $type_remote = new \phpbb\files\types\foo($this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $upload->set_allowed_extensions(array('png')); + $type_remote->set_upload($upload); + $type_remote::$tempnam_path = $this->phpbb_root_path . 'cache/wrong/path'; + + $file = $type_remote->upload('http://google.com/.png'); + + $this->assertSame(array('NOT_UPLOADED'), $file->error); + $type_remote::$tempnam_path = ''; + } } -- cgit v1.2.1 From 327e36a4d68ff9607967af52ef8f6a00c60343ff Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 9 Sep 2015 09:41:40 +0200 Subject: [ticket/13904] Modify files for updated fast-image-size library PHPBB3-13904 --- tests/files/types_base_test.php | 2 +- tests/files/types_form_test.php | 4 ++-- tests/files/types_local_test.php | 4 ++-- tests/files/types_remote_test.php | 2 +- tests/files/upload_test.php | 2 +- tests/functional/fileupload_remote_test.php | 2 +- tests/upload/filespec_test.php | 12 ++++++------ tests/upload/fileupload_test.php | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/files/types_base_test.php b/tests/files/types_base_test.php index dc82ee2639..e630bf8c48 100644 --- a/tests/files/types_base_test.php +++ b/tests/files/types_base_test.php @@ -50,7 +50,7 @@ class phpbb_files_types_base_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), diff --git a/tests/files/types_form_test.php b/tests/files/types_form_test.php index 51219f7b4e..efcece49d1 100644 --- a/tests/files/types_form_test.php +++ b/tests/files/types_form_test.php @@ -58,7 +58,7 @@ class phpbb_files_types_form_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), @@ -147,7 +147,7 @@ class phpbb_files_types_form_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $this->phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), diff --git a/tests/files/types_local_test.php b/tests/files/types_local_test.php index 8712c9cd5a..1367bbfcf8 100644 --- a/tests/files/types_local_test.php +++ b/tests/files/types_local_test.php @@ -58,7 +58,7 @@ class phpbb_files_types_local_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), @@ -139,7 +139,7 @@ class phpbb_files_types_local_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $this->phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php index 6d513ac5c0..a85844ee78 100644 --- a/tests/files/types_remote_test.php +++ b/tests/files/types_remote_test.php @@ -54,7 +54,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index 0d02926702..1716eca6c9 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -59,7 +59,7 @@ class phpbb_files_upload_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 1484acc4d5..3349ffc576 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -57,7 +57,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $this->php_ini = new \bantu\IniGetWrapper\IniGetWrapper; $container = new phpbb_mock_container_builder(); - $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \fastImageSize\fastImageSize(), $this->phpbb_root_path)); + $container->set('files.filespec', new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path)); $this->factory = new \phpbb\files\factory($container); $container->set('files.factory', $this->factory); $container->set('files.types.remote', new \phpbb\files\types\remote($this->factory, $this->language, $this->php_ini, $this->request, $phpbb_root_path)); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 10a442cd1d..08c064698c 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -93,7 +93,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); return $filespec->set_upload_ary(array_merge($upload_ary, $override)); } @@ -114,7 +114,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_empty_upload_ary() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); $this->assertInstanceOf('\phpbb\files\filespec', $filespec->set_upload_ary(array())); $this->assertTrue($filespec->init_error()); } @@ -262,7 +262,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_clean_filename_avatar($filename, $expected, $mode, $prefix = '', $user_id = '') { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, $this->mimetype_guesser); if ($filename) { @@ -435,7 +435,7 @@ class phpbb_filespec_test extends phpbb_test_case ->willReturn($safe_mode_on); $upload = new phpbb_mock_fileupload(); $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $php_ini, new \fastImageSize\fastImagesize, '', $this->mimetype_guesser); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $php_ini, new \FastImageSize\FastImagesize, '', $this->mimetype_guesser); $filespec->set_upload_ary($upload_ary); $filespec->local = false; $filespec->extension = 'gif'; @@ -494,7 +494,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $imagesize = $this->getMockBuilder('\fastImageSize\fastImageSize') + $imagesize = $this->getMockBuilder('\FastImageSize\FastImageSize') ->getMock(); $imagesize->expects($this->any()) ->method('getImageSize') @@ -530,7 +530,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_is_uploaded() { - $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \fastImageSize\fastImageSize(), $this->phpbb_root_path, null); + $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, null); $reflection_filespec = new ReflectionClass($filespec); $plupload_property = $reflection_filespec->getProperty('plupload'); $plupload_property->setAccessible(true); diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index bb3092528b..01b625efbb 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -72,7 +72,7 @@ class phpbb_fileupload_test extends phpbb_test_case $this->filesystem, $this->language, $this->php_ini, - new \fastImageSize\fastImageSize(), + new \FastImageSize\FastImageSize(), $phpbb_root_path, new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), @@ -132,7 +132,7 @@ class phpbb_fileupload_test extends phpbb_test_case $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('jpg')) ->set_max_filesize(1000); - $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \fastImageSize\fastImageSize(), $this->phpbb_root_path); + $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path); $file->set_upload_ary(array( 'size' => 50, 'tmp_name' => dirname(__FILE__) . '/fixture/disallowed', -- cgit v1.2.1 From 70ad0c6a8f7d16b767aa78cde2acc9a3b3512e6f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 9 Sep 2015 10:43:12 +0200 Subject: [ticket/13904] Add language entries for error messages in upload class PHPBB3-13904 --- tests/files/upload_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php index 1716eca6c9..c41204a0d5 100644 --- a/tests/files/upload_test.php +++ b/tests/files/upload_test.php @@ -110,9 +110,9 @@ class phpbb_files_upload_test extends phpbb_test_case array(UPLOAD_ERR_FORM_SIZE, 'WRONG_FILESIZE'), array(UPLOAD_ERR_PARTIAL, 'PARTIAL_UPLOAD'), array(UPLOAD_ERR_NO_FILE, 'NOT_UPLOADED'), - array(UPLOAD_ERR_NO_TMP_DIR, 'Temporary folder could not be found. Please check your PHP installation.'), - array(UPLOAD_ERR_CANT_WRITE, 'Can’t write to temporary folder.'), - array(UPLOAD_ERR_EXTENSION, 'A PHP extension has stopped the file upload.'), + array(UPLOAD_ERR_NO_TMP_DIR, 'NO_TEMP_DIR'), + array(UPLOAD_ERR_CANT_WRITE, 'NO_TEMP_DIR'), + array(UPLOAD_ERR_EXTENSION, 'PHP_UPLOAD_STOPPED'), array(9, false), ); } -- cgit v1.2.1 From 40e614f56436447dffd272351e23b79c2da9fa3f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 9 Sep 2015 12:58:22 +0200 Subject: [ticket/13904] Fix tests after changes to factory PHPBB3-13904 --- tests/functional/fileupload_remote_test.php | 8 ++++---- tests/upload/fileupload_test.php | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 3349ffc576..7e0f192b40 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -78,7 +78,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); - $file = $upload->handle_upload('remote', self::$root_url . 'develop/blank.gif'); + $file = $upload->handle_upload('files.types.remote', self::$root_url . 'develop/blank.gif'); $this->assertEquals('URL_INVALID', $file->error[0]); } @@ -89,7 +89,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('jpg')) ->set_max_filesize(100); - $file = $upload->handle_upload('remote', self::$root_url . 'develop/blank.jpg'); + $file = $upload->handle_upload('files.types.remote', self::$root_url . 'develop/blank.jpg'); $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); } @@ -100,7 +100,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(1000); - $file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->handle_upload('files.types.remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->get('filename'))); $this->assertTrue($file->is_uploaded()); @@ -113,7 +113,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); - $file = $upload->handle_upload('remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->handle_upload('files.types.remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(1, sizeof($file->error)); $this->assertEquals('WRONG_FILESIZE', $file->error[0]); } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 01b625efbb..211e72a6e9 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -185,7 +185,7 @@ class phpbb_fileupload_test extends phpbb_test_case ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); - $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); + $file = $upload->handle_upload('files.types.local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); $this->assertFalse($file->additional_checks()); $this->assertTrue($file->move_file('../tests/upload/fixture/copies', true)); @@ -199,7 +199,7 @@ class phpbb_fileupload_test extends phpbb_test_case ->set_max_filesize(1000); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); - $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); + $file = $upload->handle_upload('files.types.local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); $this->assertFalse($file->move_file('../tests/upload/fixture')); $this->assertFalse($file->file_moved); @@ -214,7 +214,7 @@ class phpbb_fileupload_test extends phpbb_test_case copy($this->path . 'jpg', $this->path . 'jpg.jpg'); copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg'); - $file = $upload->handle_upload('local', $this->path . 'jpg.jpg'); + $file = $upload->handle_upload('files.types.local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); $file->move_file('../tests/upload/fixture/copies', true); $this->assertEquals(0, sizeof($file->error)); -- cgit v1.2.1 From 759dc9bb84d712c11148a9689d294c09aa0f81d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 13 Sep 2015 09:30:56 +0200 Subject: [ticket/13904] Set properties to protected where possible in filespec PHPBB3-13904 --- tests/files/types_local_test.php | 4 +++- tests/upload/filespec_test.php | 31 +++++++++++++++++++------------ tests/upload/fileupload_test.php | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/files/types_local_test.php b/tests/files/types_local_test.php index 1367bbfcf8..f4fa7fad3f 100644 --- a/tests/files/types_local_test.php +++ b/tests/files/types_local_test.php @@ -144,7 +144,9 @@ class phpbb_files_types_local_test extends phpbb_test_case new \phpbb\mimetype\guesser(array( 'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(), ))); - $filespec->local = true; + $filespec_local = new ReflectionProperty($filespec, 'local'); + $filespec_local->setAccessible(true); + $filespec_local->setValue($filespec, true); $this->container->set('files.filespec', $filespec); $this->factory = new \phpbb\files\factory($this->container); diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 08c064698c..1351b46002 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -82,6 +82,13 @@ class phpbb_filespec_test extends phpbb_test_case $this->phpbb_root_path = $phpbb_root_path; } + private function set_reflection_property(&$class, $property_name, $value) + { + $property = new ReflectionProperty($class, $property_name); + $property->setAccessible(true); + $property->setValue($class, $value); + } + private function get_filespec($override = array()) { // Initialise a blank filespec object for use with trivial methods @@ -141,8 +148,8 @@ class phpbb_filespec_test extends phpbb_test_case $upload = new phpbb_mock_fileupload(); $filespec = $this->get_filespec(); $filespec->set_upload_namespace($upload); - $filespec->file_moved = true; - $filespec->filesize = $filespec->get_filesize($this->path . $filename); + $this->set_reflection_property($filespec, 'file_moved', true); + $this->set_reflection_property($filespec, 'filesize', $filespec->get_filesize($this->path . $filename)); $this->assertEquals($expected, $filespec->additional_checks()); } @@ -153,7 +160,7 @@ class phpbb_filespec_test extends phpbb_test_case $filespec = $this->get_filespec(); $filespec->set_upload_namespace($upload); $upload->valid_dimensions = false; - $filespec->file_moved = true; + $this->set_reflection_property($filespec, 'file_moved', true); $upload->max_filesize = 0; $this->assertEquals(false, $filespec->additional_checks()); @@ -381,12 +388,12 @@ class phpbb_filespec_test extends phpbb_test_case 'name' => $realname, 'type' => $mime_type, )); - $filespec->extension = $extension; + $this->set_reflection_property($filespec, 'extension', $extension); $filespec->set_upload_namespace($upload); - $filespec->local = true; + $this->set_reflection_property($filespec, 'local', true); $this->assertEquals($expected, $filespec->move_file($this->path . 'copies')); - $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/' . $realname)); + $this->assertEquals($filespec->get('file_moved'), file_exists($this->path . 'copies/' . $realname)); if ($error) { $this->assertEquals($error, $filespec->error[0]); @@ -437,12 +444,12 @@ class phpbb_filespec_test extends phpbb_test_case $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $php_ini, new \FastImageSize\FastImagesize, '', $this->mimetype_guesser); $filespec->set_upload_ary($upload_ary); - $filespec->local = false; - $filespec->extension = 'gif'; + $this->set_reflection_property($filespec, 'local', false); + $this->set_reflection_property($filespec, 'extension', 'gif'); $filespec->set_upload_namespace($upload); $this->assertEquals($move_success, $filespec->move_file($this->path . 'copies')); - $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/gif_moved')); + $this->assertEquals($filespec->get('file_moved'), file_exists($this->path . 'copies/gif_moved')); $this->assertSame($expected_error, $filespec->error); } @@ -505,12 +512,12 @@ class phpbb_filespec_test extends phpbb_test_case $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, $imagesize, '', $this->mimetype_guesser); $filespec->set_upload_ary($upload_ary); - $filespec->local = false; - $filespec->extension = 'gif'; + $this->set_reflection_property($filespec, 'local', false); + $this->set_reflection_property($filespec, 'extension', 'gif'); $filespec->set_upload_namespace($upload); $this->assertEquals(true, $filespec->move_file($this->path . 'copies')); - $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/gif_moved')); + $this->assertEquals($filespec->get('file_moved'), file_exists($this->path . 'copies/gif_moved')); $this->assertSame($expected_error, $filespec->error); } diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 211e72a6e9..05cb8dcf93 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -202,7 +202,7 @@ class phpbb_fileupload_test extends phpbb_test_case $file = $upload->handle_upload('files.types.local', $this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); $this->assertFalse($file->move_file('../tests/upload/fixture')); - $this->assertFalse($file->file_moved); + $this->assertFalse($file->get('file_moved')); $this->assertEquals(1, sizeof($file->error)); } -- cgit v1.2.1