From a0d362f51fdb83a3dd74b4372d2768bae4bf89f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 21 Jun 2016 03:39:21 +0200 Subject: [PATCH] Fix for #8942 customized redirect route class (#9010) --- src/Routing/Router.php | 2 +- tests/TestCase/Routing/RouterTest.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Routing/Router.php b/src/Routing/Router.php index ea34eba2129..54006505eae 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -222,7 +222,7 @@ public static function connect($route, $defaults = [], $options = []) */ public static function redirect($route, $url, $options = []) { - $options['routeClass'] = 'Cake\Routing\Route\RedirectRoute'; + $options += ['routeClass' => 'Cake\Routing\Route\RedirectRoute']; if (is_string($url)) { $url = ['redirect' => $url]; } diff --git a/tests/TestCase/Routing/RouterTest.php b/tests/TestCase/Routing/RouterTest.php index 441465dc095..37da0dcaa47 100644 --- a/tests/TestCase/Routing/RouterTest.php +++ b/tests/TestCase/Routing/RouterTest.php @@ -2869,6 +2869,28 @@ public function testRedirect() $this->assertInstanceOf('Cake\Routing\Route\RedirectRoute', $route); } + /** + * Test that redirect() works with another route class. + * + * @return void + */ + public function testRedirectWithAnotherRouteClass() + { + $route1 = $this->getMockBuilder('Cake\Routing\Route\RedirectRoute') + ->setConstructorArgs(['/mobile\'']) + ->getMock(); + $class = '\\' . get_class($route1); + + Router::redirect('/mobile', '/', [ + 'status' => 301, + 'routeClass' => $class + ]); + + $routes = Router::routes(); + $route = $routes[0]; + $this->assertInstanceOf($class, $route); + } + /** * Test that the compatibility method for incoming urls works. *