Skip to content

Commit

Permalink
Implementing the ability to use custom Route classes when connecting …
Browse files Browse the repository at this point in the history
…routes. Tests added.
  • Loading branch information
markstory committed Dec 4, 2009
1 parent 218af68 commit 8c4d389
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cake/libs/router.php
Expand Up @@ -275,7 +275,12 @@ function connect($route, $defaults = array(), $options = array()) {
$self->__prefixes = array_keys(array_flip($self->__prefixes));
}
$defaults += array('action' => 'index', 'plugin' => null, 'controller' => null);
$self->routes[] =& new RouterRoute($route, $defaults, $options);
$routeClass = 'RouterRoute';
if (isset($options['routeClass'])) {
$routeClass = $options['routeClass'];
unset($options['routeClass']);
}
$self->routes[] =& new $routeClass($route, $defaults, $options);
return $self->routes;
}

Expand Down
23 changes: 20 additions & 3 deletions cake/tests/cases/libs/router.test.php
Expand Up @@ -1938,17 +1938,34 @@ function testGetParams() {
*
* @return void
*/
function testRouterConnectDefaults() {
function testDefaultsMethod() {
Router::defaults(false);
Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 2));
$result = Router::parse('/posts/edit/5');
$this->assertFalse(isset($result['controller']));
$this->assertFalse(isset($result['action']));
}

/**
* test using a custom route class for route connection
*
* @return void
*/
function testUsingCustomRouteClass() {
Mock::generate('RouterRoute', 'MockConnectedRoute');
$routes = Router::connect(
'/:slug',
array('controller' => 'posts', 'action' => 'view'),
array('routeClass' => 'MockConnectedRoute', 'slug' => '[a-z_-]+')
);
$this->assertTrue(is_a($routes[0], 'MockConnectedRoute'), 'Incorrect class used. %s');
$expected = array('controller' => 'posts', 'action' => 'view', 'slug' => 'test');
$routes[0]->setReturnValue('parse', $expected);
$result = Router::parse('/test');
$this->assertEqual($result, $expected);
}
}

// SimpleTest::ignore('RouterTest');
// SimpleTest::ignore('RouterRouteTestCase');
/**
* Test case for RouterRoute
*
Expand Down

0 comments on commit 8c4d389

Please sign in to comment.