mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Implementing the ability to use custom Route classes when connecting routes. Tests added.
This commit is contained in:
parent
218af686d7
commit
8c4d389760
2 changed files with 26 additions and 4 deletions
|
@ -275,7 +275,12 @@ class Router {
|
|||
$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 @@ class RouterTest extends CakeTestCase {
|
|||
*
|
||||
* @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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue