Browse Source

Fix for #8942 customized redirect route class (#9010)

Florian Krämer 9 years ago
parent
commit
a0d362f51f
2 changed files with 23 additions and 1 deletions
  1. 1 1
      src/Routing/Router.php
  2. 22 0
      tests/TestCase/Routing/RouterTest.php

+ 1 - 1
src/Routing/Router.php

@@ -222,7 +222,7 @@ class Router
      */
     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];
         }

+ 22 - 0
tests/TestCase/Routing/RouterTest.php

@@ -2870,6 +2870,28 @@ class RouterTest extends TestCase
     }
 
     /**
+     * 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.
      *
      * @return void