Commit 95231195 authored by alexpott's avatar alexpott

Issue #2051877 by dawehner, sun, tstoeckler: Log error when people use invalid route parameters.

parent b0152299
......@@ -33,16 +33,12 @@ protected function alterRoutes(RouteCollection $collection) {
'_content',
'_form',
);
foreach ($collection->all() as $route) {
foreach ($collection->all() as $name => $route) {
if ($not_allowed_variables = array_intersect($route->compile()->getVariables(), $special_variables)) {
$placeholders = array('@variables' => implode(', ', $not_allowed_variables));
drupal_set_message(String::format('The following variables are reserved names by drupal: @variables', $placeholders));
watchdog('error', 'The following variables are reserved names by drupal: @variables', $placeholders);
return FALSE;
$reserved = implode(', ', $not_allowed_variables);
trigger_error(sprintf('Route %s uses reserved variable names: %s', $name, $reserved), E_USER_WARNING);
}
}
return TRUE;
}
/**
......
......@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Core\EventSubscriber\SpecialAttributesRouteSubscriberTest.
*/
namespace Drupal\Tests\Core\EventSubscriber {
namespace Drupal\Tests\Core\EventSubscriber;
use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber;
use Drupal\Core\Routing\RouteBuildEvent;
......@@ -85,7 +85,7 @@ public function testOnRouteBuildingValidVariables(Route $route) {
$route_collection = new RouteCollection();
$route_collection->add('test', $route);
$event = new RouteBuildEvent($route_collection, 'test');
$this->assertTrue($this->specialAttributesRouteSubscriber->onAlterRoutes($event));
$this->specialAttributesRouteSubscriber->onAlterRoutes($event);
}
/**
......@@ -95,25 +95,14 @@ public function testOnRouteBuildingValidVariables(Route $route) {
* The route to check.
*
* @dataProvider providerTestOnRouteBuildingInvalidVariables
* @expectedException \PHPUnit_Framework_Error_Warning
* @expectedExceptionMessage uses reserved variable names
*/
public function testOnRouteBuildingInvalidVariables(Route $route) {
$route_collection = new RouteCollection();
$route_collection->add('test', $route);
$event = new RouteBuildEvent($route_collection, 'test');
$this->assertFalse($this->specialAttributesRouteSubscriber->onAlterRoutes($event));
$this->specialAttributesRouteSubscriber->onAlterRoutes($event);
}
}
}
namespace {
if (!function_exists('watchdog')) {
function watchdog($type, $message, array $args = array()) {
}
}
if (!function_exists('drupal_set_message')) {
function drupal_set_message($type = NULL, $message = '') {
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment