Permalink
Browse files

Implementing the ability to use custom Route classes when connecting …

…routes. Tests added.
  • Loading branch information...
1 parent 218af68 commit 8c4d3897608668e8bccea7c509820fc0a984be46 @markstory markstory committed Dec 4, 2009
Showing with 26 additions and 4 deletions.
  1. +6 −1 cake/libs/router.php
  2. +20 −3 cake/tests/cases/libs/router.test.php
View
@@ -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;
}
@@ -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
*

0 comments on commit 8c4d389

Please sign in to comment.