diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-09-04 23:20:06 +0200 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-09-16 19:44:58 +0200 |
commit | bb5d6a2551f7329162424f1ae0edcd711b4bd5e6 (patch) | |
tree | 8104700330bf5cb9946c432344357ca3a211cf3c | |
parent | dab6b99bcda411027d040c3b985460990f2a117a (diff) | |
download | forums-bb5d6a2551f7329162424f1ae0edcd711b4bd5e6.tar forums-bb5d6a2551f7329162424f1ae0edcd711b4bd5e6.tar.gz forums-bb5d6a2551f7329162424f1ae0edcd711b4bd5e6.tar.bz2 forums-bb5d6a2551f7329162424f1ae0edcd711b4bd5e6.tar.xz forums-bb5d6a2551f7329162424f1ae0edcd711b4bd5e6.zip |
[ticket/13036] Add unit tests
PHPBB3-13036
-rw-r--r-- | phpBB/phpbb/controller/helper.php | 5 | ||||
-rw-r--r-- | tests/controller/helper_route_test.php | 124 |
2 files changed, 129 insertions, 0 deletions
diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index 77fe5cb3a8..e2932086db 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -155,6 +155,11 @@ class helper $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url); } + if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) + { + $route_url = 'app.' . $this->php_ext . '/' . $route_url; + } + return append_sid($route_url . $anchor, false, $is_amp, $session_id, true); } diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php index 203abccafb..f4c16701ff 100644 --- a/tests/controller/helper_route_test.php +++ b/tests/controller/helper_route_test.php @@ -13,6 +13,8 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + class phpbb_controller_helper_route_test extends phpbb_test_case { public function setUp() @@ -26,6 +28,8 @@ class phpbb_controller_helper_route_test extends phpbb_test_case $request->overwrite('SCRIPT_NAME', '/app.php', \phpbb\request\request_interface::SERVER); $request->overwrite('SCRIPT_FILENAME', 'app.php', \phpbb\request\request_interface::SERVER); $request->overwrite('REQUEST_URI', '/app.php', \phpbb\request\request_interface::SERVER); + $request->overwrite('SERVER_NAME', 'localhost', \phpbb\request\request_interface::SERVER); + $request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER); $this->symfony_request = new \phpbb\symfony_request( $request @@ -140,4 +144,124 @@ class phpbb_controller_helper_route_test extends phpbb_test_case $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, '', 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); } + + public function helper_url_data_absolute() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, 'http://localhost/app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, 'http://localhost/app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'http://localhost/app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'http://localhost/app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'http://localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'http://localhost/app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'http://localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, 'http://localhost/app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, 'http://localhost/app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, 'http://localhost/app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_absolute() + */ + 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->filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); + } + + public function helper_url_data_relative_path() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, 'app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, 'app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, 'app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_relative_path() + */ + 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->filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); + } + + public function helper_url_data_network() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, '//localhost/app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, '//localhost/app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '//localhost/app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '//localhost/app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '//localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '//localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '//localhost/app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '//localhost/app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '//localhost/app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, '//localhost/app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, '//localhost/app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, '//localhost/app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_network() + */ + 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->filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); + } } |