mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR: test support for superglobals in testrequest
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@94710 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
999995b83a
commit
aee97d78c3
@ -122,5 +122,50 @@ class DirectorTest extends SapphireTest {
|
||||
$this->assertFalse(Director::is_site_url("http://test.com/?url=$siteUrl"));
|
||||
}
|
||||
|
||||
public function testResetGlobalsAfterTestRequest() {
|
||||
|
||||
$_GET = array('somekey' => 'getvalue');
|
||||
$_POST = array('somekey' => 'postvalue');
|
||||
$_COOKIE = array('somekey' => 'cookievalue');
|
||||
|
||||
$getresponse = Director::test('errorpage');
|
||||
|
||||
$this->assertEquals('getvalue', $_GET['somekey'], '$_GET reset to original value after Director::test()');
|
||||
$this->assertEquals('postvalue', $_POST['somekey'], '$_POST reset to original value after Director::test()');
|
||||
$this->assertEquals('cookievalue', $_COOKIE['somekey'], '$_COOKIE reset to original value after Director::test()');
|
||||
}
|
||||
|
||||
public function testTestRequestCarriesGlobals() {
|
||||
|
||||
$fixture = array('somekey' => 'sometestvalue');
|
||||
|
||||
foreach(array('get', 'post') as $method) {
|
||||
|
||||
foreach(array('return%sValue', 'returnRequestValue', 'returnCookieValue') as $testfunction) {
|
||||
|
||||
$url = 'DirectorTestRequest_Controller/' . sprintf($testfunction, ucfirst($method)) . '?' . http_build_query($fixture);
|
||||
$getresponse = Director::test($url, $fixture, null, strtoupper($method), null, null, $fixture);
|
||||
|
||||
$this->assertType('SS_HTTPResponse', $getresponse, 'Director::test() returns SS_HTTPResponse');
|
||||
$this->assertEquals($fixture['somekey'], $getresponse->getBody(), 'Director::test() ' . $function);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DirectorTestRequest_Controller extends Controller implements TestOnly {
|
||||
|
||||
public function returnGetValue($request) { return $_GET['somekey']; }
|
||||
|
||||
public function returnPostValue($request) { return $_POST['somekey']; }
|
||||
|
||||
public function returnRequestValue($request) { return $_REQUEST['somekey']; }
|
||||
|
||||
public function returnCookieValue($request) { return $_COOKIE['somekey']; }
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user