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/files/upload_test.php') 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 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 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/files/upload_test.php') 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)); + } } -- 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 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tests/files/upload_test.php') 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() -- 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 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tests/files/upload_test.php') 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)); } } -- 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 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/files/upload_test.php') 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)); } } -- 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/files/upload_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/files/upload_test.php') 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( -- 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 + 1 file changed, 1 insertion(+) (limited to 'tests/files/upload_test.php') 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(), -- 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/upload_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/files/upload_test.php') 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(), -- 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/files/upload_test.php') 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