diff --git a/cake/libs/router.php b/cake/libs/router.php index b9cc68130..cd4c27999 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -269,7 +269,10 @@ class Router { $self->__prefixes[] = $defaults['prefix']; $self->__prefixes = array_keys(array_flip($self->__prefixes)); } - $defaults += array('action' => 'index', 'plugin' => null); + $defaults += array('plugin' => null); + if (empty($options['action'])) { + $defaults += array('action' => 'index'); + } $routeClass = 'CakeRoute'; if (isset($options['routeClass'])) { $routeClass = $options['routeClass']; diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index f44c32bdc..2e69ab7fc 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1694,6 +1694,45 @@ class RouterTest extends CakeTestCase { $this->assertEqual($result['pass'][0], 'something. . .', 'Period was chopped off %s'); } +/** + * test that patterns work for :action + * + * @return void + */ + function testParsingWithPatternOnAction() { + Router::reload(); + Router::connect( + '/blog/:action/*', + array('controller' => 'blog_posts'), + array('action' => 'other|actions') + ); + $result = Router::parse('/blog/other'); + $expected = array( + 'plugin' => null, + 'controller' => 'blog_posts', + 'action' => 'other', + 'pass' => array(), + 'named' => array() + ); + $this->assertEqual($expected, $result); + + $result = Router::parse('/blog/foobar'); + $expected = array( + 'plugin' => null, + 'controller' => 'blog', + 'action' => 'foobar', + 'pass' => array(), + 'named' => array() + ); + $this->assertEqual($expected, $result); + + $result = Router::url(array('controller' => 'blog_posts', 'action' => 'foo')); + $this->assertEqual('/blog_posts/foo', $result); + + $result = Router::url(array('controller' => 'blog_posts', 'action' => 'actions')); + $this->assertEqual('/blog/actions', $result); + } + /** * testParsingWithPrefixes method * @@ -2489,6 +2528,31 @@ class CakeRouteTestCase extends CakeTestCase { $this->assertFalse($result); } +/** + * test that patterns work for :action + * + * @return void + */ + function testPatternOnAction() { + $route =& new CakeRoute( + '/blog/:action/*', + array('controller' => 'blog_posts'), + array('action' => 'other|actions') + ); + $result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo')); + $this->assertFalse($result); + + $result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions')); + $this->assertTrue($result); + + $result = $route->parse('/blog/other'); + $expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array()); + $this->assertEqual($expected, $result); + + $result = $route->parse('/blog/foobar'); + $this->assertFalse($result); + } + /** * test persistParams ability to persist parameters from $params and remove params. *