Skip to content

Commit

Permalink
Fix error in Router::redirect().
Browse files Browse the repository at this point in the history
Type warnings would be emitted when redirect() was called with a string
target.
  • Loading branch information
markstory committed Jun 29, 2014
1 parent 982b696 commit 74c7273
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Routing/Router.php
Expand Up @@ -361,6 +361,9 @@ public static function connect($route, $defaults = [], $options = []) {
*/
public static function redirect($route, $url, $options = []) {
$options['routeClass'] = 'Cake\Routing\Route\RedirectRoute';
if (is_string($url)) {
$url = ['redirect' => $url];
}
return static::connect($route, $url, $options);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -2676,6 +2676,18 @@ public function testPatternOnAction() {
$this->assertFalse($result);
}

/**
* Test that redirect() works.
*
* @return void
*/
public function testRedirect() {
Router::redirect('/mobile', '/', ['status' => 301]);
$scope = Router::scope('/');
$route = $scope->routes()[0];
$this->assertInstanceOf('Cake\Routing\Route\RedirectRoute', $route);
}

/**
* Tests resourceMap as getter and setter.
*
Expand Down

0 comments on commit 74c7273

Please sign in to comment.