mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
8428928fd6
commit
7fe2395be3
2 changed files with 23 additions and 0 deletions
|
@ -80,6 +80,13 @@ class RedirectRoute extends CakeRoute {
|
|||
}
|
||||
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 @@ class RedirectRouteTest extends CakeTestCase {
|
|||
$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']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue