diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2013-09-19 11:49:13 -0500 |
---|---|---|
committer | Nathan Guse <nathaniel.guse@gmail.com> | 2013-09-19 11:49:13 -0500 |
commit | 2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e (patch) | |
tree | 914249f2e1d6d4e28a073d20f898a03aaa69f5f8 | |
parent | d85ae0f7bc0bd9663eda83c6713f0ef71289b0f4 (diff) | |
download | forums-2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e.tar forums-2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e.tar.gz forums-2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e.tar.bz2 forums-2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e.tar.xz forums-2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e.zip |
[ticket/11850] Fix extract current page test
PHPBB3-11850
-rw-r--r-- | tests/security/base.php | 18 | ||||
-rw-r--r-- | tests/security/extract_current_page_test.php | 40 |
2 files changed, 47 insertions, 11 deletions
diff --git a/tests/security/base.php b/tests/security/base.php index 08878ad60d..c7dbbb550a 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -14,7 +14,7 @@ abstract class phpbb_security_test_base extends phpbb_test_case */ protected function setUp() { - global $user, $phpbb_root_path, $request; + global $user, $phpbb_root_path, $phpEx, $request, $symfony_request, $phpbb_filesystem; // Put this into a global function being run by every test to init a proper user session $server['HTTP_HOST'] = 'localhost'; @@ -37,6 +37,22 @@ abstract class phpbb_security_test_base extends phpbb_test_case */ $request = new phpbb_mock_request(array(), array(), array(), $server); + $symfony_request = $this->getMock("phpbb_symfony_request", array(), array( + $request, + )); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($server['SCRIPT_NAME'])); + $symfony_request->expects($this->any()) + ->method('getQueryString') + ->will($this->returnValue($server['QUERY_STRING'])); + $symfony_request->expects($this->any()) + ->method('getBasePath') + ->will($this->returnValue($server['REQUEST_URI'])); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue('/')); + $phpbb_filesystem = new phpbb_filesystem($symfony_request, $phpbb_root_path, $phpEx); // Set no user and trick a bit to circumvent errors $user = new phpbb_user(); diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index d77cbbcaf3..2c69e7955b 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -26,13 +26,23 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base */ public function test_query_string_php_self($url, $query_string, $expected) { - global $request; + global $symfony_request, $request; - $request->merge(phpbb_request_interface::SERVER, array( - 'PHP_SELF' => $url, - 'QUERY_STRING' => $query_string, + $symfony_request = $this->getMock("phpbb_symfony_request", array(), array( + $request, )); - + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($url)); + $symfony_request->expects($this->any()) + ->method('getQueryString') + ->will($this->returnValue($query_string)); + $symfony_request->expects($this->any()) + ->method('getBasePath') + ->will($this->returnValue($server['REQUEST_URI'])); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue('/')); $result = phpbb_session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with PHP_SELF filled.'; @@ -44,12 +54,23 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base */ public function test_query_string_request_uri($url, $query_string, $expected) { - global $request; + global $symfony_request, $request; - $request->merge(phpbb_request_interface::SERVER, array( - 'PHP_SELF' => $url, - 'QUERY_STRING' => $query_string, + $symfony_request = $this->getMock("phpbb_symfony_request", array(), array( + $request, )); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($url)); + $symfony_request->expects($this->any()) + ->method('getQueryString') + ->will($this->returnValue($query_string)); + $symfony_request->expects($this->any()) + ->method('getBasePath') + ->will($this->returnValue($server['REQUEST_URI'])); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue('/')); $result = phpbb_session::extract_current_page('./'); @@ -57,4 +78,3 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base $this->assertEquals($expected, $result['query_string'], $label); } } - |