Skip to content

Commit

Permalink
Merge pull request #3188 from bar/3.0-all-routes-list
Browse files Browse the repository at this point in the history
Get all the connected routes list.
  • Loading branch information
markstory committed Apr 1, 2014
2 parents de7cf89 + 2db1c1c commit 9584cc9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Routing/RouteCollection.php
Expand Up @@ -225,6 +225,15 @@ public function get($index) {
return isset($this->_routes[$index]) ? $this->_routes[$index] : null;
}

/**
* Get the list of all connected routes.
*
* @return array.
*/
public function all() {
return $this->_routes;
}

/**
* Part of the countable interface.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -332,6 +332,25 @@ public function testMapResourcesConnectOptions() {
$this->assertEquals('^(bar)$', $route->options['foo']);
}

/**
* Test that RouterCollection::all() gets the list of all connected routes.
*
* @return void
*/
public function testRouteCollectionRoutes() {
$collection = new RouteCollection();
Router::setRouteCollection($collection);
Router::mapResources('Posts');

$routes = $collection->all();

$this->assertEquals(count($routes), 6);
$this->assertInstanceOf('Cake\Routing\Route\Route', $routes[0]);
$this->assertEquals($collection->get(0), $routes[0]);
$this->assertInstanceOf('Cake\Routing\Route\Route', $routes[5]);
$this->assertEquals($collection->get(5), $routes[5]);
}

/**
* Test mapResources with a plugin and prefix.
*
Expand Down

0 comments on commit 9584cc9

Please sign in to comment.