Skip to content
Permalink
Browse files

Fix overwriting of GET/POST

ControllerTestCase was overwriting GET and POST and not
restoring them at the end of testAction.

Fixes #2841
  • Loading branch information...
markstory committed May 1, 2012
1 parent 7fd1955 commit 004bc5b6e761a039e498e1ec25c6a2f35269c0f0
@@ -542,4 +542,23 @@ public function testComponentsSameRequestAndResponse() {
$this->assertSame($this->Case->controller->request, $this->Case->controller->RequestHandler->request);
}
/**
* Test that testAction() doesn't destroy data in GET & POST
*
* @return void
*/
public function testRestoreGetPost() {
$restored = array('new' => 'value');
$_GET = $restored;
$_POST = $restored;
$this->Case->generate('TestsApps');
$options = array('method' => 'get');
$this->Case->testAction('/tests_apps/index', $options);
$this->assertEquals($restored, $_GET);
$this->assertEquals($restored, $_POST);
}
}
@@ -217,6 +217,8 @@ protected function _testAction($url = '', $options = array()) {
'return' => 'result'
), $options);
$restore = array('get' => $_GET, 'post' => $_POST);
$_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
if (is_array($options['data'])) {
if (strtoupper($options['method']) == 'GET') {
@@ -272,6 +274,10 @@ protected function _testAction($url = '', $options = array()) {
}
$this->__dirtyController = true;
$this->headers = $Dispatch->response->header();
$_GET = $restore['get'];
$_POST = $restore['post'];
return $this->{$options['return']};
}

0 comments on commit 004bc5b

Please sign in to comment.
You can’t perform that action at this time.