Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rewrite of FilePostRedirectGet plugin to use consistent return values…

… to match PostRedirectGet plugin
  • Loading branch information...
commit 35cec8bdaa3623febe6a9d5169f15732e83b8893 1 parent 2849b99
@cgmartin authored
View
4 library/Zend/Form/Form.php
@@ -402,6 +402,10 @@ public function hasValidated()
*/
public function isValid()
{
+ if ($this->hasValidated) {
+ return $this->isValid;
+ }
+
$this->isValid = false;
if (!is_array($this->data) && !is_object($this->object)) {
View
22 library/Zend/Mvc/Controller/Plugin/FilePostRedirectGet.php
@@ -35,26 +35,19 @@ public function __invoke($form, $redirect = null, $redirectToUrl = false)
$request = $controller->getRequest();
$container = $this->getSessionContainer();
- $returnObj = new \stdClass(); // TODO: Create a value object class / interface?
- $returnObj->post = null;
- $returnObj->isValid = null;
- $returnObj->response = null;
-
if ($request->isPost()) {
$post = array_merge(
$request->getPost()->toArray(),
$request->getFiles()->toArray()
);
- $returnObj->post = $container->post = $post;
- $form->setData($post);
+ $container->post = $post;
- $returnObj->isValid = $isValid = $form->isValid();
- if (!$isValid) {
+ $form->setData($post);
+ if (!$form->isValid()) {
$container->errors = $form->getMessages();
}
- $returnObj->response = $this->redirect($redirect, $redirectToUrl);
- return $returnObj;
+ return $this->redirect($redirect, $redirectToUrl);
} else {
if (null !== $container->post) {
$post = $container->post;
@@ -63,14 +56,11 @@ public function __invoke($form, $redirect = null, $redirectToUrl = false)
unset($container->errors);
$form->setData($post);
-
- $returnObj->isValid = $isValid = (null === $errors);
- if (!$isValid) {
+ if (null !== $errors) {
$form->setMessages($errors);
}
- $returnObj->post = $post;
- return $returnObj;
+ return $post;
}
return false;
View
38 tests/ZendTest/Mvc/Controller/Plugin/FilePostRedirectGetTest.php
@@ -88,9 +88,8 @@ public function testRedirectsToUrlOnPost()
'postval1' => 'value'
)));
- $result = $this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);
- $prgResultUrl = $prgResult->response;
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultUrl = $this->controller->fileprg($this->form, '/test/getPage', true);
$this->assertInstanceOf('Zend\Http\Response', $prgResultUrl);
$this->assertTrue($prgResultUrl->getHeaders()->has('Location'));
@@ -105,9 +104,8 @@ public function testRedirectsToRouteOnPost()
'postval1' => 'value1'
)));
- $result = $this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form, 'home');
- $prgResultRoute = $prgResult->response;
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultRoute = $this->controller->fileprg($this->form, 'home');
$this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
$this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
@@ -128,7 +126,7 @@ public function testThrowsExceptionOnRouteWithoutRouter()
'postval1' => 'value'
)));
- $result = $this->controller->dispatch($this->request, $this->response);
+ $this->controller->dispatch($this->request, $this->response);
$this->controller->fileprg($this->form, 'some/route');
}
@@ -141,9 +139,8 @@ public function testNullRouteUsesMatchedRouteName()
'postval1' => 'value1'
)));
- $result = $this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form);
- $prgResultRoute = $prgResult->response;
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultRoute = $this->controller->fileprg($this->form);
$this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
$this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
@@ -161,8 +158,7 @@ public function testReuseMatchedParameters()
)));
$this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form);
- $prgResultRoute = $prgResult->response;
+ $prgResultRoute = $this->controller->fileprg($this->form);
$this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
$this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
@@ -184,8 +180,7 @@ public function testReturnsPostOnRedirectGet()
));
$this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);
- $prgResultUrl = $prgResult->response;
+ $prgResultUrl = $this->controller->fileprg($this->form, '/test/getPage', true);
$this->assertInstanceOf('Zend\Http\Response', $prgResultUrl);
$this->assertTrue($prgResultUrl->getHeaders()->has('Location'));
@@ -195,11 +190,9 @@ public function testReturnsPostOnRedirectGet()
// Do GET
$this->request = new Request();
$this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);
+ $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);
- $this->assertNotEmpty($prgResult);
- $this->assertNull($prgResult->response);
- $this->assertEquals($params, $prgResult->post);
+ $this->assertEquals($params, $prgResult);
$this->assertEquals($params['postval1'], $this->form->get('postval1')->getValue());
}
@@ -221,9 +214,7 @@ public function testAppliesFormErrorsOnPostRedirectGet()
$this->form->setInputFilter($inputFilter);
$this->controller->dispatch($this->request, $this->response);
- $prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);
- $prgResultUrl = $prgResult->response;
-
+ $prgResultUrl = $this->controller->fileprg($this->form, '/test/getPage', true);
$this->assertInstanceOf('Zend\Http\Response', $prgResultUrl);
$this->assertTrue($prgResultUrl->getHeaders()->has('Location'));
$this->assertEquals('/test/getPage', $prgResultUrl->getHeaders()->get('Location')->getUri());
@@ -235,10 +226,7 @@ public function testAppliesFormErrorsOnPostRedirectGet()
$prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);
$messages = $this->form->getMessages();
- $this->assertNotEmpty($prgResult);
- $this->assertNull($prgResult->response);
- $this->assertEquals($params, $prgResult->post);
- $this->assertFalse($prgResult->isValid);
+ $this->assertEquals($params, $prgResult);
$this->assertNotEmpty($messages['postval1']['isEmpty']);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.