From 6692db892f538d3a72f1dbd06af9a94f24a9da9a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 18:19:50 -0500 Subject: [ticket/11832] update_web_root_path helper and tests PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/filesystem/web_root_path_test.php (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php new file mode 100644 index 0000000000..7b44ac8c67 --- /dev/null +++ b/tests/filesystem/web_root_path_test.php @@ -0,0 +1,70 @@ +set_phpbb_root_path(); + + $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + } + + /** + * Set the phpbb_root_path + * + * This is necessary because dataProvider functions are called + * before setUp or setUpBeforeClass; so we must set the path + * 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() + { + $this->phpbb_root_path = __DIR__ . './../../phpBB/'; + } + + public function test_get_web_root_path() + { + // Symfony Request = null, so always should return phpbb_root_path + $this->assertEquals($this->phpbb_root_path, $this->filesystem->get_web_root_path()); + } + + public function update_web_root_path_data() + { + $this->set_phpbb_root_path(); + + return array( + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + ), + array( + 'test.php', + $this->phpbb_root_path . 'test.php', + ), + array( + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + ), + ); + } + + /** + * @dataProvider update_web_root_path_data + */ + public function test_update_web_root_path($input, $expected) + { + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input)); + } +} -- cgit v1.2.1 From 3684d8e9711516264fedac0519262891d9894ea1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 10:13:26 -0500 Subject: [ticket/11832] Use $phpbb_filesystem instead of the container in append_sid PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 7b44ac8c67..3c530619dc 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,7 +18,9 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + global $phpbb_filesystem; + + $phpbb_filesystem = $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); } /** -- cgit v1.2.1 From c46637990e5937881f98d9711783fe9982532884 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 10:14:57 -0500 Subject: [ticket/11832] Use dirname(__FILE__) PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 3c530619dc..3c9637fe06 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -33,7 +33,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case */ public function set_phpbb_root_path() { - $this->phpbb_root_path = __DIR__ . './../../phpBB/'; + $this->phpbb_root_path = dirname(__FILE__) . './../../phpBB/'; } public function test_get_web_root_path() -- cgit v1.2.1 From 3a4efa79592616ac099e95d07e9aed52bc5a19a3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 11:15:24 -0500 Subject: [ticket/11832] More extensive testing PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 49 ++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 3c9637fe06..badc2fab58 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,9 +18,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - global $phpbb_filesystem; - - $phpbb_filesystem = $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); } /** @@ -49,7 +47,6 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case return array( array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . 'test.php', ), array( 'test.php', @@ -57,7 +54,28 @@ class phpbb_filesystem_web_root_path_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', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + '/', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + '//', + ), + 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', + '////', ), ); } @@ -65,8 +83,25 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case /** * @dataProvider update_web_root_path_data */ - public function test_update_web_root_path($input, $expected) + public function test_update_web_root_path($input, $expected = null, $getPathInfo = null, $getRequestUri = null, $getScriptName = null) { - $this->assertEquals($expected, $this->filesystem->update_web_root_path($input)); + $expected = ($expected === null) ? $input : $expected; + + $symfony_request = null; + if ($getPathInfo !== null) + { + $symfony_request = $this->getMock("Symfony\Component\HttpFoundation\Request"); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue($getPathInfo)); + $symfony_request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue($getRequestUri)); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($getScriptName)); + } + + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); } } -- cgit v1.2.1 From b06c8a80d15c52dd53b12065d5e6e9d56f203ceb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 10:25:49 -0500 Subject: [ticket/11832] Fix the web path corrections Add some real life examples to test PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index badc2fab58..8e0ba278e0 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -62,7 +62,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', '//', ), array( @@ -75,7 +75,16 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case 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', ), ); } -- cgit v1.2.1 From aa710df2db2512f6065f91dcf8b5fc7d100edf41 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 09:52:02 -0500 Subject: [ticket/11832] Create phpbb_symfony_request to handle initiating symfony_request Now symfony_request is also a service (removed the function phpbb_create_symfony_request). Inject symfony request into filesystem Cleanup for the tests PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 55 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 8e0ba278e0..b681c26de9 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,7 +18,8 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + $symfony_request = new phpbb_symfony_request(new phpbb_mock_request()); + $this->filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); } /** @@ -40,13 +41,14 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->assertEquals($this->phpbb_root_path, $this->filesystem->get_web_root_path()); } - public function update_web_root_path_data() + public function basic_update_web_root_path_data() { $this->set_phpbb_root_path(); return array( array( $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', ), array( 'test.php', @@ -54,7 +56,24 @@ class phpbb_filesystem_web_root_path_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', ), + ); + } + + /** + * @dataProvider basic_update_web_root_path_data + */ + public function test_basic_update_web_root_path($input, $expected) + { + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); + } + + public function update_web_root_path_data() + { + $this->set_phpbb_root_path(); + + return array( array( $this->phpbb_root_path . 'test.php', $this->phpbb_root_path . 'test.php', @@ -92,25 +111,23 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case /** * @dataProvider update_web_root_path_data */ - public function test_update_web_root_path($input, $expected = null, $getPathInfo = null, $getRequestUri = null, $getScriptName = null) + public function test_update_web_root_path($input, $expected, $getPathInfo, $getRequestUri = null, $getScriptName = null) { - $expected = ($expected === null) ? $input : $expected; + $symfony_request = $this->getMock("phpbb_symfony_request", array(), array( + new phpbb_mock_request(), + )); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue($getPathInfo)); + $symfony_request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue($getRequestUri)); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($getScriptName)); - $symfony_request = null; - if ($getPathInfo !== null) - { - $symfony_request = $this->getMock("Symfony\Component\HttpFoundation\Request"); - $symfony_request->expects($this->any()) - ->method('getPathInfo') - ->will($this->returnValue($getPathInfo)); - $symfony_request->expects($this->any()) - ->method('getRequestUri') - ->will($this->returnValue($getRequestUri)); - $symfony_request->expects($this->any()) - ->method('getScriptName') - ->will($this->returnValue($getScriptName)); - } + $filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); - $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); + $this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request)); } } -- cgit v1.2.1 From b4a374dc73eda55db1c67b87bd65a73f79411ef5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 10:58:03 -0500 Subject: [ticket/11832] Fix INCLUDE(JS/CSS) PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/filesystem/web_root_path_test.php') diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index b681c26de9..ae59d4f709 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,8 +18,13 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $symfony_request = new phpbb_symfony_request(new phpbb_mock_request()); - $this->filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); + $this->filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + 'php' + ); } /** @@ -126,7 +131,11 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ->method('getScriptName') ->will($this->returnValue($getScriptName)); - $filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); + $filesystem = new phpbb_filesystem( + $symfony_request, + $this->phpbb_root_path, + 'php' + ); $this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request)); } -- cgit v1.2.1