From 004bc5b6e761a039e498e1ec25c6a2f35269c0f0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 30 Apr 2012 20:36:03 -0400 Subject: [PATCH] Fix overwriting of GET/POST ControllerTestCase was overwriting GET and POST and not restoring them at the end of testAction. Fixes #2841 --- .../Case/TestSuite/ControllerTestCaseTest.php | 19 +++++++++++++++++++ lib/Cake/TestSuite/ControllerTestCase.php | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php index af124be1d..cf6bbb85a 100644 --- a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php @@ -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); + } + } diff --git a/lib/Cake/TestSuite/ControllerTestCase.php b/lib/Cake/TestSuite/ControllerTestCase.php index c017942d3..ad279785f 100644 --- a/lib/Cake/TestSuite/ControllerTestCase.php +++ b/lib/Cake/TestSuite/ControllerTestCase.php @@ -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']}; }