Skip to content
Permalink
Browse files

Making Router throw exceptions when invalid route classes are used fo…

…r routes.
  • Loading branch information...
markstory committed Apr 24, 2010
1 parent e896901 commit 797fa0009ac8f42312ecdd4553115ee6fdb69eb4
Showing with 17 additions and 5 deletions.
  1. +3 −5 cake/libs/router.php
  2. +14 −0 cake/tests/cases/libs/router.test.php
@@ -269,11 +269,9 @@ public static function connect($route, $defaults = array(), $options = array())
$routeClass = $options['routeClass'];
unset($options['routeClass']);
}
//TODO 2.0 refactor this to use a string class name, throw exception, and then construct.
$Route =& new $routeClass($route, $defaults, $options);
if ($routeClass !== 'CakeRoute' && !is_subclass_of($Route, 'CakeRoute')) {
trigger_error(__('Route classes must extend CakeRoute'), E_USER_WARNING);
return false;
$Route = new $routeClass($route, $defaults, $options);
if (!$Route instanceof CakeRoute) {
throw new Exception(__('Route classes must extend CakeRoute'));
}
$self->routes[] =& $Route;
return $self->routes;
@@ -1910,6 +1910,20 @@ function testUsingCustomRouteClass() {
$this->assertEqual($result, $expected);
}
/**
* test that route classes must extend CakeRoute
*
* @return void
*/
function testCustomRouteException() {
try {
Router::connect('/:controller', array(), array('routeClass' => 'Object'));
$this->$this->assertFalse(true, 'No exception thrown when an invalid class was used.');
} catch (Exception $e) {
$this->assertTrue(true, 'Exception correctly thrown');
}
}
/**
* test reversing parameter arrays back into strings.
*

0 comments on commit 797fa00

Please sign in to comment.
You can’t perform that action at this time.