Skip to content

Commit

Permalink
Fix overwriting of GET/POST
Browse files Browse the repository at this point in the history
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 004bc5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
Expand Up @@ -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);
}

}
6 changes: 6 additions & 0 deletions lib/Cake/TestSuite/ControllerTestCase.php
Expand Up @@ -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') {
Expand Down Expand Up @@ -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']};
}

Expand Down

0 comments on commit 004bc5b

Please sign in to comment.