Skip to content

Commit

Permalink
Add test for added cases in RouteCollection::_getNames()
Browse files Browse the repository at this point in the history
The additional prefix names are needed for cases like this test.
Uncomment accidentally commented out test case.
  • Loading branch information
markstory committed Jul 7, 2014
1 parent 7cb51d7 commit f981c7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
36 changes: 36 additions & 0 deletions tests/TestCase/Routing/RouteCollectionTest.php
Expand Up @@ -178,6 +178,42 @@ public function testMatchPlugin() {
$this->assertEquals('contacts', $result);
}

/**
* Test that prefixes increase the specificity of a route match.
*
* Connect the admin route after the non prefixed version, this means
* the non-prefix route would have a more specific name (users:index)
*
* @return void
*/
public function testMatchPrefixSpecificity() {
$context = [
'_base' => '/',
'_scheme' => 'http',
'_host' => 'example.org',
];
$routes = new RouteBuilder($this->collection, '/');
$routes->connect('/:action/*', ['controller' => 'Users']);
$routes->connect('/admin/:controller', ['prefix' => 'admin', 'action' => 'index']);

$url = [
'plugin' => null,
'prefix' => 'admin',
'controller' => 'Users',
'action' => 'index'
];
$result = $this->collection->match($url, $context);
$this->assertEquals('admin/Users', $result);

$url = [
'plugin' => null,
'controller' => 'Users',
'action' => 'index'
];
$result = $this->collection->match($url, $context);
$this->assertEquals('index', $result);
}

/**
* Test getting named routes.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -1880,9 +1880,9 @@ public function testPagesUrlParsing() {
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

// $result = Router::parse('/');
// $expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
// $this->assertEquals($expected, $result);
$result = Router::parse('/');
$expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
$this->assertEquals($expected, $result);

$result = Router::parse('/pages/home/');
$expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
Expand Down

0 comments on commit f981c7c

Please sign in to comment.