mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding tests for incorrectly matched routes
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5931 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
458bd08027
commit
9b578c5bb1
2 changed files with 39 additions and 5 deletions
|
@ -837,16 +837,15 @@ class Router extends Object {
|
|||
if (array_diff($paramsKeys, $routeParams) != array()) {
|
||||
return false;
|
||||
}
|
||||
$required = array_values(array_diff($defaultsKeys, $urlKeys));
|
||||
$required = array_values(array_diff($routeParams, $urlKeys));
|
||||
$reqCount = count($required);
|
||||
|
||||
|
||||
for ($i = 0; $i < $reqCount; $i++) {
|
||||
if (array_key_exists($required[$i], $defaults) && $defaults[$required[$i]] === null) {
|
||||
unset($required[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$isFilled = true;
|
||||
|
||||
if (!empty($routeParams)) {
|
||||
|
|
|
@ -661,7 +661,6 @@ class RouterTest extends UnitTestCase {
|
|||
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2'));
|
||||
$expected = '/beheer/posts/index/0?var=test&var2=test2';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
}
|
||||
|
||||
function testExtensionParsingSetting() {
|
||||
|
@ -865,7 +864,6 @@ class RouterTest extends UnitTestCase {
|
|||
function testPassedArgsOrder() {
|
||||
$this->router->reload();
|
||||
|
||||
$this->router->testing = true;
|
||||
$this->router->connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
|
||||
$this->router->connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1));
|
||||
$this->router->parse('/');
|
||||
|
@ -900,6 +898,43 @@ class RouterTest extends UnitTestCase {
|
|||
$expected = array('protected', 'admin');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testRegexRouteMatching() {
|
||||
$this->router->reload();
|
||||
$this->router->connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng'));
|
||||
|
||||
$result = $this->router->parse('/test/test_action');
|
||||
$expected = array('pass' => array(), 'controller' => 'test', 'action' => 'test_action', 'plugin' => null);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->parse('/eng/test/test_action');
|
||||
$expected = array('pass' => array(), 'locale' => 'eng', 'controller' => 'test', 'action' => 'test_action', 'plugin' => null);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->parse('/badness/test/test_action');
|
||||
$expected = array('pass' => array('test_action'), 'controller' => 'badness', 'action' => 'test', 'plugin' => null);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->router->reload();
|
||||
$this->router->connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng'));
|
||||
|
||||
$this->router->setRequestInfo(array(
|
||||
array('plugin' => null, 'controller' => 'test', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array ('url' => 'test/test_action'), 'bare' => 0, 'webservices' => null),
|
||||
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/test/test_action', 'webroot' => '/')
|
||||
));
|
||||
|
||||
$result = $this->router->url(array('action' => 'test_another_action'));
|
||||
$expected = '/test/test_another_action/';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->url(array('action' => 'test_another_action', 'locale' => 'eng'));
|
||||
$expected = '/eng/test/test_another_action';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->url(array('action' => 'test_another_action', 'locale' => 'badness'));
|
||||
$expected = '/test/test_another_action/locale:badness';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue