Skip to content

Commit

Permalink
Fix for #8942 customized redirect route class (#9010)
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum authored and markstory committed Jun 21, 2016
1 parent 97e071f commit a0d362f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Routing/Router.php
Expand Up @@ -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];
}
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit a0d362f

Please sign in to comment.