More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / EventSubscriber / PathRootsSubscriberTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\EventSubscriber;
4
5 use Drupal\Core\EventSubscriber\PathRootsSubscriber;
6 use Drupal\Core\Routing\RouteBuildEvent;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\Routing\Route;
9 use Symfony\Component\Routing\RouteCollection;
10
11 /**
12  * @coversDefaultClass \Drupal\Core\EventSubscriber\PathRootsSubscriber
13  * @group EventSubscriber
14  */
15 class PathRootsSubscriberTest extends UnitTestCase {
16
17   /**
18    * The mocked state.
19    *
20    * @var \Drupal\Core\State\StateInterface|\PHPUnit_Framework_MockObject_MockObject
21    */
22   protected $state;
23
24   /**
25    * The tested path root subscriber.
26    *
27    * @var \Drupal\Core\EventSubscriber\PathRootsSubscriber
28    */
29   protected $pathRootsSubscriber;
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     $this->state = $this->getMock('Drupal\Core\State\StateInterface');
36     $this->pathRootsSubscriber = new PathRootsSubscriber($this->state);
37   }
38
39   /**
40    * Tests altering and finished event.
41    *
42    * @covers ::onRouteAlter
43    * @covers ::onRouteFinished
44    */
45   public function testSubscribing() {
46
47     // Ensure that onRouteFinished can be called without throwing notices
48     // when no path roots got set.
49     $this->pathRootsSubscriber->onRouteFinished();
50
51     $route_collection = new RouteCollection();
52     $route_collection->add('test_route1', new Route('/test/bar'));
53     $route_collection->add('test_route2', new Route('/test/baz'));
54     $route_collection->add('test_route3', new Route('/test2/bar/baz'));
55
56     $event = new RouteBuildEvent($route_collection, 'provider');
57     $this->pathRootsSubscriber->onRouteAlter($event);
58
59     $route_collection = new RouteCollection();
60     $route_collection->add('test_route4', new Route('/test1/bar'));
61     $route_collection->add('test_route5', new Route('/test2/baz'));
62     $route_collection->add('test_route6', new Route('/test2/bar/baz'));
63
64     $event = new RouteBuildEvent($route_collection, 'provider');
65     $this->pathRootsSubscriber->onRouteAlter($event);
66
67     $this->state->expects($this->once())
68       ->method('set')
69       ->with('router.path_roots', ['test', 'test2', 'test1']);
70
71     $this->pathRootsSubscriber->onRouteFinished();
72   }
73
74 }