diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index 1c90a62..8ae908a 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -7,12 +7,9 @@ namespace Drupal\Tests\Core\EventSubscriber; -use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber; -use Drupal\Core\Routing\RouteBuildEvent; 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 @@ -21,37 +18,29 @@ 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. * * @return array * An array of invalid routes. */ public function providerTestOnRouteBuildingInvalidVariables() { + // Build an array of mock route objects based on paths. $routes = array(); - $routes[] = array(new Route('/test/{system_path}')); - $routes[] = array(new Route('/test/{_legacy}')); - $routes[] = array(new Route('/test/{_authentication_provider}')); - $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}')); + $paths = array( + '/test/{system_path}', + '/test/{_legacy}', + '/test/{_authentication_provider}', + '/test/{' . RouteObjectInterface::ROUTE_OBJECT . '}', + '/test/{' . RouteObjectInterface::ROUTE_NAME . '}', + '/test/{_content}', + '/test/{_form}', + '/test/{_raw_variables}', + ); + + foreach ($paths as $path) { + $route = $this->getMock('Symfony\Component\Routing\Route', NULL, array($path)); + $routes[] = array($route); + } return $routes; } @@ -63,11 +52,19 @@ public function providerTestOnRouteBuildingInvalidVariables() { * An array of valid routes. */ public function providerTestOnRouteBuildingValidVariables() { + // Build an array of mock route objects based on paths. $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}')); + $paths = array( + '/test/{account}', + '/test/{node}', + '/test/{user}', + '/test/{entity_test}', + ); + + foreach ($paths as $path) { + $route = $this->getMock('Symfony\Component\Routing\Route', NULL, array($path)); + $routes[] = array($route); + } return $routes; } @@ -79,12 +76,22 @@ 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); + + $event = $this->getMock( + 'Drupal\Core\Routing\RouteBuildEvent', + NULL, + array($route_collection, 'test') + ); + + $subscriber = $this->getMock('Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber'); + + $this->assertTrue($subscriber->onAlterRoutes($event)); } /** @@ -96,12 +103,22 @@ 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); + + $event = $this->getMock( + 'Drupal\Core\Routing\RouteBuildEvent', + NULL, + array($route_collection, 'test') + ); + + $subscriber = $this->getMock('Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber'); + + $this->assertFalse($subscriber->onAlterRoutes($event)); } }