BUGFIX: Fixed superglobal masquerading in Director::test()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60393 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-11 05:26:51 +00:00
parent eb9e66808c
commit 3b1a6293a2

View File

@ -153,11 +153,29 @@ class Director {
list($url, $getVarsEncoded) = explode('?', $url, 2);
parse_str($getVarsEncoded, $getVars);
}
if(!$session) $session = new Session(null);
// Back up the current values of the superglobals
$existingRequestVars = $_REQUEST;
$existingGetVars = $_GET;
$existingPostVars = $_POST;
$existingSessionVars = $_SESSION;
// Replace the superglobals with appropriate test values
$_REQUEST = array_merge((array)$getVars, (array)$post);
$_GET = (array)$getVars;
$_POST = (array)$post;
$_SESSION = $session ? $session->inst_getAll() : array();
$req = new HTTPRequest($httpMethod, $url, $getVars, $postVars, $body);
if($headers) foreach($headers as $k => $v) $req->addHeader($k, $v);
$result = Director::handleRequest($req, $session);
// Restore the superglobals
$_REQUEST = $existingRequestVars;
$_GET = $existingGetVars;
$_POST = $existingPostVars;
$_SESSION = $existingSessionVars;
return $result;
}