Commit c1b4c032 authored by alexpott's avatar alexpott

Issue #2364467 by Mile23, neclimdul:...

Issue #2364467 by Mile23, neclimdul: SpecialAttributesRouteSubscriber::onAlterRoutes() doesn't return a value
parent c8907ebc
......@@ -44,14 +44,10 @@ protected function alterRoutes(RouteCollection $collection) {
*
* @param \Drupal\Core\Routing\RouteBuildEvent $event
* The route build event.
*
* @return bool
* Returns TRUE if the variables were successfully replaced, otherwise
* FALSE.
*/
public function onAlterRoutes(RouteBuildEvent $event) {
$collection = $event->getRouteCollection();
return $this->alterRoutes($collection);
$this->alterRoutes($collection);
}
}
......@@ -12,7 +12,6 @@
use Drupal\Tests\UnitTestCase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* @coversDefaultClass \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
......@@ -20,22 +19,6 @@
*/
class SpecialAttributesRouteSubscriberTest extends UnitTestCase {
/**
* The tested route subscriber.
*
* @var \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
*/
protected $specialAttributesRouteSubscriber;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->specialAttributesRouteSubscriber = new SpecialAttributesRouteSubscriber();
}
/**
* Provides a list of routes with invalid route variables.
*
......@@ -43,14 +26,21 @@ protected function setUp() {
* An array of invalid routes.
*/
public function providerTestOnRouteBuildingInvalidVariables() {
$routes = array();
$routes[] = array(new Route('/test/{system_path}'));
$routes[] = array(new Route('/test/{_legacy}'));
$routes[] = array(new Route('/test/{' . RouteObjectInterface::ROUTE_OBJECT . '}'));
$routes[] = array(new Route('/test/{' . RouteObjectInterface::ROUTE_NAME . '}'));
$routes[] = array(new Route('/test/{_content}'));
$routes[] = array(new Route('/test/{_form}'));
$routes[] = array(new Route('/test/{_raw_variables}'));
// Build an array of mock route objects based on paths.
$routes = [];
$paths = [
'/test/{system_path}',
'/test/{_legacy}',
'/test/{' . RouteObjectInterface::ROUTE_OBJECT . '}',
'/test/{' . RouteObjectInterface::ROUTE_NAME . '}',
'/test/{_content}',
'/test/{_form}',
'/test/{_raw_variables}',
];
foreach ($paths as $path) {
$routes[] = [new Route($path)];
}
return $routes;
}
......@@ -62,11 +52,18 @@ public function providerTestOnRouteBuildingInvalidVariables() {
* An array of valid routes.
*/
public function providerTestOnRouteBuildingValidVariables() {
$routes = array();
$routes[] = array(new Route('/test/{account}'));
$routes[] = array(new Route('/test/{node}'));
$routes[] = array(new Route('/test/{user}'));
$routes[] = array(new Route('/test/{entity_test}'));
// Build an array of mock route objects based on paths.
$routes = [];
$paths = [
'/test/{account}',
'/test/{node}',
'/test/{user}',
'/test/{entity_test}',
];
foreach ($paths as $path) {
$routes[] = [new Route($path)];
}
return $routes;
}
......@@ -78,12 +75,16 @@ public function providerTestOnRouteBuildingValidVariables() {
* The route to check.
*
* @dataProvider providerTestOnRouteBuildingValidVariables
*
* @covers ::onAlterRoutes
*/
public function testOnRouteBuildingValidVariables(Route $route) {
$route_collection = new RouteCollection();
$route_collection = $this->getMock('Symfony\Component\Routing\RouteCollection', NULL);
$route_collection->add('test', $route);
$event = new RouteBuildEvent($route_collection, 'test');
$this->specialAttributesRouteSubscriber->onAlterRoutes($event);
$subscriber = new SpecialAttributesRouteSubscriber();
$this->assertNull($subscriber->onAlterRoutes($event));
}
/**
......@@ -95,12 +96,16 @@ public function testOnRouteBuildingValidVariables(Route $route) {
* @dataProvider providerTestOnRouteBuildingInvalidVariables
* @expectedException \PHPUnit_Framework_Error_Warning
* @expectedExceptionMessage uses reserved variable names
*
* @covers ::onAlterRoutes
*/
public function testOnRouteBuildingInvalidVariables(Route $route) {
$route_collection = new RouteCollection();
$route_collection = $this->getMock('Symfony\Component\Routing\RouteCollection', NULL);
$route_collection->add('test', $route);
$event = new RouteBuildEvent($route_collection, 'test');
$this->specialAttributesRouteSubscriber->onAlterRoutes($event);
$subscriber = new SpecialAttributesRouteSubscriber();
$subscriber->onAlterRoutes($event);
}
}
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