From a2ba6d77156a1510d7ce007068f8557c5ef139ba Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 12 Apr 2007 07:17:39 +0000 Subject: [PATCH] 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 --- cake/libs/router.php | 4 ++-- cake/tests/cases/libs/router.test.php | 31 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index 2751eca34..8b6da1d87 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -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]+' ); /** diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 0b2939032..54dc05cb4 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -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() {