Skip to content
Permalink
Browse files

Raise exceptions when scopes and routes have conflicting parameters

Having a scope contain a route with different parameters is most likely
a mistake. In addition it will defeat optimizations for reverse routing.
  • Loading branch information...
markstory committed Jun 29, 2014
1 parent 5e72b75 commit 41a97c2165871bfcbc279ae195859fdc54e5fabc
Showing with 25 additions and 0 deletions.
  1. +13 −0 src/Routing/ScopedRouteCollection.php
  2. +12 −0 tests/TestCase/Routing/ScopedRouteCollectionTest.php
@@ -390,6 +390,19 @@ protected function _makeRoute($route, $defaults, $options) {
$route = str_replace('//', '/', $this->_path . $route);
if (is_array($defaults)) {
foreach ($this->_params as $param => $val) {
if (isset($defaults[$param]) && $defaults[$param] !== $val) {
$msg = 'You cannot define routes that conflict with the scope. ' .
'Scope had %s = %s, while route had %s = %s';
throw new Error\Exception(sprintf(
$msg,
$param,
$val,
$param,
$defaults[$param]
));
}
}
$defaults += $this->_params;
}
$route = new $routeClass($route, $defaults, $options);
@@ -166,6 +166,18 @@ public function testConnectErrorInvalidRouteClass() {
$routes->connect('/:controller', [], ['routeClass' => '\StdClass']);
}
/**
* Test conflicting parameters raises an exception.
*
* @expectedException \Cake\Error\Exception
* @expectedExceptionMessage You cannot define routes that conflict with the scope.
* @return void
*/
public function testConnectConflictingParameters() {
$routes = new ScopedRouteCollection('/admin', ['prefix' => 'admin'], []);
$routes->connect('/', ['prefix' => 'manager', 'controller' => 'Dashboard', 'action' => 'view']);
}
/**
* Test connecting redirect routes.
*

0 comments on commit 41a97c2

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