mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Bringing Router coverage up to 94.45%, minor router refactorings
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8258 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f53181bc96
commit
9da7b6ef55
2 changed files with 78 additions and 10 deletions
|
@ -533,10 +533,7 @@ class Router extends Object {
|
|||
function compile($i) {
|
||||
$route = $this->routes[$i];
|
||||
|
||||
if (!list($pattern, $names) = $this->writeRoute($route[0], $route[1], $route[2])) {
|
||||
unset($this->routes[$i]);
|
||||
return array();
|
||||
}
|
||||
list($pattern, $names) = $this->writeRoute($route[0], $route[1], $route[2]);
|
||||
$this->routes[$i] = array(
|
||||
$route[0], $pattern, $names,
|
||||
array_merge(array('plugin' => null, 'controller' => null), (array)$route[1]),
|
||||
|
@ -1271,9 +1268,9 @@ class Router extends Object {
|
|||
return $param;
|
||||
}
|
||||
|
||||
$return = preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $param);
|
||||
return $return;
|
||||
return preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $param);
|
||||
}
|
||||
|
||||
foreach ($param as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$return[$key] = preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $value);
|
||||
|
@ -1346,7 +1343,9 @@ class Router extends Object {
|
|||
continue;
|
||||
}
|
||||
$param = $_this->stripEscape($param);
|
||||
if ((!isset($options['named']) || !empty($options['named'])) && strpos($param, $_this->named['separator']) !== false) {
|
||||
|
||||
$separatorIsPresent = strpos($param, $_this->named['separator']) !== false;
|
||||
if ((!isset($options['named']) || !empty($options['named'])) && $separatorIsPresent) {
|
||||
list($key, $val) = explode($_this->named['separator'], $param, 2);
|
||||
$hasRule = isset($rules[$key]);
|
||||
$passIt = (!$hasRule && !$greedy) || ($hasRule && !Router::matchNamed($key, $val, $rules[$key], $context));
|
||||
|
|
|
@ -1670,5 +1670,74 @@ class RouterTest extends CakeTestCase {
|
|||
$this->assertEqual(Router::stripPlugin($url), $url);
|
||||
$this->assertEqual(Router::stripPlugin($url, null), $url);
|
||||
}
|
||||
/**
|
||||
* testCurentRoute
|
||||
*
|
||||
* This test needs some improvement and actual requestAction() usage
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testCurentRoute() {
|
||||
$url = array('controller' => 'pages', 'action' => 'display', 'government');
|
||||
Router::connect('/government', $url);
|
||||
Router::parse('/government');
|
||||
$route = Router::currentRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]);
|
||||
}
|
||||
/**
|
||||
* testRequestRoute
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testRequestRoute() {
|
||||
$url = array('controller' => 'products', 'action' => 'display', 5);
|
||||
Router::connect('/government', $url);
|
||||
Router::parse('/government');
|
||||
$route = Router::requestRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]);
|
||||
|
||||
// test that the first route is matched
|
||||
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
|
||||
Router::connect('/government', $url);
|
||||
Router::parse('/government');
|
||||
$route = Router::requestRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]);
|
||||
|
||||
// test that an unmatched route does not change the current route
|
||||
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
|
||||
Router::connect('/actor', $url);
|
||||
Router::parse('/government');
|
||||
$route = Router::requestRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]);
|
||||
}
|
||||
/**
|
||||
* testGetParams
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetParams() {
|
||||
$paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot');
|
||||
$params = array('param1' => '1', 'param2' => '2');
|
||||
Router::setRequestInfo(array($params, $paths));
|
||||
$expected = array(
|
||||
'plugin' => false, 'controller' => false, 'action' => false,
|
||||
'param1' => '1', 'param2' => '2'
|
||||
);
|
||||
$this->assertEqual(Router::getparams(), $expected);
|
||||
$this->assertEqual(Router::getparam('controller'), false);
|
||||
$this->assertEqual(Router::getparam('param1'), '1');
|
||||
$this->assertEqual(Router::getparam('param2'), '2');
|
||||
|
||||
Router::reload();
|
||||
|
||||
$params = array('controller' => 'pages', 'action' => 'display');
|
||||
Router::setRequestInfo(array($params, $paths));
|
||||
$expected = array('plugin' => false, 'controller' => 'pages', 'action' => 'display');
|
||||
$this->assertEqual(Router::getparams(), $expected);
|
||||
$this->assertEqual(Router::getparams(true), $expected);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue