From a58d4bc590a02e61277463eee9b46ed68cb5e556 Mon Sep 17 00:00:00 2001 From: Derek Illchuk Date: Mon, 14 Mar 2016 05:53:44 -0500 Subject: [PATCH] Resolves https://github.com/ZF-Commons/ZfcUser/issues/629 On login form failure, 'redirect' parameter is lost. --- src/ZfcUser/Controller/UserController.php | 8 ++++---- tests/ZfcUserTest/Controller/UserControllerTest.php | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index e9bbd143..aae467e2 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -94,10 +94,10 @@ public function loginAction() $request = $this->getRequest(); $form = $this->getLoginForm(); - if ($this->getOptions()->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) { - $redirect = $request->getQuery()->get('redirect'); - } else { - $redirect = false; + $redirect = false; + if ($this->getOptions()->getUseRedirectParameterIfPresent()) { + $redirect = $request->isPost() ? $request->getPost()->get('redirect') + : $request->getQuery()->get('redirect'); } if (!$request->isPost()) { diff --git a/tests/ZfcUserTest/Controller/UserControllerTest.php b/tests/ZfcUserTest/Controller/UserControllerTest.php index c08759f1..e12e3bc3 100644 --- a/tests/ZfcUserTest/Controller/UserControllerTest.php +++ b/tests/ZfcUserTest/Controller/UserControllerTest.php @@ -176,7 +176,7 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) ->method('addMessage') ->will($this->returnSelf()); - $postArray = array('some', 'data'); + $postArray = new Parameters(array('some', 'data')); $request = $this->getMock('Zend\Http\Request'); $request->expects($this->any()) ->method('isPost') @@ -264,7 +264,7 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $url->expects($this->once()) ->method('fromRoute') ->with($controller::ROUTE_LOGIN) - ->will($this->returnValue($route_url)); + ->will($this->returnValue($route_url . $redirectQuery)); $this->pluginManagerPlugins['url']= $url; $TEST = true; @@ -301,8 +301,9 @@ public function testLoginActionIsNotPost($redirect) $this->pluginManagerPlugins['flashMessenger']= $flashMessenger; + $isPostTimes = $redirect ? 2 : 1; $request = $this->getMock('Zend\Http\Request'); - $request->expects($this->once()) + $request->expects($this->exactly($isPostTimes)) ->method('isPost') ->will($this->returnValue(false));