From 418ac43c5ad2c5ef52753a141d30bec6a0f4f5af Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Wed, 2 Jul 2014 13:16:18 +0200 Subject: [PATCH 01/15] New redirect strategy --- config/module.config.php | 7 +- src/ZfcUser/Controller/RedirectCallback.php | 94 +++++++++++++++++++ src/ZfcUser/Controller/UserController.php | 22 +++-- .../Controller/RedirectCallbackFactory.php | 21 +++++ .../Controller/UserControllerFactory.php | 25 +++++ 5 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 src/ZfcUser/Controller/RedirectCallback.php create mode 100644 src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php create mode 100644 src/ZfcUser/Factory/Controller/UserControllerFactory.php diff --git a/config/module.config.php b/config/module.config.php index fbdc30f9..6b392a26 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -16,14 +16,17 @@ ), ), 'controllers' => array( - 'invokables' => array( - 'zfcuser' => 'ZfcUser\Controller\UserController', + 'factories' => array( + 'zfcuser' => 'ZfcUser\Factory\Controller\UserControllerFactory', ), ), 'service_manager' => array( 'aliases' => array( 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', ), + 'factories' => array( + 'zfcuser_redirect_callback' => 'ZfcUser\Factory\Controller\RedirectCallbackFactory' + ) ), 'router' => array( 'routes' => array( diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php new file mode 100644 index 00000000..d8246cb5 --- /dev/null +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -0,0 +1,94 @@ +router = $router; + $this->request = $request; + $this->response = $response; + $this->options = $options; + } + + /** + * @return Response + */ + public function __invoke() + { + $routeMatch = $this->router->match($this->request); + $response = $this->response; + $response->getHeaders()->addHeaderLine('Location', $this->getRedirect($routeMatch->getMatchedRouteName(), $routeMatch->getParam('redirect', false))); + $response->setStatusCode(302); + return $response; + } + + /** + * @param $route + * @return bool + */ + protected function routeExists($route) + { + try{ + $this->router->assemble($route); + } catch (Exception\RuntimeException $e) { + return false; + } + return true; + } + + /** + * Returns the url to redirect to based on current route. + * If $redirect is set and the option to use redirect is set to true, it will return the $redirect url. + * + * @param string $currentRoute + * @param bool $redirect + * @return mixed + */ + protected function getRedirect($currentRoute, $redirect = false) + { + if (!$this->options->getUseRedirectParameterIfPresent() || ($redirect && !$this->routeExists($redirect))) { + $redirect = false; + } + + switch ($currentRoute) { + case 'zfcuser/login': + $route = ($redirect) ?: $this->options->getLoginRedirectRoute(); + return $this->router->assemble([], ['name' => $route]); + break; + case 'zfcuser/logout': + $route = ($redirect) ?: $this->options->getLogoutRedirectRoute(); + return $this->router->assemble([], ['name' => $route]); + break; + default: + return $this->router->assemble([], ['name' => 'zfcuser']); + } + } + +} diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index 43d81134..26c88485 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -55,6 +55,16 @@ class UserController extends AbstractActionController */ protected $options; + /** + * @var Callable $redirectCallback + */ + protected $redirectCallback; + + public function __construct($redirectCallback) + { + $this->redirectCallback = $redirectCallback; + } + /** * User page */ @@ -116,13 +126,8 @@ public function logoutAction() $this->zfcUserAuthentication()->getAuthAdapter()->logoutAdapters(); $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); - $redirect = $this->params()->fromPost('redirect', $this->params()->fromQuery('redirect', false)); - - if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) { - return $this->redirect()->toRoute($redirect); - } - - return $this->redirect()->toRoute($this->getOptions()->getLogoutRedirectRoute()); + $redirect = $this->redirectCallback; + return $redirect(); } /** @@ -165,7 +170,8 @@ public function authenticateAction() $route = $route($this->zfcUserAuthentication()->getIdentity()); } - return $this->redirect()->toRoute($route); + $redirect = $this->redirectCallback; + return $redirect(); } /** diff --git a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php new file mode 100644 index 00000000..96425dcd --- /dev/null +++ b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php @@ -0,0 +1,21 @@ +get('Router'); + $response = $serviceLocator->get('Response'); + $request = $serviceLocator->get('Request'); + $options = $serviceLocator->get('zfcuser_module_options'); + return new RedirectCallback($router, $response, $request, $options); + } +} diff --git a/src/ZfcUser/Factory/Controller/UserControllerFactory.php b/src/ZfcUser/Factory/Controller/UserControllerFactory.php new file mode 100644 index 00000000..5486b903 --- /dev/null +++ b/src/ZfcUser/Factory/Controller/UserControllerFactory.php @@ -0,0 +1,25 @@ +getServiceLocator(); + + $redirectCallback = $serviceManager->get('zfcuser_redirect_callback'); + $controller = new UserController($redirectCallback); + + return $controller; + } +} From a720f3775ef3cbc391b3eeb707ff66f37132b877 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Wed, 2 Jul 2014 21:39:32 +0200 Subject: [PATCH 02/15] Cleanup + fix existing tests --- src/ZfcUser/Controller/RedirectCallback.php | 45 +++++++++--- src/ZfcUser/Controller/UserController.php | 5 +- .../Controller/RedirectCallbackFactory.php | 7 +- .../Controller/UserControllerTest.php | 71 ++++--------------- 4 files changed, 57 insertions(+), 71 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index d8246cb5..850c62ef 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -2,8 +2,8 @@ namespace ZfcUser\Controller; -use Zend\Mvc\Controller\Plugin\Redirect; use Zend\Mvc\Router\RouteInterface; +use Zend\Mvc\Router\RouteMatch; use Zend\Mvc\Router\Exception; use Zend\Http\PhpEnvironment\Request; use Zend\Http\PhpEnvironment\Response; @@ -11,7 +11,10 @@ class RedirectCallback { - /** @var RouteInterface */ + /** @var RouteMatch */ + protected $routeMatch; + + /** @var RouteInterface */ protected $router; /** @var Response */ @@ -24,13 +27,14 @@ class RedirectCallback protected $options; /** - * @param RouteInterface $router + * @param RouteMatch $router * @param Response $response * @param Request $request * @param ModuleOptions $options */ - public function __construct(RouteInterface $router, Response $response, Request $request, ModuleOptions $options) + public function __construct(RouteMatch $routeMatch, RouteInterface $router, Response $response, Request $request, ModuleOptions $options) { + $this->routeMatch = $routeMatch; $this->router = $router; $this->request = $request; $this->response = $response; @@ -43,19 +47,43 @@ public function __construct(RouteInterface $router, Response $response, Request public function __invoke() { $routeMatch = $this->router->match($this->request); + + $redirect = $this->getRedirect($routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); + $response = $this->response; - $response->getHeaders()->addHeaderLine('Location', $this->getRedirect($routeMatch->getMatchedRouteName(), $routeMatch->getParam('redirect', false))); + $response->getHeaders()->addHeaderLine('Location', $redirect); $response->setStatusCode(302); return $response; } + /** + * Return the redirect from param. + * First checks GET then POST + * @return string + */ + protected function getRedirectRouteFromRequest() + { + $request = $this->request; + $redirect = $request->getQuery('redirect'); + if ($redirect && $this->routeExists($redirect)) { + return $redirect; + } + + $redirect = $request->getPost('redirect'); + if ($redirect && $this->routeExists($redirect)) { + return $redirect; + } + + return false; + } + /** * @param $route * @return bool */ protected function routeExists($route) { - try{ + try { $this->router->assemble($route); } catch (Exception\RuntimeException $e) { return false; @@ -73,7 +101,9 @@ protected function routeExists($route) */ protected function getRedirect($currentRoute, $redirect = false) { - if (!$this->options->getUseRedirectParameterIfPresent() || ($redirect && !$this->routeExists($redirect))) { + $useRedirect = $this->options->getUseRedirectParameterIfPresent(); + $routeExists = ($redirect && $this->routeExists($redirect)); + if (!$useRedirect || !$routeExists) { $redirect = false; } @@ -90,5 +120,4 @@ protected function getRedirect($currentRoute, $redirect = false) return $this->router->assemble([], ['name' => 'zfcuser']); } } - } diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index 26c88485..1bc95428 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -160,14 +160,11 @@ public function authenticateAction() ); } - if ($this->getOptions()->getUseRedirectParameterIfPresent() && $redirect) { - return $this->redirect()->toRoute($redirect); - } - $route = $this->getOptions()->getLoginRedirectRoute(); if (is_callable($route)) { $route = $route($this->zfcUserAuthentication()->getIdentity()); + return $this->redirect()->toRoute($route); } $redirect = $this->redirectCallback; diff --git a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php index 96425dcd..8cf0f86d 100644 --- a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php +++ b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php @@ -16,6 +16,11 @@ public function createService(ServiceLocatorInterface $serviceLocator) $response = $serviceLocator->get('Response'); $request = $serviceLocator->get('Request'); $options = $serviceLocator->get('zfcuser_module_options'); - return new RedirectCallback($router, $response, $request, $options); + + /** @var MvcEvent $mvcEvent */ + $mvcEvent = $serviceLocator->get('Application')->getMvcEvent(); + $routeMatch = $mvcEvent->getRouteMatch(); + + return new RedirectCallback($routeMatch, $router, $response, $request, $options); } } diff --git a/tests/ZfcUserTest/Controller/UserControllerTest.php b/tests/ZfcUserTest/Controller/UserControllerTest.php index f581c6d6..dd97ae12 100644 --- a/tests/ZfcUserTest/Controller/UserControllerTest.php +++ b/tests/ZfcUserTest/Controller/UserControllerTest.php @@ -26,9 +26,15 @@ class UserControllerTest extends \PHPUnit_Framework_TestCase protected $options; + protected $redirectCallback; + public function setUp() { - $controller = new Controller; + $this->redirectCallback = $this->getMockBuilder('ZfcUser\Controller\RedirectCallback') + ->disableOriginalConstructor() + ->getMock(); + + $controller = new Controller($this->redirectCallback); $this->controller = $controller; $this->zfcUserAuthenticationPlugin = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication'); @@ -362,50 +368,11 @@ public function testLogoutAction($withRedirect, $post, $query) )); - $params = $this->getMock('Zend\Mvc\Controller\Plugin\Params'); - $params->expects($this->any()) - ->method('__invoke') - ->will($this->returnSelf()); - $params->expects($this->once()) - ->method('fromPost') - ->will($this->returnCallback(function ($key, $default) use ($post) { - return $post ?: $default; - })); - $params->expects($this->once()) - ->method('fromQuery') - ->will($this->returnCallback(function ($key, $default) use ($query) { - return $query ?: $default; - })); - $this->pluginManagerPlugins['params'] = $params; - $response = new Response(); - $redirect = $this->getMock('Zend\Mvc\Controller\Plugin\Redirect'); - $redirect->expects($this->any()) - ->method('toRoute') - ->will($this->returnValue($response)); - - if ($withRedirect) { - $expectedLocation = $post ?: $query ?: false; - $this->options->expects($this->once()) - ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $withRedirect)); - $redirect->expects($this->any()) - ->method('toRoute') - ->with($expectedLocation) - ->will($this->returnValue($response)); - } else { - $expectedLocation = "/user/logout"; - $this->options->expects($this->once()) - ->method('getLogoutRedirectRoute') - ->will($this->returnValue($expectedLocation)); - $redirect->expects($this->any()) - ->method('toRoute') - ->with($expectedLocation) - ->will($this->returnValue($response)); - } - - $this->pluginManagerPlugins['redirect']= $redirect; + $this->redirectCallback->expects($this->once()) + ->method('__invoke') + ->will($this->returnValue($response)); $result = $controller->logoutAction(); @@ -513,21 +480,9 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes ->will($this->returnValue('user/login')); $this->pluginManagerPlugins['url'] = $url; - } elseif ($wantRedirect && $hasRedirect) { - $redirect->expects($this->once()) - ->method('toRoute') - ->with(($post ?: $query ?: false)) - ->will($this->returnValue($response)); } else { - - $redirect->expects($this->once()) - ->method('toRoute') - ->with('zfcuser') - ->will($this->returnValue($response)); - - $this->options->expects($this->once()) - ->method('getLoginRedirectRoute') - ->will($this->returnValue('zfcuser')); + $this->redirectCallback->expects($this->once()) + ->method('__invoke'); } $this->options->expects($this->any()) @@ -1010,7 +965,7 @@ public function testSetterGetterServices( $serviceName, $callback = null ) { - $controller = new Controller; + $controller = new Controller($this->redirectCallback); $controller->setPluginManager($this->pluginManager); From 5d54a4b7599db67b7d9254028def4dbefac76a21 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Wed, 2 Jul 2014 21:42:16 +0200 Subject: [PATCH 03/15] Cleanup --- src/ZfcUser/Controller/RedirectCallback.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 850c62ef..bdfc4cee 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -27,7 +27,8 @@ class RedirectCallback protected $options; /** - * @param RouteMatch $router + * @param RouteMatch $routeMatch + * @param RouteInterface $router * @param Response $response * @param Request $request * @param ModuleOptions $options @@ -46,9 +47,7 @@ public function __construct(RouteMatch $routeMatch, RouteInterface $router, Resp */ public function __invoke() { - $routeMatch = $this->router->match($this->request); - - $redirect = $this->getRedirect($routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); + $redirect = $this->getRedirect($this->routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); $response = $this->response; $response->getHeaders()->addHeaderLine('Location', $redirect); From 2becf294d13af24ba3896a5c70e14dfe0d72118e Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Wed, 2 Jul 2014 22:03:12 +0200 Subject: [PATCH 04/15] Add current tests fix. Fix callable case --- src/ZfcUser/Controller/UserController.php | 6 +++++- tests/ZfcUserTest/Controller/RedirectCallbackTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/ZfcUserTest/Controller/RedirectCallbackTest.php diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index 1bc95428..efcf4fb5 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -56,10 +56,14 @@ class UserController extends AbstractActionController protected $options; /** - * @var Callable $redirectCallback + * @var callable $redirectCallback */ protected $redirectCallback; + + /** + * @param callable $redirectCallback + */ public function __construct($redirectCallback) { $this->redirectCallback = $redirectCallback; diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php new file mode 100644 index 00000000..f744419e --- /dev/null +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -0,0 +1,8 @@ + Date: Wed, 2 Jul 2014 22:59:49 +0200 Subject: [PATCH 05/15] Use Application instead of response/routeMatch/request --- src/ZfcUser/Controller/RedirectCallback.php | 13 ++++++------- .../Factory/Controller/RedirectCallbackFactory.php | 9 ++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index bdfc4cee..7f4580aa 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -2,6 +2,7 @@ namespace ZfcUser\Controller; +use Zend\Mvc\Application; use Zend\Mvc\Router\RouteInterface; use Zend\Mvc\Router\RouteMatch; use Zend\Mvc\Router\Exception; @@ -27,18 +28,16 @@ class RedirectCallback protected $options; /** - * @param RouteMatch $routeMatch + * @param Application $application * @param RouteInterface $router - * @param Response $response - * @param Request $request * @param ModuleOptions $options */ - public function __construct(RouteMatch $routeMatch, RouteInterface $router, Response $response, Request $request, ModuleOptions $options) + public function __construct(Application $application, RouteInterface $router, ModuleOptions $options) { - $this->routeMatch = $routeMatch; + $this->routeMatch = $application->getMvcEvent()->getRouteMatch(); $this->router = $router; - $this->request = $request; - $this->response = $response; + $this->request = $application->getRequest(); + $this->response = $application->getResponse(); $this->options = $options; } diff --git a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php index 8cf0f86d..ca369db6 100644 --- a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php +++ b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php @@ -13,14 +13,9 @@ class RedirectCallbackFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $router = $serviceLocator->get('Router'); - $response = $serviceLocator->get('Response'); - $request = $serviceLocator->get('Request'); + $application = $serviceLocator->get('Application'); $options = $serviceLocator->get('zfcuser_module_options'); - /** @var MvcEvent $mvcEvent */ - $mvcEvent = $serviceLocator->get('Application')->getMvcEvent(); - $routeMatch = $mvcEvent->getRouteMatch(); - - return new RedirectCallback($routeMatch, $router, $response, $request, $options); + return new RedirectCallback($application, $router, $options); } } From 2115f582ec7812184d4924104e96e0dda2a28ade Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 13:55:28 +0200 Subject: [PATCH 06/15] Add tests --- src/ZfcUser/Controller/RedirectCallback.php | 2 +- .../Controller/RedirectCallbackTest.php | 316 ++++++++++++++++++ 2 files changed, 317 insertions(+), 1 deletion(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 7f4580aa..af2a70c2 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -82,7 +82,7 @@ protected function getRedirectRouteFromRequest() protected function routeExists($route) { try { - $this->router->assemble($route); + $this->router->assemble([], ['name' => $route]); } catch (Exception\RuntimeException $e) { return false; } diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php index f744419e..2387332c 100644 --- a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -2,7 +2,323 @@ namespace ZfcUserTest\Controller; +use ZfcUser\Controller\RedirectCallback; + class RedirectCallbackTest extends \PHPUnit_Framework_TestCase { + /** @var RedirectCallback */ + protected $redirectCallback; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $moduleOptions; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $router; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $application; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $request; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $response; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $mvcEvent; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $routeMatch; + + public function setUp() + { + $this->router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface') + ->disableOriginalConstructor() + ->getMock(); + + $this->moduleOptions = $this->getMockBuilder('ZfcUser\Options\ModuleOptions') + ->disableOriginalConstructor() + ->getMock(); + + $this->application = $this->getMockBuilder('Zend\Mvc\Application') + ->disableOriginalConstructor() + ->getMock(); + $this->setUpApplication(); + + $this->redirectCallback = new RedirectCallback( + $this->application, + $this->router, + $this->moduleOptions + ); + } + + public function testInvoke() + { + $url = 'someUrl'; + + $this->routeMatch->expects($this->once()) + ->method('getMatchedRouteName') + ->will($this->returnValue('someRoute')); + + $headers = $this->getMock('Zend\Http\Headers'); + $headers->expects($this->once()) + ->method('addHeaderLine') + ->with('Location', $url); + + $this->router->expects($this->any()) + ->method('assemble') + ->with([], ['name' => 'zfcuser']) + ->will($this->returnValue($url)); + + $this->response->expects($this->once()) + ->method('getHeaders') + ->will($this->returnValue($headers)); + + $this->response->expects($this->once()) + ->method('setStatusCode') + ->with(302); + + $result = $this->redirectCallback->__invoke(); + + $this->assertSame($this->response, $result); + } + + /** + * @dataProvider providerGetRedirectRouteFromRequest + */ + public function testGetRedirectRouteFromRequest($get, $post, $getRouteExists, $postRouteExists) + { + $expectedResult = false; + + $this->request->expects($this->once()) + ->method('getQuery') + ->will($this->returnValue($get)); + + if ($get) { + $this->router->expects($this->any()) + ->method('assemble') + ->with([], ['name' => $get]) + ->will($getRouteExists); + + if ($getRouteExists == $this->returnValue(true)) { + $expectedResult = $get; + } + } + + if (!$get || !$getRouteExists) { + $this->request->expects($this->once()) + ->method('getPost') + ->will($this->returnValue($post)); + + if ($post) { + $this->router->expects($this->any()) + ->method('assemble') + ->with([], ['name' => $post]) + ->will($postRouteExists); + + if ($postRouteExists == $this->returnValue(true)) { + $expectedResult = $post; + } + } + } + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirectRouteFromRequest' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback); + + $this->assertSame($expectedResult, $result); + } + + public function providerGetRedirectRouteFromRequest() + { + return array( + array('user', false, $this->returnValue('route'), false), + array('user', false, $this->returnValue('route'), $this->returnValue(true)), + array('user', 'user', $this->returnValue('route'), $this->returnValue(true)), + array('user', 'user', $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException), $this->returnValue(true)), + array('user', 'user', $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException), $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)), + array(false, 'user', false, $this->returnValue(true)), + array(false, 'user', false, $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)), + array(false, 'user', false, $this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)), + ); + } + + public function testRouteExistsRouteExists() + { + $route = 'existingRoute'; + + $this->router->expects($this->once()) + ->method('assemble') + ->with([], ['name' => $route]); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'routeExists' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route); + + $this->assertTrue($result); + } + + public function testRouteExistsRouteDoesntExists() + { + $route = 'existingRoute'; + + $this->router->expects($this->once()) + ->method('assemble') + ->with([], ['name' => $route]) + ->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'routeExists' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route); + + $this->assertFalse($result); + } + + /** + * @dataProvider providerGetRedirectNoRedirectParam + */ + public function testGetRedirectNoRedirectParam($currentRoute, $optionsReturn, $expectedResult, $optionsMethod) + { + $this->moduleOptions->expects($this->once()) + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue(true)); + + $this->router->expects($this->at(0)) + ->method('assemble'); + $this->router->expects($this->at(1)) + ->method('assemble') + ->with([], ['name' => $optionsReturn]) + ->will($this->returnValue($expectedResult)); + + if ($optionsMethod) { + $this->moduleOptions->expects($this->never()) + ->method($optionsMethod) + ->will($this->returnValue($optionsReturn)); + } + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirect' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $currentRoute, $optionsReturn); + + $this->assertSame($expectedResult, $result); + } + + public function providerGetRedirectNoRedirectParam() + { + return array( + array('zfcuser/login', 'zfcuser', '/user', 'getLoginRedirectRoute'), + array('zfcuser/logout', 'zfcuser/login', '/user/login', 'getLogoutRedirectRoute'), + array('testDefault', 'zfcuser', '/home', false), + ); + } + + public function testGetRedirectWithOptionOnButNoRedirect() + { + $route = 'zfcuser/login'; + $redirect = false; + $expectedResult = '/user/login'; + + $this->moduleOptions->expects($this->once()) + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue(true)); + + $this->moduleOptions->expects($this->once()) + ->method('getLoginRedirectRoute') + ->will($this->returnValue($route)); + + $this->router->expects($this->once()) + ->method('assemble') + ->with([], ['name' => $route]) + ->will($this->returnValue($expectedResult)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirect' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route, $redirect); + + $this->assertSame($expectedResult, $result); + } + + public function testGetRedirectWithOptionOnRedirectDoesntExists() + { + $route = 'zfcuser/login'; + $redirect = 'doesntExists'; + $expectedResult = '/user/login'; + + $this->moduleOptions->expects($this->once()) + ->method('getUseRedirectParameterIfPresent') + ->will($this->returnValue(true)); + + $this->router->expects($this->at(0)) + ->method('assemble') + ->with([], ['name' => $redirect]) + ->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)); + + $this->router->expects($this->at(1)) + ->method('assemble') + ->with([], ['name' => $route]) + ->will($this->returnValue($expectedResult)); + + $this->moduleOptions->expects($this->once()) + ->method('getLoginRedirectRoute') + ->will($this->returnValue($route)); + + $method = new \ReflectionMethod( + 'ZfcUser\Controller\RedirectCallback', + 'getRedirect' + ); + $method->setAccessible(true); + $result = $method->invoke($this->redirectCallback, $route, $redirect); + + $this->assertSame($expectedResult, $result); + } + + private function setUpApplication() + { + $this->request = $this->getMockBuilder('Zend\Http\PhpEnvironment\Request') + ->disableOriginalConstructor() + ->getMock(); + + $this->response = $this->getMockBuilder('Zend\Http\PhpEnvironment\Response') + ->disableOriginalConstructor() + ->getMock(); + + + $this->routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch') + ->disableOriginalConstructor() + ->getMock(); + + $this->mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent') + ->disableOriginalConstructor() + ->getMock(); + $this->mvcEvent->expects($this->once()) + ->method('getRouteMatch') + ->will($this->returnValue($this->routeMatch)); + + + $this->application->expects($this->once()) + ->method('getMvcEvent') + ->will($this->returnValue($this->mvcEvent)); + $this->application->expects($this->once()) + ->method('getRequest') + ->will($this->returnValue($this->request)); + $this->application->expects($this->once()) + ->method('getResponse') + ->will($this->returnValue($this->response)); + } + } From d2f12b0c4cd5b5bbf22f5ccbc0983e13cf6b6104 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 14:43:25 +0200 Subject: [PATCH 07/15] refactor --- src/ZfcUser/Controller/RedirectCallback.php | 14 +++++++--- src/ZfcUser/Controller/UserController.php | 6 ++++- .../Controller/RedirectCallbackFactory.php | 8 ++++++ .../Controller/UserControllerFactory.php | 6 ++++- .../Controller/RedirectCallbackTest.php | 26 ++++++++++++------- .../Controller/UserControllerTest.php | 4 +++ 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index af2a70c2..39599d21 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -10,6 +10,10 @@ use Zend\Http\PhpEnvironment\Response; use ZfcUser\Options\ModuleOptions; +/** + * Class RedirectCallback + * @package ZfcUser\Controller + */ class RedirectCallback { /** @var RouteMatch */ @@ -24,6 +28,9 @@ class RedirectCallback /** @var Request */ protected $request; + /** @var Application */ + protected $application; + /** @var ModuleOptions */ protected $options; @@ -36,8 +43,7 @@ public function __construct(Application $application, RouteInterface $router, Mo { $this->routeMatch = $application->getMvcEvent()->getRouteMatch(); $this->router = $router; - $this->request = $application->getRequest(); - $this->response = $application->getResponse(); + $this->application = $application; $this->options = $options; } @@ -48,7 +54,7 @@ public function __invoke() { $redirect = $this->getRedirect($this->routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); - $response = $this->response; + $response = $this->application->getResponse(); $response->getHeaders()->addHeaderLine('Location', $redirect); $response->setStatusCode(302); return $response; @@ -61,7 +67,7 @@ public function __invoke() */ protected function getRedirectRouteFromRequest() { - $request = $this->request; + $request = $this->application->getRequest(); $redirect = $request->getQuery('redirect'); if ($redirect && $this->routeExists($redirect)) { return $redirect; diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index efcf4fb5..80cd4491 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -60,12 +60,14 @@ class UserController extends AbstractActionController */ protected $redirectCallback; - /** * @param callable $redirectCallback */ public function __construct($redirectCallback) { + if (!is_callable($redirectCallback)) { + throw new \InvalidArgumentException('You must supply a callable redirectCallback'); + } $this->redirectCallback = $redirectCallback; } @@ -131,6 +133,7 @@ public function logoutAction() $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); $redirect = $this->redirectCallback; + return $redirect(); } @@ -172,6 +175,7 @@ public function authenticateAction() } $redirect = $this->redirectCallback; + return $redirect(); } diff --git a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php index ca369db6..b26989f1 100644 --- a/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php +++ b/src/ZfcUser/Factory/Controller/RedirectCallbackFactory.php @@ -1,9 +1,12 @@ get('Router'); + + /* @var Application $application */ $application = $serviceLocator->get('Application'); + + /* @var ModuleOptions $options */ $options = $serviceLocator->get('zfcuser_module_options'); return new RedirectCallback($application, $router, $options); diff --git a/src/ZfcUser/Factory/Controller/UserControllerFactory.php b/src/ZfcUser/Factory/Controller/UserControllerFactory.php index 5486b903..57a763f0 100644 --- a/src/ZfcUser/Factory/Controller/UserControllerFactory.php +++ b/src/ZfcUser/Factory/Controller/UserControllerFactory.php @@ -5,6 +5,7 @@ use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use ZfcUser\Authentication\Adapter; +use ZfcUser\Controller\RedirectCallback; use ZfcUser\Controller\UserController; class UserControllerFactory implements FactoryInterface @@ -14,10 +15,13 @@ class UserControllerFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $controllerManager) { - /** @var ControllerManager $controllerManager*/ + /* @var ControllerManager $controllerManager*/ $serviceManager = $controllerManager->getServiceLocator(); + /* @var RedirectCallback $redirectCallback */ $redirectCallback = $serviceManager->get('zfcuser_redirect_callback'); + + /* @var UserController $controller */ $controller = new UserController($redirectCallback); return $controller; diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php index 2387332c..8089e6a9 100644 --- a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -2,7 +2,14 @@ namespace ZfcUserTest\Controller; +use Zend\Http\PhpEnvironment\Request; +use Zend\Http\PhpEnvironment\Response; +use Zend\Mvc\Application; +use Zend\Mvc\MvcEvent; +use Zend\Mvc\Router\RouteInterface; +use Zend\Mvc\Router\RouteMatch; use ZfcUser\Controller\RedirectCallback; +use ZfcUser\Options\ModuleOptions; class RedirectCallbackTest extends \PHPUnit_Framework_TestCase { @@ -10,25 +17,25 @@ class RedirectCallbackTest extends \PHPUnit_Framework_TestCase /** @var RedirectCallback */ protected $redirectCallback; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|ModuleOptions */ protected $moduleOptions; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|RouteInterface */ protected $router; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|Application */ protected $application; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|Request */ protected $request; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|Response */ protected $response; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|MvcEvent */ protected $mvcEvent; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject|RouteMatch */ protected $routeMatch; public function setUp() @@ -297,7 +304,6 @@ private function setUpApplication() ->disableOriginalConstructor() ->getMock(); - $this->routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch') ->disableOriginalConstructor() ->getMock(); @@ -313,10 +319,10 @@ private function setUpApplication() $this->application->expects($this->once()) ->method('getMvcEvent') ->will($this->returnValue($this->mvcEvent)); - $this->application->expects($this->once()) + $this->application->expects($this->any()) ->method('getRequest') ->will($this->returnValue($this->request)); - $this->application->expects($this->once()) + $this->application->expects($this->any()) ->method('getResponse') ->will($this->returnValue($this->response)); } diff --git a/tests/ZfcUserTest/Controller/UserControllerTest.php b/tests/ZfcUserTest/Controller/UserControllerTest.php index dd97ae12..06fabf8e 100644 --- a/tests/ZfcUserTest/Controller/UserControllerTest.php +++ b/tests/ZfcUserTest/Controller/UserControllerTest.php @@ -2,6 +2,7 @@ namespace ZfcUserTest\Controller; +use ZfcUser\Controller\RedirectCallback; use ZfcUser\Controller\UserController as Controller; use Zend\Http\Response; use Zend\Stdlib\Parameters; @@ -26,6 +27,9 @@ class UserControllerTest extends \PHPUnit_Framework_TestCase protected $options; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|RedirectCallback + */ protected $redirectCallback; public function setUp() From 779a577c0a7fc227f14c92467e53bf090ed2e012 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 14:52:21 +0200 Subject: [PATCH 08/15] Change property visibility --- src/ZfcUser/Controller/RedirectCallback.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 39599d21..7b3296a2 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -6,7 +6,6 @@ use Zend\Mvc\Router\RouteInterface; use Zend\Mvc\Router\RouteMatch; use Zend\Mvc\Router\Exception; -use Zend\Http\PhpEnvironment\Request; use Zend\Http\PhpEnvironment\Response; use ZfcUser\Options\ModuleOptions; @@ -17,22 +16,16 @@ class RedirectCallback { /** @var RouteMatch */ - protected $routeMatch; + private $routeMatch; /** @var RouteInterface */ - protected $router; - - /** @var Response */ - protected $response; - - /** @var Request */ - protected $request; + private $router; /** @var Application */ - protected $application; + private $application; /** @var ModuleOptions */ - protected $options; + private $options; /** * @param Application $application From a4ca81529cb8601b8f020c69558bf80f64a6b756 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 15:07:53 +0200 Subject: [PATCH 09/15] Remove routeMatch from class state --- src/ZfcUser/Controller/RedirectCallback.php | 7 ++----- tests/ZfcUserTest/Controller/RedirectCallbackTest.php | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 7b3296a2..19bb6be1 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -11,12 +11,9 @@ /** * Class RedirectCallback - * @package ZfcUser\Controller */ class RedirectCallback { - /** @var RouteMatch */ - private $routeMatch; /** @var RouteInterface */ private $router; @@ -34,7 +31,6 @@ class RedirectCallback */ public function __construct(Application $application, RouteInterface $router, ModuleOptions $options) { - $this->routeMatch = $application->getMvcEvent()->getRouteMatch(); $this->router = $router; $this->application = $application; $this->options = $options; @@ -45,7 +41,8 @@ public function __construct(Application $application, RouteInterface $router, Mo */ public function __invoke() { - $redirect = $this->getRedirect($this->routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); + $routeMatch = $this->application->getMvcEvent()->getRouteMatch(); + $redirect = $this->getRedirect($routeMatch->getMatchedRouteName(), $this->getRedirectRouteFromRequest()); $response = $this->application->getResponse(); $response->getHeaders()->addHeaderLine('Location', $redirect); diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php index 8089e6a9..a41bf049 100644 --- a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -311,12 +311,12 @@ private function setUpApplication() $this->mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent') ->disableOriginalConstructor() ->getMock(); - $this->mvcEvent->expects($this->once()) + $this->mvcEvent->expects($this->any()) ->method('getRouteMatch') ->will($this->returnValue($this->routeMatch)); - $this->application->expects($this->once()) + $this->application->expects($this->any()) ->method('getMvcEvent') ->will($this->returnValue($this->mvcEvent)); $this->application->expects($this->any()) From d3c228ab33ff21522f6d01a0b6a1a9281cded1ee Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 15:10:38 +0200 Subject: [PATCH 10/15] Add class description --- src/ZfcUser/Controller/RedirectCallback.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 19bb6be1..59704dc6 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -10,7 +10,7 @@ use ZfcUser\Options\ModuleOptions; /** - * Class RedirectCallback + * Returns a redirect response based on the current routing and parameters */ class RedirectCallback { From de165fb945ed9890d593267da35ca9914d5c8065 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 15:10:53 +0200 Subject: [PATCH 11/15] Removed unused use statement --- src/ZfcUser/Controller/RedirectCallback.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 59704dc6..a57449d9 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -4,7 +4,6 @@ use Zend\Mvc\Application; use Zend\Mvc\Router\RouteInterface; -use Zend\Mvc\Router\RouteMatch; use Zend\Mvc\Router\Exception; use Zend\Http\PhpEnvironment\Response; use ZfcUser\Options\ModuleOptions; From e5b2977250411cad4cf8ed584be77dd68b6dfe41 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 15:31:42 +0200 Subject: [PATCH 12/15] Fix CS --- tests/ZfcUserTest/Controller/RedirectCallbackTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php index a41bf049..8676a355 100644 --- a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -326,5 +326,4 @@ private function setUpApplication() ->method('getResponse') ->will($this->returnValue($this->response)); } - } From d674ec2607ba02e1589df8b308a8196a02ae677c Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 15:48:38 +0200 Subject: [PATCH 13/15] Convert short array to long array --- .../Controller/RedirectCallbackTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php index 8676a355..236352c1 100644 --- a/tests/ZfcUserTest/Controller/RedirectCallbackTest.php +++ b/tests/ZfcUserTest/Controller/RedirectCallbackTest.php @@ -75,7 +75,7 @@ public function testInvoke() $this->router->expects($this->any()) ->method('assemble') - ->with([], ['name' => 'zfcuser']) + ->with(array(), array('name' => 'zfcuser')) ->will($this->returnValue($url)); $this->response->expects($this->once()) @@ -105,7 +105,7 @@ public function testGetRedirectRouteFromRequest($get, $post, $getRouteExists, $p if ($get) { $this->router->expects($this->any()) ->method('assemble') - ->with([], ['name' => $get]) + ->with(array(), array('name' => $get)) ->will($getRouteExists); if ($getRouteExists == $this->returnValue(true)) { @@ -121,7 +121,7 @@ public function testGetRedirectRouteFromRequest($get, $post, $getRouteExists, $p if ($post) { $this->router->expects($this->any()) ->method('assemble') - ->with([], ['name' => $post]) + ->with(array(), array('name' => $post)) ->will($postRouteExists); if ($postRouteExists == $this->returnValue(true)) { @@ -160,7 +160,7 @@ public function testRouteExistsRouteExists() $this->router->expects($this->once()) ->method('assemble') - ->with([], ['name' => $route]); + ->with(array(), array('name' => $route)); $method = new \ReflectionMethod( 'ZfcUser\Controller\RedirectCallback', @@ -178,7 +178,7 @@ public function testRouteExistsRouteDoesntExists() $this->router->expects($this->once()) ->method('assemble') - ->with([], ['name' => $route]) + ->with(array(), array('name' => $route)) ->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)); $method = new \ReflectionMethod( @@ -204,7 +204,7 @@ public function testGetRedirectNoRedirectParam($currentRoute, $optionsReturn, $e ->method('assemble'); $this->router->expects($this->at(1)) ->method('assemble') - ->with([], ['name' => $optionsReturn]) + ->with(array(), array('name' => $optionsReturn)) ->will($this->returnValue($expectedResult)); if ($optionsMethod) { @@ -247,7 +247,7 @@ public function testGetRedirectWithOptionOnButNoRedirect() $this->router->expects($this->once()) ->method('assemble') - ->with([], ['name' => $route]) + ->with(array(), array('name' => $route)) ->will($this->returnValue($expectedResult)); $method = new \ReflectionMethod( @@ -272,12 +272,12 @@ public function testGetRedirectWithOptionOnRedirectDoesntExists() $this->router->expects($this->at(0)) ->method('assemble') - ->with([], ['name' => $redirect]) + ->with(array(), array('name' => $redirect)) ->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException)); $this->router->expects($this->at(1)) ->method('assemble') - ->with([], ['name' => $route]) + ->with(array(), array('name' => $route)) ->will($this->returnValue($expectedResult)); $this->moduleOptions->expects($this->once()) From 6abfd1a73c7fc6088943922f5904064658782e35 Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 16:09:00 +0200 Subject: [PATCH 14/15] Convert short array to long array --- src/ZfcUser/Controller/RedirectCallback.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index a57449d9..c3ed6d71 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -77,7 +77,7 @@ protected function getRedirectRouteFromRequest() protected function routeExists($route) { try { - $this->router->assemble([], ['name' => $route]); + $this->router->assemble(array(), array('name' => $route)); } catch (Exception\RuntimeException $e) { return false; } @@ -103,14 +103,14 @@ protected function getRedirect($currentRoute, $redirect = false) switch ($currentRoute) { case 'zfcuser/login': $route = ($redirect) ?: $this->options->getLoginRedirectRoute(); - return $this->router->assemble([], ['name' => $route]); + return $this->router->assemble(array(), array('name' => $route)); break; case 'zfcuser/logout': $route = ($redirect) ?: $this->options->getLogoutRedirectRoute(); - return $this->router->assemble([], ['name' => $route]); + return $this->router->assemble(array(), array('name' => $route)); break; default: - return $this->router->assemble([], ['name' => 'zfcuser']); + return $this->router->assemble(array(), array('name' => 'zfcuser')); } } } From cf16a3f90a26ca66b7ad06825d85d81f659abbcc Mon Sep 17 00:00:00 2001 From: Danielss89 Date: Thu, 3 Jul 2014 16:42:52 +0200 Subject: [PATCH 15/15] Change method visiblity --- src/ZfcUser/Controller/RedirectCallback.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index c3ed6d71..cf2dd1e5 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -9,7 +9,7 @@ use ZfcUser\Options\ModuleOptions; /** - * Returns a redirect response based on the current routing and parameters + * Builds a redirect response based on the current routing and parameters */ class RedirectCallback { @@ -54,7 +54,7 @@ public function __invoke() * First checks GET then POST * @return string */ - protected function getRedirectRouteFromRequest() + private function getRedirectRouteFromRequest() { $request = $this->application->getRequest(); $redirect = $request->getQuery('redirect'); @@ -74,7 +74,7 @@ protected function getRedirectRouteFromRequest() * @param $route * @return bool */ - protected function routeExists($route) + private function routeExists($route) { try { $this->router->assemble(array(), array('name' => $route)); @@ -92,7 +92,7 @@ protected function routeExists($route) * @param bool $redirect * @return mixed */ - protected function getRedirect($currentRoute, $redirect = false) + private function getRedirect($currentRoute, $redirect = false) { $useRedirect = $this->options->getUseRedirectParameterIfPresent(); $routeExists = ($redirect && $this->routeExists($redirect));