Adding additional tests for CakeRoute::persistParams(). Ensures that url params can overwrite persisted values.

Tests added.
This commit is contained in:
Mark Story 2009-12-14 18:43:29 -05:00
parent b8946db4b0
commit ecc38f0aed
2 changed files with 9 additions and 4 deletions

View file

@ -1361,7 +1361,7 @@ class CakeRoute {
*/
function persistParams($url, $params) {
foreach ($this->options['persist'] as $persistKey) {
if (array_key_exists($persistKey, $params)) {
if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) {
$url[$persistKey] = $params[$persistKey];
}
}

View file

@ -2266,8 +2266,14 @@ class CakeRouteTestCase extends CakeTestCase {
$url = array('controller' => 'posts', 'action' => 'index');
$params = array('lang' => 'en', 'color' => 'blue');
$result = $route->persistParams($url, $params);
$this->assertEqual($result['lang'], $params['lang']);
$this->assertEqual($result['color'], $params['color']);
$this->assertEqual($result['lang'], 'en');
$this->assertEqual($result['color'], 'blue');
$url = array('controller' => 'posts', 'action' => 'index', 'color' => 'red');
$params = array('lang' => 'en', 'color' => 'blue');
$result = $route->persistParams($url, $params);
$this->assertEqual($result['lang'], 'en');
$this->assertEqual($result['color'], 'red');
}
/**
@ -2286,5 +2292,4 @@ class CakeRouteTestCase extends CakeTestCase {
}
}
?>