Fix overwriting of GET/POST

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

Fixes #2841
This commit is contained in:
mark_story 2012-04-30 20:36:03 -04:00
parent 7fd19551db
commit 004bc5b6e7
2 changed files with 25 additions and 0 deletions

View file

@ -542,4 +542,23 @@ class ControllerTestCaseTest extends CakeTestCase {
$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);
}
}

View file

@ -217,6 +217,8 @@ abstract class ControllerTestCase extends CakeTestCase {
'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 @@ abstract class ControllerTestCase extends CakeTestCase {
}
$this->__dirtyController = true;
$this->headers = $Dispatch->response->header();
$_GET = $restore['get'];
$_POST = $restore['post'];
return $this->{$options['return']};
}