Ver Fonte

ZF-4511: clear query and post params when resetting request

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18180 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew há 16 anos atrás
pai
commit
6bdcf5431e

+ 4 - 0
library/Zend/Test/PHPUnit/ControllerTestCase.php

@@ -243,6 +243,10 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
      */
     public function resetRequest()
     {
+        if ($this->_request instanceof Zend_Controller_Request_HttpTestCase) {
+            $this->_request->clearQuery()
+                           ->clearPost();
+        }
         $this->_request = null;
         return $this;
     }

+ 18 - 0
tests/Zend/Test/PHPUnit/ControllerTestCaseTest.php

@@ -718,6 +718,24 @@ class Zend_Test_PHPUnit_ControllerTestCaseTest extends PHPUnit_Framework_TestCas
         $this->assertNull($request->getPost('foo'), 'Retrieved foo post parameter: ' . var_export($request->getPost(), 1));
         $this->assertNull($request->getCookie('bar'), 'Retrieved bar cookie parameter: ' . var_export($request->getCookie(), 1));
     }
+
+    /**
+     * @group ZF-4511
+     */
+    public function testResetRequestShouldClearPostAndQueryParameters()
+    {
+        $this->testCase->getFrontController()->setControllerDirectory(dirname(__FILE__) . '/_files/application/controllers');
+        $this->testCase->getRequest()->setPost(array(
+            'foo' => 'bar',
+        ));
+        $this->testCase->getRequest()->setQuery(array(
+            'bar' => 'baz',
+        ));
+        $this->testCase->dispatch('/zend-test-php-unit-foo/baz');
+        $this->testCase->resetRequest();
+        $this->assertTrue(empty($_POST));
+        $this->assertTrue(empty($_GET));
+    }
 }
 
 // Concrete test case class for testing purposes