diff options
Diffstat (limited to 'tests/path_helper/path_helper_test.php')
-rw-r--r-- | tests/path_helper/path_helper_test.php | 95 |
1 files changed, 79 insertions, 16 deletions
diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index a3ad901379..27e94d6a07 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -13,6 +13,7 @@ class phpbb_path_helper_test extends phpbb_test_case { + /** @var \phpbb\path_helper */ protected $path_helper; protected $phpbb_root_path = ''; @@ -20,13 +21,15 @@ class phpbb_path_helper_test extends phpbb_test_case { parent::setUp(); - $this->set_phpbb_root_path(); + $filesystem = new \phpbb\filesystem(); + $this->set_phpbb_root_path($filesystem); $this->path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), new \phpbb\filesystem(), + $this->getMock('\phpbb\request\request'), $this->phpbb_root_path, 'php' ); @@ -40,9 +43,9 @@ class phpbb_path_helper_test extends phpbb_test_case * any time we wish to use it in one of these functions (and * also in general for everything else) */ - public function set_phpbb_root_path() + public function set_phpbb_root_path($filesystem) { - $this->phpbb_root_path = dirname(__FILE__) . './../../phpBB/'; + $this->phpbb_root_path = $filesystem->clean_path(dirname(__FILE__) . '/../../phpBB/'); } public function test_get_web_root_path() @@ -53,7 +56,8 @@ class phpbb_path_helper_test extends phpbb_test_case public function basic_update_web_root_path_data() { - $this->set_phpbb_root_path(); + $filesystem = new \phpbb\filesystem(); + $this->set_phpbb_root_path($filesystem); return array( array( @@ -71,7 +75,7 @@ class phpbb_path_helper_test extends phpbb_test_case ), array( $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + $filesystem->clean_path($this->phpbb_root_path . $this->phpbb_root_path . 'test.php'), ), ); } @@ -81,51 +85,55 @@ class phpbb_path_helper_test extends phpbb_test_case */ public function test_basic_update_web_root_path($input, $expected) { - $this->assertEquals($expected, $this->path_helper->update_web_root_path($input, $symfony_request)); + $this->assertEquals($expected, $this->path_helper->update_web_root_path($input)); } public function update_web_root_path_data() { - $this->set_phpbb_root_path(); + $this->set_phpbb_root_path(new \phpbb\filesystem()); return array( array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . 'test.php', '/', + null, + null, + '', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '//', + null, + null, + './../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '//', 'foo/bar.php', 'bar.php', + './../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../../test.php', '/foo/template', '/phpbb3-fork/phpBB/app.php/foo/template', '/phpbb3-fork/phpBB/app.php', + './../../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '/foo/template', '/phpbb3-fork/phpBB/foo/template', '/phpbb3-fork/phpBB/app.php', + './../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '/', '/phpbb3-fork/phpBB/app.php/', '/phpbb3-fork/phpBB/app.php', + './../', ), ); } @@ -133,9 +141,9 @@ class phpbb_path_helper_test extends phpbb_test_case /** * @dataProvider update_web_root_path_data */ - public function test_update_web_root_path($input, $expected, $getPathInfo, $getRequestUri = null, $getScriptName = null) + public function test_update_web_root_path($input, $getPathInfo, $getRequestUri, $getScriptName, $correction) { - $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( + $symfony_request = $this->getMock('\phpbb\symfony_request', array(), array( new phpbb_mock_request(), )); $symfony_request->expects($this->any()) @@ -151,11 +159,12 @@ class phpbb_path_helper_test extends phpbb_test_case $path_helper = new \phpbb\path_helper( $symfony_request, new \phpbb\filesystem(), + $this->getMock('\phpbb\request\request'), $this->phpbb_root_path, 'php' ); - $this->assertEquals($expected, $path_helper->update_web_root_path($input, $symfony_request)); + $this->assertEquals($correction . $input, $path_helper->update_web_root_path($input, $symfony_request)); } public function clean_url_data() @@ -331,4 +340,58 @@ class phpbb_path_helper_test extends phpbb_test_case { $this->assertEquals($expected, $this->path_helper->append_url_params($url, $params, $is_amp)); } + + public function get_web_root_path_from_ajax_referer_data() + { + return array( + array( + 'http://www.phpbb.com/community/route1/route2/', + 'http://www.phpbb.com/community', + '../../', + ), + array( + 'http://www.phpbb.com/community/route1/route2', + 'http://www.phpbb.com/community', + '../', + ), + array( + 'http://www.phpbb.com/community/route1', + 'http://www.phpbb.com/community', + '', + ), + array( + 'http://www.phpbb.com/community/', + 'http://www.phpbb.com/community', + '', + ), + array( + 'http://www.phpbb.com/notcommunity/route1/route2/', + 'http://www.phpbb.com/community', + '../../../community/', + ), + array( + 'http://www.phpbb.com/notcommunity/route1/route2', + 'http://www.phpbb.com/community', + '../../community/', + ), + array( + 'http://www.phpbb.com/notcommunity/route1', + 'http://www.phpbb.com/community', + '../community/', + ), + array( + 'http://www.phpbb.com/notcommunity/', + 'http://www.phpbb.com/community', + '../community/', + ), + ); + } + + /** + * @dataProvider get_web_root_path_from_ajax_referer_data + */ + public function test_get_web_root_path_from_ajax_referer($referer_url, $board_url, $expected) + { + $this->assertEquals($this->phpbb_root_path . $expected, $this->path_helper->get_web_root_path_from_ajax_referer($referer_url, $board_url)); + } } |