diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/controller/common_helper_route.php | 78 | ||||
-rw-r--r-- | tests/functions_acp/build_cfg_template_test.php | 8 | ||||
-rw-r--r-- | tests/request/request_test.php | 106 |
3 files changed, 169 insertions, 23 deletions
diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index ff1af8119b..ea77a289c9 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -18,6 +18,15 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; abstract class phpbb_controller_common_helper_route extends phpbb_test_case { protected $root_path; + private $user; + private $config; + private $template; + private $extension_manager; + private $request; + private $symfony_request; + private $provider; + private $filesystem; + private $phpbb_path_helper; public function setUp() { @@ -68,6 +77,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case protected function generate_route_objects() { + global $request; + $this->request = new phpbb_mock_request(); $this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER); $this->request->overwrite('SCRIPT_FILENAME', $this->get_script_name(), \phpbb\request\request_interface::SERVER); @@ -75,6 +86,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $this->request->overwrite('SERVER_NAME', 'localhost', \phpbb\request\request_interface::SERVER); $this->request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER); + $request = $this->request; + $this->symfony_request = new \phpbb\symfony_request( $this->request ); @@ -135,8 +148,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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id), $description); } public function helper_url_data_with_rewrite() @@ -175,8 +188,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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id), $description); } public function helper_url_data_absolute() @@ -215,8 +228,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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); } public function helper_url_data_relative_path() @@ -255,8 +268,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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); } public function helper_url_data_network() @@ -295,8 +308,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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); } //TODO public function helper_url_data_absolute_with_rewrite() @@ -335,8 +348,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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); } public function helper_url_data_relative_path_with_rewrite() @@ -375,8 +388,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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); } public function helper_url_data_network_with_rewrite() @@ -415,7 +428,40 @@ 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->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); + } + + public function helper_url_data_force_server_vars() + { + return array( + array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_URL, 'http://my_server:443/my/board/app.php/foo'), + array(true, true, 'my_server', 444, '/my/board', 'https://', UrlGeneratorInterface::ABSOLUTE_URL, 'https://my_server:444/my/board/foo'), + array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::NETWORK_PATH, '//my_server:443/my/board/app.php/foo'), + array(true, true, 'my_server', 444, '/my/board', 'https://', UrlGeneratorInterface::NETWORK_PATH, '//my_server:444/my/board/foo'), + array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_PATH, '/my/board/app.php/foo'), + array(true, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_PATH, '/my/board/foo'), + array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::RELATIVE_PATH, 'app.php/foo'), + array(true, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::RELATIVE_PATH, 'foo'), + ); + } + + /** + * @dataProvider helper_url_data_force_server_vars() + */ + public function test_helper_url_force_server_vars($enable_mod_rewrite, $force_server_vars, $server_name, $server_port, $script_path, $server_protocol, $type, $expected) + { + $this->config = new \phpbb\config\config(array( + 'enable_mod_rewrite' => $enable_mod_rewrite, + 'force_server_vars' => $force_server_vars, + 'server_name' => $server_name, + 'server_port' => $server_port, + 'script_path' => $script_path, + 'server_protocol' => $server_protocol, + )); + + $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + static::assertEquals($expected, $helper->route('controller1', array(), false, false, $type)); + } } diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index a8d7ae6f09..2e3a8adac7 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -68,7 +68,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - '<input id="number_key_name" type="number" size="2" maxlength="2" min="5" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" size="2" maxlength="2" min="5" max="15" name="config[config_key_name_height]" value="20" />', + '<input id="number_key_name" type="number" min="5" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" min="5" max="15" name="config[config_key_name_height]" value="20" />', ), array( array('dimension', 0, 15), @@ -76,7 +76,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - '<input id="number_key_name" type="number" size="2" maxlength="2" min="0" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" size="2" maxlength="2" min="0" max="15" name="config[config_key_name_height]" value="20" />', + '<input id="number_key_name" type="number" min="0" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" min="0" max="15" name="config[config_key_name_height]" value="20" />', ), ); } @@ -104,7 +104,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name' => 10), 'config_key_name', array(), - '<input id="number_key_name" type="number" maxlength="2" min="5" max="15" name="config[config_key_name]" value="10" />', + '<input id="number_key_name" type="number" min="5" max="15" name="config[config_key_name]" value="10" />', ), array( array('number', -1, 9999), @@ -112,7 +112,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name' => 10), 'config_key_name', array(), - '<input id="number_key_name" type="number" maxlength="4" min="-1" max="9999" name="config[config_key_name]" value="10" />', + '<input id="number_key_name" type="number" min="-1" max="9999" name="config[config_key_name]" value="10" />', ), ); } diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 131abe6aac..ebaea1f9ef 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -13,7 +13,10 @@ class phpbb_request_test extends phpbb_test_case { + /** @var \phpbb\request\type_cast_helper_interface */ private $type_cast_helper; + + /** @var \phpbb\request\request */ private $request; protected function setUp() @@ -143,15 +146,112 @@ class phpbb_request_test extends phpbb_test_case $this->assertTrue($this->request->is_ajax()); } - public function test_is_secure() + public function data_is_secure() + { + return array( + array( + array( + 'HTTPS' => 'on', + ), + true, + ), + array( + array( + 'HTTPS' => '1', + ), + true, + ), + array( + array( + 'HTTPS' => 'yes', + ), + true, + ), + array( + array( + 'HTTPS' => 1, + ), + true, + ), + array( + array( + 'HTTPS' => 'off', + ), + false, + ), + array( + array( + 'HTTPS' => '0', + ), + false, + ), + array( + array( + 'HTTPS' => 0, + ), + false, + ), + array( + array( + 'HTTPS' => '', + ), + false, + ), + array( + array( + 'HTTPS' => 'off', + 'HTTP_X_FORWARDED_PROTO' => 'https', + ), + true, + ), + array( + array( + 'HTTPS' => 'on', + 'HTTP_X_FORWARDED_PROTO' => 'http', + ), + true, + ), + array( + array( + 'HTTPS' => 'off', + 'HTTP_X_FORWARDED_PROTO' => 'http', + ), + false, + ), + array( + array( + 'HTTP_X_FORWARDED_PROTO' => 'http', + ), + false, + ), + array( + array( + 'HTTP_X_FORWARDED_PROTO' => 'https', + ), + true, + ), + array( + array( + 'HTTPS' => 'on', + 'HTTP_X_FORWARDED_PROTO' => 'http', + ), + true, + ), + ); + } + + /** + * @dataProvider data_is_secure + */ + public function test_is_secure($server_data, $expected) { $this->assertFalse($this->request->is_secure()); $this->request->enable_super_globals(); - $_SERVER['HTTPS'] = 'on'; + $_SERVER = $server_data; $this->request = new \phpbb\request\request($this->type_cast_helper); - $this->assertTrue($this->request->is_secure()); + $this->assertSame($expected, $this->request->is_secure()); } public function test_variable_names() |