mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
7fd19551db
commit
004bc5b6e7
2 changed files with 25 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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']};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue