mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Make CakeRoute::persistParams() more tolerant
Subclasses and instances may not always define persist options. CakeRoute should be accepting of these differences. Fixes #3957
This commit is contained in:
parent
50b192eb1b
commit
8209a298f7
2 changed files with 37 additions and 0 deletions
|
@ -378,6 +378,9 @@ class CakeRoute {
|
|||
* @return array An array with persistent parameters applied.
|
||||
*/
|
||||
public function persistParams($url, $params) {
|
||||
if (empty($this->options['persist']) || !is_array($this->options['persist'])) {
|
||||
return $url;
|
||||
}
|
||||
foreach ($this->options['persist'] as $persistKey) {
|
||||
if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) {
|
||||
$url[$persistKey] = $params[$persistKey];
|
||||
|
|
|
@ -484,6 +484,40 @@ class CakeRouteTest extends CakeTestCase {
|
|||
$this->assertEquals('red', $result['color']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test persist with a non array value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPersistParamsNonArray() {
|
||||
$url = array('controller' => 'posts', 'action' => 'index');
|
||||
$params = array('lang' => 'en', 'color' => 'blue');
|
||||
|
||||
$route = new CakeRoute(
|
||||
'/:lang/:color/blog/:action',
|
||||
array('controller' => 'posts')
|
||||
// No persist options
|
||||
);
|
||||
$result = $route->persistParams($url, $params);
|
||||
$this->assertEquals($url, $result);
|
||||
|
||||
$route = new CakeRoute(
|
||||
'/:lang/:color/blog/:action',
|
||||
array('controller' => 'posts'),
|
||||
array('persist' => false)
|
||||
);
|
||||
$result = $route->persistParams($url, $params);
|
||||
$this->assertEquals($url, $result);
|
||||
|
||||
$route = new CakeRoute(
|
||||
'/:lang/:color/blog/:action',
|
||||
array('controller' => 'posts'),
|
||||
array('persist' => 'derp')
|
||||
);
|
||||
$result = $route->persistParams($url, $params);
|
||||
$this->assertEquals($url, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the parse method of CakeRoute.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue