Adding fix for Ticket #2392

Added tests for this fix.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4848 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-04-12 07:17:39 +00:00
parent 4e8a803e81
commit a2ba6d7715
2 changed files with 33 additions and 2 deletions

View file

@ -74,8 +74,8 @@ class Router extends Object {
var $__named = array(
'Action' => 'index|show|list|add|create|edit|update|remove|del|delete|new|view|item',
'Year' => '[12][0-9]{3}',
'Month' => '(0[1-9]|1[012])',
'Day' => '(0[1-9]|[12][0-9]|3[01])',
'Month' => '0[1-9]|1[012]',
'Day' => '0[1-9]|[12][0-9]|3[01]',
'ID' => '[0-9]+'
);
/**

View file

@ -145,6 +145,37 @@ class RouterTest extends UnitTestCase {
$result = $this->router->url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2'));
$this->assertEqual($result, $expected);
$this->router->routes = array();
$this->router->connect('/posts/:value/:somevalue/:othervalue/*', array('controller' => 'posts', 'action' => 'view'), array('value','somevalue', 'othervalue'));
$result = $this->router->parse('/posts/2007/08/01/title-of-post-here');
$expected = array('value' => '2007', 'somevalue' => '08', 'othervalue' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'));
$this->assertEqual($result, $expected);
$this->router->routes = array();
$this->router->connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
$result = $this->router->parse('/posts/2007/08/01/title-of-post-here');
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'));
$this->assertEqual($result, $expected);
$this->router->routes = array();
$this->router->connect('/posts/:day/:year/:month/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
$result = $this->router->parse('/posts/01/2007/08/title-of-post-here');
$expected = array('day' => '01', 'year' => '2007', 'month' => '08', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'));
$this->assertEqual($result, $expected);
$this->router->routes = array();
$this->router->connect('/posts/:month/:day/:year//*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day));
$result = $this->router->parse('/posts/08/01/2007/title-of-post-here');
$expected = array('month' => '08', 'day' => '01', 'year' => '2007', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'));
$this->assertEqual($result, $expected);
$this->router->routes = array();
$this->router->connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'));
$result = $this->router->parse('/posts/2007/08/01/title-of-post-here');
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'));
$this->assertEqual($result, $expected);
}
function testAdminRouting() {