diff --git a/library/Zend/Mvc/Controller/Plugin/FilePostRedirectGet.php b/library/Zend/Mvc/Controller/Plugin/FilePostRedirectGet.php index 4fa5d2cf3bd..73df1fe6cad 100644 --- a/library/Zend/Mvc/Controller/Plugin/FilePostRedirectGet.php +++ b/library/Zend/Mvc/Controller/Plugin/FilePostRedirectGet.php @@ -46,6 +46,7 @@ public function __invoke($form, $redirect = null, $redirectToUrl = false) if (!$form->isValid()) { $container->errors = $form->getMessages(); } + $container->setExpirationHops(1, array('post', 'errors')); return $this->redirect($redirect, $redirectToUrl); } else { @@ -67,11 +68,10 @@ public function __invoke($form, $redirect = null, $redirectToUrl = false) } } - protected function getSessionContainer() + public function getSessionContainer() { if (!isset($this->sessionContainer)) { $this->sessionContainer = new Container('file_prg_post1'); - $this->sessionContainer->setExpirationHops(1, array('post', 'errors')); } return $this->sessionContainer; } diff --git a/library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php b/library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php index 0428352a2f8..6dc528750d0 100644 --- a/library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php +++ b/library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php @@ -36,6 +36,7 @@ public function __invoke($redirect = null, $redirectToUrl = false) if ($request->isPost()) { $container->post = $request->getPost()->toArray(); + $container->setExpirationHops(1, 'post'); return $this->redirect($redirect, $redirectToUrl); } else { if ($container->post !== null) { @@ -48,11 +49,10 @@ public function __invoke($redirect = null, $redirectToUrl = false) } } - protected function getSessionContainer() + public function getSessionContainer() { if (!isset($this->sessionContainer)) { $this->sessionContainer = new Container('prg_post1'); - $this->sessionContainer->setExpirationHops(1, 'post'); } return $this->sessionContainer; } diff --git a/tests/ZendTest/Mvc/Controller/Plugin/FilePostRedirectGetTest.php b/tests/ZendTest/Mvc/Controller/Plugin/FilePostRedirectGetTest.php index bc84cad82ce..e83afb31546 100644 --- a/tests/ZendTest/Mvc/Controller/Plugin/FilePostRedirectGetTest.php +++ b/tests/ZendTest/Mvc/Controller/Plugin/FilePostRedirectGetTest.php @@ -194,6 +194,13 @@ public function testReturnsPostOnRedirectGet() $this->assertEquals($params, $prgResult); $this->assertEquals($params['postval1'], $this->form->get('postval1')->getValue()); + + // Do GET again to make sure data is empty + $this->request = new Request(); + $this->controller->dispatch($this->request, $this->response); + $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true); + + $this->assertFalse($prgResult); } public function testAppliesFormErrorsOnPostRedirectGet() diff --git a/tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php b/tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php index d84a9c8ed38..70bb120d9ca 100644 --- a/tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php +++ b/tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php @@ -108,6 +108,37 @@ public function testRedirectsToRouteOnPost() $this->assertEquals(303, $prgResultRoute->getStatusCode()); } + public function testReturnsPostOnRedirectGet() + { + $params = array( + 'postval1' => 'value1' + ); + $this->request->setMethod('POST'); + $this->request->setPost(new Parameters($params)); + + $result = $this->controller->dispatch($this->request, $this->response); + $prgResultRoute = $this->controller->prg('home'); + + $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute); + $this->assertTrue($prgResultRoute->getHeaders()->has('Location')); + $this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri()); + $this->assertEquals(303, $prgResultRoute->getStatusCode()); + + // Do GET + $this->request = new Request(); + $this->controller->dispatch($this->request, $this->response); + $prgResult = $this->controller->prg('home'); + + $this->assertEquals($params, $prgResult); + + // Do GET again to make sure data is empty + $this->request = new Request(); + $this->controller->dispatch($this->request, $this->response); + $prgResult = $this->controller->prg('home'); + + $this->assertFalse($prgResult); + } + /** * @expectedException Zend\Mvc\Exception\RuntimeException */