From 0bf6966c5228d446c4f0d3862619db0f619c7369 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 13 Jul 2011 19:20:16 +0200 Subject: [feature/request-class] Add server(), header() and is_ajax() to request Extend the request class with helpers for reading server vars (server()) and HTTP request headers (header()). Refactor the existing code base to make use of these helpers, make $_SERVER a deactivated super global. Also introduce an is_ajax() method, which checks the X-Requested-With header for the value 'XMLHttpRequest', which is sent by JavaScript libraries, such as jQuery. PHPBB3-9716 --- tests/request/request_test.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tests/request/request_test.php') diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 203c9fd880..9999e88121 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -23,7 +23,6 @@ class phpbb_request_test extends phpbb_test_case $_GET['unset'] = ''; $this->type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $this->request = new phpbb_request($this->type_cast_helper); } @@ -60,6 +59,20 @@ class phpbb_request_test extends phpbb_test_case $this->assertFalse($this->request->is_set_post('unset')); } + public function test_is_ajax_without_ajax() + { + $this->assertFalse($this->request->is_ajax()); + } + + public function test_is_ajax_with_ajax() + { + $this->request->enable_super_globals(); + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $this->request = new phpbb_request($this->type_cast_helper); + + $this->assertTrue($this->request->is_ajax()); + } + public function test_variable_names() { $expected = array('test', 'unset'); -- cgit v1.2.1 From 24e9fb24d105b8e475dbaf66fd99be2839b86675 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 6 Aug 2011 19:47:12 +0200 Subject: [feature/request-class] Make server() use the $html_encode parameter $request->server() should not auto html-escape values. header() however should. Also introduce some tests for this behaviour. Thanks to nn- for catching this. PHPBB3-9716 --- tests/request/request_test.php | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/request/request_test.php') diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 9999e88121..24c9ae5112 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -22,6 +22,10 @@ class phpbb_request_test extends phpbb_test_case $_REQUEST['test'] = 3; $_GET['unset'] = ''; + $_SERVER['HTTP_HOST'] = 'example.com'; + $_SERVER['HTTP_ACCEPT'] = 'application/json'; + $_SERVER['HTTP_SOMEVAR'] = ''; + $this->type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); $this->request = new phpbb_request($this->type_cast_helper); } @@ -43,6 +47,46 @@ class phpbb_request_test extends phpbb_test_case $this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']'); } + public function test_server() + { + $this->assertEquals('example.com', $this->request->server('HTTP_HOST')); + } + + public function test_server_escaping() + { + $this->type_cast_helper + ->expects($this->once()) + ->method('recursive_set_var') + ->with( + $this->anything(), + '', + true, + false + ); + + $this->request->server('HTTP_SOMEVAR'); + } + + public function test_header() + { + $this->assertEquals('application/json', $this->request->header('Accept')); + } + + public function test_header_escaping() + { + $this->type_cast_helper + ->expects($this->once()) + ->method('recursive_set_var') + ->with( + $this->anything(), + '', + true, + true + ); + + $this->request->header('SOMEVAR'); + } + /** * Checks that directly accessing $_POST will trigger * an error. -- cgit v1.2.1 From a48889fed83b007202e76ddf1ba5436eca310df0 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 18 Aug 2011 22:21:50 +0200 Subject: [feature/request-class] Add is_secure method to request for HTTPS PHPBB3-9716 --- tests/request/request_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/request/request_test.php') diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 24c9ae5112..2e56841601 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -117,6 +117,17 @@ class phpbb_request_test extends phpbb_test_case $this->assertTrue($this->request->is_ajax()); } + public function test_is_secure() + { + $this->assertFalse($this->request->is_secure()); + + $this->request->enable_super_globals(); + $_SERVER['HTTPS'] = 'on'; + $this->request = new phpbb_request($this->type_cast_helper); + + $this->assertTrue($this->request->is_secure()); + } + public function test_variable_names() { $expected = array('test', 'unset'); -- cgit v1.2.1 From fd08cd8dd013c0d1bf8e18611f798c6987d9de9c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 18 Aug 2011 23:19:48 +0200 Subject: [feature/request-class] Remove $html_encode arg, force manual decoding PHPBB3-9716 --- tests/request/request_test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/request/request_test.php') diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 2e56841601..e492fa5cf1 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -60,8 +60,7 @@ class phpbb_request_test extends phpbb_test_case ->with( $this->anything(), '', - true, - false + true ); $this->request->server('HTTP_SOMEVAR'); @@ -80,7 +79,6 @@ class phpbb_request_test extends phpbb_test_case ->with( $this->anything(), '', - true, true ); -- cgit v1.2.1 From 66c50f6b30400b729d3fea4fb06dad5eb559aa51 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 2 Jan 2012 17:14:00 +0000 Subject: [ticket/9916] Updating license in non-distributed files PHPBB3-9916 --- tests/request/request_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/request/request_test.php') diff --git a/tests/request/request_test.php b/tests/request/request_test.php index e492fa5cf1..bca5125b7a 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -4,7 +4,7 @@ * @package testing * @version $Id$ * @copyright (c) 2009 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1