From 999995b83a507116563a62435e2c419de6f7bf63 Mon Sep 17 00:00:00 2001 From: Andreas Piening Date: Tue, 8 Dec 2009 23:08:07 +0000 Subject: [PATCH] MINOR: added cookies to Director::test() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@94684 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Director.php | 5 +++-- dev/FunctionalTest.php | 10 ++++++---- dev/TestSession.php | 14 ++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/control/Director.php b/core/control/Director.php index 4a5bade9a..1167e41ff 100755 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -170,12 +170,13 @@ class Director { * Overwritten by $postVars['_method'] if present. * @param string $body The HTTP body * @param array $headers HTTP headers with key-value pairs + * @param array $cookies to populate $_COOKIE * @return SS_HTTPResponse * * @uses getControllerForURL() The rule-lookup logic is handled by this. * @uses Controller::run() Controller::run() handles the page logic for a Director::direct() call. */ - static function test($url, $postVars = null, $session = null, $httpMethod = null, $body = null, $headers = null) { + static function test($url, $postVars = null, $session = null, $httpMethod = null, $body = null, $headers = null, $cookies = null) { // These are needed so that calling Director::test() doesnt muck with whoever is calling it. // Really, it's some inapproriate coupling and should be resolved by making less use of statics $oldStage = Versioned::current_stage(); @@ -216,7 +217,7 @@ class Director { $_GET = (array)$getVars; $_POST = (array)$postVars; $_SESSION = $session ? $session->inst_getAll() : array(); - $_COOKIE = array(); + $_COOKIE = (array) $cookies; $_SERVER['REQUEST_URI'] = Director::baseURL() . $urlWithQuerystring; $req = new SS_HTTPRequest($httpMethod, $url, $getVars, $postVars, $body); diff --git a/dev/FunctionalTest.php b/dev/FunctionalTest.php index e02c66d84..04e83aa32 100644 --- a/dev/FunctionalTest.php +++ b/dev/FunctionalTest.php @@ -86,20 +86,22 @@ class FunctionalTest extends SapphireTest { /** * Submit a get request + * @uses Director::test() */ - function get($url) { + function get($url, $session = null, $headers = null, $cookies = null) { $this->cssParser = null; - $response = $this->mainSession->get($url); + $response = $this->mainSession->get($url, $session, $headers, $cookies); if($this->autoFollowRedirection && is_object($response) && $response->getHeader('Location')) $response = $this->mainSession->followRedirection(); return $response; } /** * Submit a post request + * @uses Director::test() */ - function post($url, $data) { + function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) { $this->cssParser = null; - $response = $this->mainSession->post($url, $data); + $response = $this->mainSession->post($url, $data, $headers, $session, $body, $cookies); if($this->autoFollowRedirection && is_object($response) && $response->getHeader('Location')) $response = $this->mainSession->followRedirection(); return $response; } diff --git a/dev/TestSession.php b/dev/TestSession.php index 78b5b27f2..34ea50559 100644 --- a/dev/TestSession.php +++ b/dev/TestSession.php @@ -40,9 +40,10 @@ class TestSession { * Submit a get request * @uses Director::test() */ - function get($url) { - $headers = ($this->lastUrl) ? array('Referer'=>$this->lastUrl) : null; - $this->lastResponse = Director::test($url, null, $this->session, null, null, $headers); + function get($url, $session = null, $headers = null, $cookies = null) { + $headers = (array) $headers; + if($this->lastUrl) $headers['Referer'] = $this->lastUrl; + $this->lastResponse = Director::test($url, null, $session ? $session : $this->session, null, null, $headers, $cookies); $this->lastUrl = $url; if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING); return $this->lastResponse; @@ -52,9 +53,10 @@ class TestSession { * Submit a post request * @uses Director::test() */ - function post($url, $data, $headers = null) { - $headers = ($this->lastUrl) ? array('Referer'=>$this->lastUrl) : null; - $this->lastResponse = Director::test($url, $data, $this->session, null, null, $headers); + function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) { + $headers = (array) $headers; + if($this->lastUrl) $headers['Referer'] = $this->lastUrl; + $this->lastResponse = Director::test($url, $data, $session ? $session : $this->session, null, $body, $headers, $cookies); $this->lastUrl = $url; if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING); return $this->lastResponse;