Skip to content
Permalink
Browse files

RedirectRoute class does not honor persist as array with custom route…

… elements.

Custom route elements like '/:lang/etc' should be persisted by redirect
routes as they are in standard routes.

Refs #GH-1531
  • Loading branch information...
joostdekeijzer authored and markstory committed Aug 15, 2013
1 parent 8428928 commit 7fe2395be3ee21a2e1203dec968ab58d84140621
Showing with 23 additions and 0 deletions.
  1. +7 −0 lib/Cake/Routing/Route/RedirectRoute.php
  2. +16 −0 lib/Cake/Test/Case/Routing/Route/RedirectRouteTest.php
@@ -80,6 +80,13 @@ public function parse($url) {
}
if (isset($this->options['persist']) && is_array($redirect)) {
$redirect += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
if (is_array($this->options['persist'])) {
foreach ($this->options['persist'] as $elem) {
if (isset($params[$elem])) {
$redirect[$elem] = $params[$elem];
}
}
}
$redirect = Router::reverse($redirect);
}
$status = 301;
@@ -103,6 +103,22 @@ public function testParsing() {
$result = $route->parse('/my_controllers/do_something/passme/named:param');
$header = $route->response->header();
$this->assertEquals(Router::url('/tags/add', true), $header['Location']);
$route = new RedirectRoute('/:lang/my_controllers', array('controller' => 'tags', 'action' => 'add'), array('lang' => '(nl|en)', 'persist' => array('lang')));
$route->stop = false;
$route->response = $this->getMock('CakeResponse', array('_sendHeader'));
$result = $route->parse('/nl/my_controllers/');
$header = $route->response->header();
$this->assertEquals(Router::url('/tags/add/lang:nl', true), $header['Location']);
Router::$routes = array(); // reset default routes
Router::connect('/:lang/preferred_controllers', array('controller' => 'tags', 'action' => 'add'), array('lang' => '(nl|en)', 'persist' => array('lang')));
$route = new RedirectRoute('/:lang/my_controllers', array('controller' => 'tags', 'action' => 'add'), array('lang' => '(nl|en)', 'persist' => array('lang')));
$route->stop = false;
$route->response = $this->getMock('CakeResponse', array('_sendHeader'));
$result = $route->parse('/nl/my_controllers/');
$header = $route->response->header();
$this->assertEquals(Router::url('/nl/preferred_controllers', true), $header['Location']);
}
}

0 comments on commit 7fe2395

Please sign in to comment.
You can’t perform that action at this time.