More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / EventSubscriber / SpecialAttributesRouteSubscriberTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\EventSubscriber;
4
5 use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber;
6 use Drupal\Core\Routing\RouteBuildEvent;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
9 use Symfony\Component\Routing\Route;
10
11 /**
12  * @coversDefaultClass \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
13  * @group EventSubscriber
14  */
15 class SpecialAttributesRouteSubscriberTest extends UnitTestCase {
16
17   /**
18    * Provides a list of routes with invalid route variables.
19    *
20    * @return array
21    *   An array of invalid routes.
22    */
23   public function providerTestOnRouteBuildingInvalidVariables() {
24     // Build an array of mock route objects based on paths.
25     $routes = [];
26     $paths = [
27       '/test/{system_path}',
28       '/test/{_legacy}',
29       '/test/{' . RouteObjectInterface::ROUTE_OBJECT . '}',
30       '/test/{' . RouteObjectInterface::ROUTE_NAME . '}',
31       '/test/{_content}',
32       '/test/{_form}',
33       '/test/{_raw_variables}',
34     ];
35
36     foreach ($paths as $path) {
37       $routes[] = [new Route($path)];
38     }
39
40     return $routes;
41   }
42
43   /**
44    * Provides a list of routes with valid route variables.
45    *
46    * @return array
47    *   An array of valid routes.
48    */
49   public function providerTestOnRouteBuildingValidVariables() {
50     // Build an array of mock route objects based on paths.
51     $routes = [];
52     $paths = [
53       '/test/{account}',
54       '/test/{node}',
55       '/test/{user}',
56       '/test/{entity_test}',
57     ];
58
59     foreach ($paths as $path) {
60       $routes[] = [new Route($path)];
61     }
62
63     return $routes;
64   }
65
66   /**
67    * Tests the onAlterRoutes method for valid variables.
68    *
69    * @param \Symfony\Component\Routing\Route $route
70    *   The route to check.
71    *
72    * @dataProvider providerTestOnRouteBuildingValidVariables
73    *
74    * @covers ::onAlterRoutes
75    */
76   public function testOnRouteBuildingValidVariables(Route $route) {
77     $route_collection = $this->getMock('Symfony\Component\Routing\RouteCollection', NULL);
78     $route_collection->add('test', $route);
79
80     $event = new RouteBuildEvent($route_collection, 'test');
81     $subscriber = new SpecialAttributesRouteSubscriber();
82     $this->assertNull($subscriber->onAlterRoutes($event));
83   }
84
85   /**
86    * Tests the onAlterRoutes method for invalid variables.
87    *
88    * @param \Symfony\Component\Routing\Route $route
89    *   The route to check.
90    *
91    * @dataProvider providerTestOnRouteBuildingInvalidVariables
92    * @covers ::onAlterRoutes
93    */
94   public function testOnRouteBuildingInvalidVariables(Route $route) {
95     $route_collection = $this->getMock('Symfony\Component\Routing\RouteCollection', NULL);
96     $route_collection->add('test', $route);
97
98     $event = new RouteBuildEvent($route_collection, 'test');
99     $subscriber = new SpecialAttributesRouteSubscriber();
100     $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names');
101     $subscriber->onAlterRoutes($event);
102   }
103
104 }