diff options
Diffstat (limited to 'tests')
38 files changed, 1378 insertions, 202 deletions
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 6d77f2ed3a..9003f72de2 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -57,7 +57,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case new \phpbb\mimetype\content_guesser, ); $guesser = new \phpbb\mimetype\guesser($guessers); - $imagesize = new \fastImageSize\fastImageSize(); + $imagesize = new \FastImageSize\FastImageSize(); $dispatcher = new phpbb_mock_event_dispatcher(); @@ -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, $filesystem, $path_helper, $dispatcher, $files_factory, $cache)); } $cur_avatar->expects($this->any()) ->method('get_name') 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/console/thumbnail_test.php b/tests/console/thumbnail_test.php index b5ed02b5e7..45d7adacb9 100644 --- a/tests/console/thumbnail_test.php +++ b/tests/console/thumbnail_test.php @@ -39,6 +39,11 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case { global $config, $phpbb_root_path, $phpEx, $phpbb_filesystem; + if (!@extension_loaded('gd')) + { + $this->markTestSkipped('Thumbnail tests require gd extension.'); + } + parent::setUp(); $config = $this->config = new \phpbb\config\config(array( diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 3c74c16bae..4c0c8569a3 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -125,6 +125,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $this->router = new phpbb_mock_router($container, $this->filesystem, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT, $this->extension_manager); $this->router->find_routing_files($this->extension_manager->all_enabled(false)); $this->router->find(dirname(__FILE__) . '/'); + // Set correct current phpBB root path $this->root_path = $this->get_phpbb_root_path(); } @@ -168,7 +169,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description); } @@ -211,7 +213,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description); } @@ -254,7 +257,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_absolute($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); } @@ -297,7 +301,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_relative_path($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); } @@ -340,7 +345,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_network($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); } @@ -383,7 +389,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_absolute_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); } @@ -423,7 +430,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_relative_path_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); } @@ -466,7 +474,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_network_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); } } diff --git a/tests/files/type_foo.php b/tests/files/type_foo.php new file mode 100644 index 0000000000..95940b9d2f --- /dev/null +++ b/tests/files/type_foo.php @@ -0,0 +1,31 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +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_base_test.php b/tests/files/types_base_test.php new file mode 100644 index 0000000000..e630bf8c48 --- /dev/null +++ b/tests/files/types_base_test.php @@ -0,0 +1,93 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +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); + } +} diff --git a/tests/files/types_form_test.php b/tests/files/types_form_test.php new file mode 100644 index 0000000000..efcece49d1 --- /dev/null +++ b/tests/files/types_form_test.php @@ -0,0 +1,174 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once 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); + } +} diff --git a/tests/files/types_local_test.php b/tests/files/types_local_test.php new file mode 100644 index 0000000000..f4fa7fad3f --- /dev/null +++ b/tests/files/types_local_test.php @@ -0,0 +1,163 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once 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 = 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); + + $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); + } +} diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php new file mode 100644 index 0000000000..a85844ee78 --- /dev/null +++ b/tests/files/types_remote_test.php @@ -0,0 +1,141 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/type_foo.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 $config, $phpbb_root_path, $phpEx; + + $config = new \phpbb\config\config(array()); + $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); + } + + 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 = ''; + } +} diff --git a/tests/files/upload_test.php b/tests/files/upload_test.php new file mode 100644 index 0000000000..c41204a0d5 --- /dev/null +++ b/tests/files/upload_test.php @@ -0,0 +1,128 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +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 \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 $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->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_reset_vars() + { + $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(); + $this->assertEquals(0, $upload->max_filesize); + } + + public function test_set_disallowed_content() + { + $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); + + $upload->set_disallowed_content(array('foo')); + $this->assertEquals(array('foo'), $disallowed_content->getValue($upload)); + $upload->set_disallowed_content(array('foo', 'bar', 'meh')); + $this->assertEquals(array('foo', 'bar', 'meh'), $disallowed_content->getValue($upload)); + $upload->set_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(), $disallowed_content->getValue($upload)); + $upload->reset_vars(); + $this->assertEquals(array(), $disallowed_content->getValue($upload)); + } + + public function test_is_valid() + { + $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')); + } + + 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, 'NO_TEMP_DIR'), + array(UPLOAD_ERR_CANT_WRITE, 'NO_TEMP_DIR'), + array(UPLOAD_ERR_EXTENSION, 'PHP_UPLOAD_STOPPED'), + 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->php_ini, $this->request, $this->phpbb_root_path); + $this->assertSame($expected, $upload->assign_internal_error($error_code)); + } +} diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 4f28879687..280e814c06 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -48,7 +48,7 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case public function test_feed() { - $crawler = self::request('GET', 'feed.php', array(), false); + $crawler = self::request('GET', 'app.php/feed', array(), false); self::assert_response_xml(); $this->assertGreaterThan(0, $crawler->filter('entry')->count()); } diff --git a/tests/functional/controllers_compatibility_test.php b/tests/functional/controllers_compatibility_test.php index 7ba0b0d991..9499888a1a 100644 --- a/tests/functional/controllers_compatibility_test.php +++ b/tests/functional/controllers_compatibility_test.php @@ -24,6 +24,19 @@ class phpbb_functional_controllers_compatibility_test extends phpbb_functional_t $this->assert301('report.php?pm=1', 'app.php/pm/1/report'); } + public function test_feed_compatibility() + { + $this->assert301('feed.php', 'app.php/feed'); + $this->assert301('feed.php?mode=foobar', 'app.php/feed/foobar'); + $this->assert301('feed.php?mode=news', 'app.php/feed/news'); + $this->assert301('feed.php?mode=topics', 'app.php/feed/topics'); + $this->assert301('feed.php?mode=topics_news', 'app.php/feed/topics_news'); + $this->assert301('feed.php?mode=topics_active', 'app.php/feed/topics_active'); + $this->assert301('feed.php?mode=forums', 'app.php/feed/forums'); + $this->assert301('feed.php?f=1', 'app.php/feed/forum/1'); + $this->assert301('feed.php?t=1', 'app.php/feed/topic/1'); + } + protected function assert301($from, $to) { self::$client->followRedirects(false); diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index 9041c8dc69..16afced238 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + /** * @group functional */ @@ -24,9 +26,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case { parent::__construct($name, $data, $dataName); - $this->backupStaticAttributesBlacklist += array( - 'phpbb_functional_feed_test' => array('init_values'), - ); + $this->backupStaticAttributesBlacklist['phpbb_functional_feed_test'] = array('init_values'); + + $this->purge_cache(); } public function test_setup_config_before_state() @@ -55,66 +57,64 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form->setValues($values); $crawler = self::submit($form); - $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); // Special config (Guest can't see attachments) $this->add_lang('acp/permissions'); $crawler = self::request('GET', "adm/index.php?i=acp_permissions&sid={$this->sid}&icat=16&mode=setting_group_global&group_id[0]=1"); - $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + self::assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); $form['setting[1][0][u_download]']->select(-1); $crawler = self::submit($form); - $this->assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text()); + self::assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text()); } public function test_dump_board_state() { - $crawler = self::request('GET', 'feed.php?mode=forums', array(), false); + $crawler = self::request('GET', 'app.php/feed/forums', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['forums_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=overall', array(), false); + $crawler = self::request('GET', 'app.php/feed/overall', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['overall_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['topics_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_new', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['topics_new_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_active', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['topics_active_value'] = $crawler->filterXPath('//entry')->count(); $this->login(); - $crawler = self::request('GET', 'feed.php?mode=forums', array(), false); + $crawler = self::request('GET', 'app.php/feed/forums', array(), false); self::assert_response_xml(); self::$init_values['admin']['forums_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=overall', array(), false); + $crawler = self::request('GET', 'app.php/feed/overall', array(), false); self::assert_response_xml(); self::$init_values['admin']['overall_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics', array(), false); self::assert_response_xml(); self::$init_values['admin']['topics_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_new', array(), false); self::assert_response_xml(); self::$init_values['admin']['topics_new_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_active', array(), false); self::assert_response_xml(); self::$init_values['admin']['topics_active_value'] = $crawler->filterXPath('//entry')->count(); - - } public function test_setup_forums() @@ -132,7 +132,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); $this->load_ids(array( 'forums' => array( @@ -149,7 +149,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); // 'Feeds #news' will be used for feed.php?mode=news $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); @@ -160,9 +160,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); - // 'Feeds #exclude' will not be displayed on feed.php?mode=forums + // 'Feeds #exclude' will not be displayed on app.php/feed/forums $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); $form = $crawler->selectButton('addforum')->form(array( 'forum_name' => 'Feeds #exclude', @@ -171,7 +171,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); } public function test_setup_config_after_forums() @@ -195,7 +195,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form['feed_exclude_id']->select(array($this->data['forums']['Feeds #exclude'])); $crawler = self::submit($form); - $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); } public function test_feeds_empty() @@ -266,6 +266,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'id' => $this->data['forums']['Feeds #exclude'], 'contents_lang' => array('NO_FEED'), 'invalid' => true, + 'response_code' => 404, ), ), 't' => array( @@ -273,6 +274,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'id' => $this->data['topics']['Feeds #exclude - Topic #1'], 'contents_lang' => array('NO_FEED'), 'invalid' => true, + 'response_code' => 404, ), ), 'overall' => array( @@ -325,7 +327,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text()); + self::assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text()); $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id']; $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); @@ -333,7 +335,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post2 = $this->create_post($this->data['forums']['Feeds #news'], $post['topic_id'], 'Re: Feeds #news - Topic #2', 'This is a test post posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); - $this->assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text()); + self::assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text()); $this->data['posts']['Re: Feeds #news - Topic #2'] = (int) $post2['post_id']; } @@ -489,7 +491,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); - $this->assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text()); + self::assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text()); $this->data['posts']['Re: Feeds #1 - Topic #2'] = (int) $post2['post_id']; } @@ -510,14 +512,14 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->add_lang('posting'); $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Feeds #1']}&p={$this->data['posts']['Re: Feeds #1 - Topic #2']}&sid={$this->sid}"); - $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + self::assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); $form = $crawler->selectButton('Yes')->form(); $crawler = self::submit($form); - $this->assertContainsLang('POST_DELETED', $crawler->text()); + self::assertContainsLang('POST_DELETED', $crawler->text()); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}"); - $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); + self::assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); } public function test_feeds_softdeleted_post_admin() @@ -609,15 +611,15 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->add_lang('posting'); $crawler = $this->get_quickmod_page($this->data['topics']['Feeds #1 - Topic #2'], 'DELETE_TOPIC'); - $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + self::assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); $this->add_lang('mcp'); $form = $crawler->selectButton('Yes')->form(); $crawler = self::submit($form); - $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); + self::assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}"); - $this->assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text()); + self::assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text()); } public function test_feeds_softdeleted_topic_admin() @@ -710,8 +712,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 't' => array( array( 'id' => $this->data['topics']['Feeds #1 - Topic #2'], - 'contents_lang' => array('SORRY_AUTH_READ'), + 'contents_lang' => array('SORRY_AUTH_READ_TOPIC'), 'invalid' => true, + 'response_code' => 403, ), ), 'overall' => array( @@ -752,10 +755,10 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case // Test creating a reply $this->login('disapprove_user'); - $post2 = $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD'); + $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD'); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1.1 - Topic #2']}&sid={$this->sid}"); - $this->assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text()); + self::assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text()); } public function test_feeds_unapproved_post_admin() @@ -847,7 +850,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id']; $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}"); - $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); + self::assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); $this->logout(); $this->set_flood_interval(15); @@ -863,10 +866,10 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('Submit')->form(); $values = $form->getValues(); - $values["config[flood_interval]"] = $flood_interval; + $values['config[flood_interval]'] = $flood_interval; $form->setValues($values); $crawler = self::submit($form); - $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + self::assertGreaterThan(0, $crawler->filter('.successbox')->count()); $this->logout(); } @@ -958,8 +961,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 't' => array( array( 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'], - 'contents_lang' => array('SORRY_AUTH_READ'), + 'contents_lang' => array('SORRY_AUTH_READ_TOPIC'), 'invalid' => true, + 'response_code' => 403, ), ), 'overall' => array( @@ -998,7 +1002,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #3', 'This is a test topic posted by the testing framework. [attachment=0]Attachment #0[/attachment]', array('upload_files' => 1)); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - $this->assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text()); + self::assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text()); $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id']; } @@ -1216,7 +1220,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post2 = $this->create_post($this->data['forums']['Feeds #1'], $this->data['topics']['Feeds #1 - Topic #3'], 'Re: Feeds #1 - Topic #3-1', 'This is a test post posted by the testing framework. [attachment=0]Attachment #0[/attachment]'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); - $this->assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text()); + self::assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text()); $this->data['posts']['Re: Feeds #1 - Topic #3-1'] = (int) $post2['post_id']; } @@ -1316,9 +1320,14 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case { foreach ($feeds as $feed_data) { - if ($mode === 'f' || $mode === 't') + if ($mode === 'f') + { + $params = "/forum/{$feed_data['id']}"; + $this->assert_feed($params, $feed_data); + } + else if ($mode === 't') { - $params = "?{$mode}={$feed_data['id']}"; + $params = "/topic/{$feed_data['id']}"; $this->assert_feed($params, $feed_data); } else @@ -1342,10 +1351,10 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case case 'news': break; default: - $this->fail('Unsupported feed mode: ' . $mode); + self::fail('Unsupported feed mode: ' . $mode); } - $params = "?mode={$mode}"; + $params = "/{$mode}"; $this->assert_feed($params, $feed_data); } } @@ -1354,19 +1363,19 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case protected function assert_feed($params, $data) { - $crawler = self::request('GET', 'feed.php' . $params, array(), false); + $crawler = self::request('GET', 'app.php/feed' . $params, array(), false); if (empty($data['invalid'])) { self::assert_response_xml(); - $this->assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'feed.php{$params}'"); + self::assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'app.php/feed{$params}'"); if (!empty($data['xpath'])) { foreach($data['xpath'] as $xpath => $count_expected) { - $this->assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'feed.php{$params}', Search for {$xpath}"); + self::assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'app.php/feed{$params}', Search for {$xpath}"); } } @@ -1375,7 +1384,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case foreach($data['contents'] as $entry_id => $string) { $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); - $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContains($string, $content, "Tested feed : 'app.php/feed{$params}'"); } } @@ -1384,7 +1393,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case foreach($data['contents_lang'] as $entry_id => $string) { $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); - $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContainsLang($string, $content, "Tested feed : 'app.php/feed{$params}'"); } } @@ -1392,21 +1401,21 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case { foreach($data['attachments'] as $entry_id => $attachments) { + $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); foreach ($attachments as $i => $attachment) { - $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); - $url = "./download/file.php?id={$attachment['id']}"; + $url = self::$root_url . "download/file.php?id={$attachment['id']}"; $string = "Attachment #{$i}"; if ($attachment['displayed']) { - $this->assertContains($url, $content, "Tested feed : 'feed.php{$params}'"); - $this->assertNotContains($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContains($url, $content, "Tested feed : 'app.php/feed{$params}'"); + self::assertNotContains($string, $content, "Tested feed : 'app.php/feed{$params}'"); } else { - $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'"); - $this->assertNotContains($url, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContains($string, $content, "Tested feed : 'app.php/feed{$params}'"); + self::assertNotContains($url, $content, "Tested feed : 'app.php/feed{$params}'"); } } } @@ -1414,14 +1423,14 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case } else { - self::assert_response_html(); + self::assert_response_html($data['response_code'] ?: 202); if (!empty($data['contents_lang'])) { + $content = $crawler->filter('html')->text(); foreach($data['contents_lang'] as $string) { - $content = $crawler->filter('html')->text(); - $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContainsLang($string, $content, "Tested feed : 'app.php/feed{$params}'"); } } } @@ -1439,7 +1448,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (in_array($row['forum_name'], $data['forums'])) + if (in_array($row['forum_name'], $data['forums'], false)) { $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; } @@ -1455,7 +1464,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (in_array($row['topic_title'], $data['topics'])) + if (in_array($row['topic_title'], $data['topics'], false)) { $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; } @@ -1472,7 +1481,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (in_array($row['post_subject'], $data['posts'])) + if (in_array($row['post_subject'], $data['posts'], false)) { $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; $post_ids[] = (int) $row['post_id']; diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 4aa1a83b30..7e0f192b40 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -11,15 +11,29 @@ * */ -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; + + /** @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; + public function setUp() { parent::setUp(); @@ -27,8 +41,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; + global $config, $phpbb_root_path, $phpEx; if (!is_array($config)) { @@ -38,9 +51,17 @@ 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)); + $this->request = $this->getMock('\phpbb\request\request'); + $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)); + $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)); + $this->phpbb_root_path = $phpbb_root_path; } public function tearDown() @@ -52,30 +73,47 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_invalid_extension() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 100); - $file = $upload->remote_upload(self::$root_url . 'develop/blank.gif'); + /** @var \phpbb\files\upload $upload */ + $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); + $file = $upload->handle_upload('files.types.remote', 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); - $file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg'); + /** @var \phpbb\files\upload $upload */ + $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); + $file = $upload->handle_upload('files.types.remote', 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); - $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + /** @var \phpbb\files\upload $upload */ + $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); + $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->filename)); + $this->assertTrue(file_exists($file->get('filename'))); + $this->assertTrue($file->is_uploaded()); } public function test_too_large() { - $upload = new fileupload($this->filesystem, '', array('gif'), 100); - $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + /** @var \phpbb\files\upload $upload */ + $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); + $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/functional/forum_style_test.php b/tests/functional/forum_style_test.php index 65be94f4d0..b3c1115b7f 100644 --- a/tests/functional/forum_style_test.php +++ b/tests/functional/forum_style_test.php @@ -16,16 +16,28 @@ */ class phpbb_functional_forum_style_test extends phpbb_functional_test_case { + public function test_font_awesome_style() + { + $crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); + $this->assertContains('font-awesome.min', $crawler->filter('head > link[rel=stylesheet]')->eq(0)->attr('href')); + + $crawler = self::request('GET', 'viewtopic.php?t=1'); + $this->assertContains('font-awesome.min', $crawler->filter('head > link[rel=stylesheet]')->eq(0)->attr('href')); + + $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); + $this->assertContains('font-awesome.min', $crawler->filter('head > link[rel=stylesheet]')->eq(0)->attr('href')); + } + public function test_default_forum_style() { $crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); - $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href')); $crawler = self::request('GET', 'viewtopic.php?t=1'); - $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href')); $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); - $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href')); } public function test_custom_forum_style() @@ -35,13 +47,13 @@ class phpbb_functional_forum_style_test extends phpbb_functional_test_case $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2'); $crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); - $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href')); $crawler = self::request('GET', 'viewtopic.php?t=1'); - $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href')); $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); - $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href')); $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2'); $this->delete_style(2, 'test_style'); diff --git a/tests/installer/database_helper_test.php b/tests/installer/database_helper_test.php index d2ebe76ad5..ed355884f6 100644 --- a/tests/installer/database_helper_test.php +++ b/tests/installer/database_helper_test.php @@ -56,7 +56,23 @@ class phpbb_installer_database_helper_test extends phpbb_test_case */ public function test_validate_table_prefix($expected, $test_string) { - $this->assertEquals($expected, $this->database_helper->validate_table_prefix('sqlite3', $test_string)); + $db_helper_mock = $this->getMockBuilder('\phpbb\install\helper\database') + ->setMethods(array('get_available_dbms')) + ->disableOriginalConstructor() + ->getMock(); + + $db_helper_mock->method('get_available_dbms') + ->willReturn(array('sqlite3' => array( + 'LABEL' => 'SQLite3', + 'SCHEMA' => 'sqlite', + 'MODULE' => 'sqlite3', + 'DELIM' => ';', + 'DRIVER' => 'phpbb\db\driver\sqlite3', + 'AVAILABLE' => true, + '2.0.x' => false, + ))); + + $this->assertEquals($expected, $db_helper_mock->validate_table_prefix('sqlite3', $test_string)); } // Data provider for the remove comments function 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/log/fixtures/delete_log.xml b/tests/log/fixtures/delete_log.xml index 4b2402102e..393c686f0c 100644 --- a/tests/log/fixtures/delete_log.xml +++ b/tests/log/fixtures/delete_log.xml @@ -6,6 +6,7 @@ <column>user_id</column> <column>forum_id</column> <column>topic_id</column> + <column>post_id</column> <column>reportee_id</column> <column>log_ip</column> <column>log_time</column> @@ -18,6 +19,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_INSTALL_INSTALLED</value> @@ -30,6 +32,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_KEY_NOT_EXISTS</value> @@ -42,6 +45,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_CRITICAL</value> @@ -54,6 +58,7 @@ <value>12</value> <value>34</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD</value> @@ -66,6 +71,7 @@ <value>12</value> <value>45</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD</value> @@ -78,6 +84,7 @@ <value>23</value> <value>56</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD</value> @@ -90,6 +97,7 @@ <value>12</value> <value>45</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD2</value> @@ -101,6 +109,7 @@ <value>1</value> <value>0</value> <value>0</value> + <value>0</value> <value>2</value> <value>127.0.0.1</value> <value>1</value> @@ -113,6 +122,7 @@ <value>1</value> <value>0</value> <value>0</value> + <value>0</value> <value>1</value> <value>127.0.0.1</value> <value>1</value> @@ -126,6 +136,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_SINGULAR_PLURAL</value> @@ -138,6 +149,7 @@ <value>15</value> <value>3</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD3</value> @@ -150,6 +162,7 @@ <value>13</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value></value> @@ -162,6 +175,7 @@ <value>14</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value></value> @@ -174,6 +188,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value></value> @@ -186,6 +201,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value></value> diff --git a/tests/log/fixtures/empty_log.xml b/tests/log/fixtures/empty_log.xml index 261b6a622a..47fd639b17 100644 --- a/tests/log/fixtures/empty_log.xml +++ b/tests/log/fixtures/empty_log.xml @@ -6,6 +6,7 @@ <column>user_id</column> <column>forum_id</column> <column>topic_id</column> + <column>post_id</column> <column>reportee_id</column> <column>log_ip</column> <column>log_time</column> diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml index ef35884444..5b9ded9ffb 100644 --- a/tests/log/fixtures/full_log.xml +++ b/tests/log/fixtures/full_log.xml @@ -6,6 +6,7 @@ <column>user_id</column> <column>forum_id</column> <column>topic_id</column> + <column>post_id</column> <column>reportee_id</column> <column>log_ip</column> <column>log_time</column> @@ -18,6 +19,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_INSTALL_INSTALLED</value> @@ -30,6 +32,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_KEY_NOT_EXISTS</value> @@ -42,6 +45,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_CRITICAL</value> @@ -54,6 +58,7 @@ <value>12</value> <value>34</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD</value> @@ -66,6 +71,7 @@ <value>12</value> <value>45</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD</value> @@ -78,6 +84,7 @@ <value>23</value> <value>56</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD</value> @@ -90,6 +97,7 @@ <value>12</value> <value>45</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD2</value> @@ -101,6 +109,7 @@ <value>1</value> <value>0</value> <value>0</value> + <value>0</value> <value>2</value> <value>127.0.0.1</value> <value>1</value> @@ -113,6 +122,7 @@ <value>1</value> <value>0</value> <value>0</value> + <value>0</value> <value>1</value> <value>127.0.0.1</value> <value>1</value> @@ -126,6 +136,7 @@ <value>0</value> <value>0</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_SINGULAR_PLURAL</value> @@ -138,6 +149,7 @@ <value>15</value> <value>3</value> <value>0</value> + <value>0</value> <value>127.0.0.1</value> <value>1</value> <value>LOG_MOD3</value> diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 02e0b3912f..81b1f4a78c 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -46,6 +46,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 0, 'topic_id' => 0, + 'post_id' => 0, 'viewforum' => '', 'action' => 'LOG_INSTALL_INSTALLED 3.1.0-dev', @@ -65,6 +66,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 0, 'topic_id' => 0, + 'post_id' => 0, 'viewforum' => '', 'action' => '{LOG KEY NOT EXISTS}<br />additional_data', @@ -84,6 +86,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 0, 'topic_id' => 0, + 'post_id' => 0, 'viewforum' => '', 'action' => '{LOG CRITICAL}<br />critical data', @@ -103,10 +106,12 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 12, 'topic_id' => 34, + 'post_id' => 0, 'viewforum' => '', 'action' => '{LOG MOD}', 'viewtopic' => '', + 'viewpost' => '', 'viewlogs' => '', ), 5 => array( @@ -124,10 +129,12 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 12, 'topic_id' => 45, + 'post_id' => 0, 'viewforum' => '', 'action' => '{LOG MOD}', 'viewtopic' => '', + 'viewpost' => '', 'viewlogs' => '', ), 6 => array( @@ -145,10 +152,12 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 23, 'topic_id' => 56, + 'post_id' => 0, 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'), 'action' => '{LOG MOD}', 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 'f=23&t=56'), + 'viewpost' => '', 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&mode=topic_logs&t=56'), ), 7 => array( @@ -166,10 +175,12 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 12, 'topic_id' => 45, + 'post_id' => 0, 'viewforum' => '', 'action' => 'LOG_MOD2', 'viewtopic' => '', + 'viewpost' => '', 'viewlogs' => '', ), 8 => array( @@ -187,6 +198,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 0, 'topic_id' => 0, + 'post_id' => 0, 'viewforum' => '', 'action' => 'LOG_USER admin', @@ -206,6 +218,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 0, 'topic_id' => 0, + 'post_id' => 0, 'viewforum' => '', 'action' => 'LOG_USER guest', @@ -225,6 +238,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 0, 'topic_id' => 0, + 'post_id' => 0, 'viewforum' => '', 'action' => 'LOG_SINGULAR_PLURAL 2', @@ -244,10 +258,12 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'time' => 1, 'forum_id' => 15, 'topic_id' => 3, + 'post_id' => 0, 'viewforum' => '', 'action' => 'LOG_MOD3 guest ', 'viewtopic' => '', + 'viewpost' => '', 'viewlogs' => '', ), ); diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php index 1d9f5dc5bf..0116dced49 100644 --- a/tests/mock/controller_helper.php +++ b/tests/mock/controller_helper.php @@ -13,19 +13,6 @@ class phpbb_mock_controller_helper extends \phpbb\controller\helper { - public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $phpbb_root_path_ext) - { - $this->template = $template; - $this->user = $user; - $this->config = $config; - $this->symfony_request = $symfony_request; - $this->request = $request; - $this->filesystem = $filesystem; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->router = $router; - } - public function get_current_url() { return ''; 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/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 07f9ec9c56..0607098d93 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -54,7 +54,8 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case $request ); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $router, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $router, $symfony_request, $request, $filesystem, '', 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $symfony_request, $request, $this->routing_helper); $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher); } 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/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index 390bc65264..3047653d51 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -132,7 +132,7 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case ), array( '[img]https://area51.phpbb.com/images/area51.png[/img]', - '<img src="https://area51.phpbb.com/images/area51.png" alt="Image">' + '<img src="https://area51.phpbb.com/images/area51.png" class="postimage" alt="Image">' ), array( '[url]https://area51.phpbb.com/[/url]', diff --git a/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html index a17446581a..76a35542be 100644 --- a/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html +++ b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html @@ -31,7 +31,7 @@ <!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size --> -<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img --> +<!-- BEGIN img --><img src="{URL}" class="postimage" alt="{L_IMAGE}" /><!-- END img --> <!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url --> diff --git a/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html index cd2f0acae3..fad8d828fd 100644 --- a/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html +++ b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html @@ -31,7 +31,7 @@ <!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size --> -<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img --> +<!-- BEGIN img --><img src="{URL}" class="postimage" alt="{L_IMAGE}" /><!-- END img --> <!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url --> diff --git a/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html index 909c09df5a..3e38d13a32 100644 --- a/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html +++ b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html @@ -31,7 +31,7 @@ <!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size --> -<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img --> +<!-- BEGIN img --><img src="{URL}" class="postimage" alt="{L_IMAGE}" /><!-- END img --> <!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url --> diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 3c0bbb96c7..ad5bfa78fc 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -112,7 +112,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ), array( '<r><IMG src="http://example.org/foo.png"><s>[img]</s>http://example.org/foo.png<e>[/img]</e></IMG></r>', - '<img src="http://example.org/foo.png" alt="Image">', + '<img src="http://example.org/foo.png" class="postimage" alt="Image">', array('set_viewimg' => true) ), array( @@ -231,7 +231,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ), array( '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', - '<img src="http://localhost/mrgreen.gif" alt="Image">' + '<img src="http://localhost/mrgreen.gif" class="postimage" alt="Image">' ), array( '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php index f2b0d6c78b..dba3713447 100644 --- a/tests/text_processing/generate_text_for_display_test.php +++ b/tests/text_processing/generate_text_for_display_test.php @@ -173,7 +173,7 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca ), array( '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', - '<img src="http://localhost/mrgreen.gif" alt="Image">' + '<img src="http://localhost/mrgreen.gif" class="postimage" alt="Image">' ), array( '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.html b/tests/text_processing/tickets_data/PHPBB3-12195.html index d8e0f8d523..c286c0fee9 100644 --- a/tests/text_processing/tickets_data/PHPBB3-12195.html +++ b/tests/text_processing/tickets_data/PHPBB3-12195.html @@ -1 +1 @@ -<a href="//example.org/" class="postlink"><img src="//example.org/img.png" alt="Image"></a>
\ No newline at end of file +<a href="//example.org/" class="postlink"><img src="//example.org/img.png" class="postimage" alt="Image"></a>
\ No newline at end of file diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index f953970f64..1351b46002 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 { @@ -26,12 +25,16 @@ class phpbb_filespec_test extends phpbb_test_case private $filesystem; public $path; + /** @var \phpbb\language\language */ + protected $language; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + 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)) { @@ -45,9 +48,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/'; @@ -76,8 +76,17 @@ 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(); + $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()) @@ -91,14 +100,13 @@ 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->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)); } protected function tearDown() { - global $user; $this->config = array(); - $user = null; $iterator = new DirectoryIterator($this->path . 'copies'); foreach ($iterator as $fileinfo) @@ -111,6 +119,13 @@ 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); + $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 @@ -132,13 +147,26 @@ class phpbb_filespec_test extends phpbb_test_case { $upload = new phpbb_mock_fileupload(); $filespec = $this->get_filespec(); - $filespec->upload = $upload; - $filespec->file_moved = true; - $filespec->filesize = $filespec->get_filesize($this->path . $filename); + $filespec->set_upload_namespace($upload); + $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()); } + public function test_additional_checks_dimensions() + { + $upload = new phpbb_mock_fileupload(); + $filespec = $this->get_filespec(); + $filespec->set_upload_namespace($upload); + $upload->valid_dimensions = false; + $this->set_reflection_property($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 @@ -173,6 +201,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'), ); } @@ -184,7 +213,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) @@ -200,7 +229,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))); @@ -209,6 +238,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, new \bantu\IniGetWrapper\IniGetWrapper, new \FastImageSize\FastImageSize(), $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( @@ -226,7 +304,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() @@ -289,7 +367,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), ); } @@ -300,8 +378,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; @@ -311,18 +388,137 @@ class phpbb_filespec_test extends phpbb_test_case 'name' => $realname, 'type' => $mime_type, )); - $filespec->extension = $extension; - $filespec->upload = $upload; - $filespec->local = true; + $this->set_reflection_property($filespec, 'extension', $extension); + $filespec->set_upload_namespace($upload); + $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]); } - $phpEx = ''; + $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')); + } + + 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); + $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->get('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); + $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->get('file_moved'), file_exists($this->path . 'copies/gif_moved')); + $this->assertSame($expected_error, $filespec->error); } /** @@ -336,6 +532,29 @@ 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')); + } + + 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); + $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 9de384b64f..05cb8dcf93 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 @@ -22,29 +21,80 @@ class phpbb_fileupload_test extends phpbb_test_case 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 $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, $phpbb_root_path, $phpEx; if (!is_array($config)) { - $config = array(); + $config = new \phpbb\config\config(array()); } $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->request = $this->getMock('\phpbb\request\request'); + $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)); + $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( + $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); + $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, + $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); $this->path = __DIR__ . '/fixture/'; + $this->phpbb_root_path = $phpbb_root_path; } private function gen_valid_filespec() @@ -69,15 +119,38 @@ 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, $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(); $upload->common_checks($file); $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->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->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', '<body>' . 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 fileupload($this->filesystem, '', array('jpg'), 100); + $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(); $file->realname = 'invalid?'; $upload->common_checks($file); @@ -86,7 +159,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, $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(); $file->filesize = 1000; $upload->common_checks($file); @@ -95,7 +170,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, $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(); $upload->common_checks($file); $this->assertEquals(0, sizeof($file->error)); @@ -103,33 +180,41 @@ 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, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); + $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'); + $file = $upload->handle_upload('files.types.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() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 1000); + $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); copy($this->path . 'jpg', $this->path . 'jpg.jpg'); - $file = $upload->local_upload($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); + $this->assertFalse($file->get('file_moved')); $this->assertEquals(1, sizeof($file->error)); } public function test_move_existent_file_overwrite() { - $upload = new fileupload($this->filesystem, '', array('jpg'), 1000); + $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); 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('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)); @@ -138,7 +223,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, $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); $file1 = $this->gen_valid_filespec(); $file2 = $this->gen_valid_filespec(); diff --git a/tests/upload/imagesize_test.php b/tests/upload/imagesize_test.php index bfea4b819d..d20e866dab 100644 --- a/tests/upload/imagesize_test.php +++ b/tests/upload/imagesize_test.php @@ -16,7 +16,7 @@ require_once(__DIR__ . '/../../phpBB/includes/functions.php'); class phpbb_upload_imagesize_test extends \phpbb_test_case { - /** @var \fastImageSize\fastImageSize */ + /** @var \FastImageSize\FastImageSize */ protected $imagesize; /** @var string Path to fixtures */ @@ -25,7 +25,7 @@ class phpbb_upload_imagesize_test extends \phpbb_test_case public function setUp() { parent::setUp(); - $this->imagesize = new \fastImageSize\fastImageSize(); + $this->imagesize = new \FastImageSize\FastImageSize(); $this->path = __DIR__ . '/fixture/'; } 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..9f46a78d5b 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,44 @@ 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')); + $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_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.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(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 +71,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); |