Pull merge.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Routing / RouterTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Routing;
4
5 use Drupal\Core\Path\CurrentPathStack;
6 use Drupal\Core\Routing\RequestContext;
7 use Drupal\Core\Routing\RouteCompiler;
8 use Drupal\Core\Routing\RouteProviderInterface;
9 use Drupal\Core\Routing\Router;
10 use Drupal\Core\Routing\UrlGeneratorInterface;
11 use Drupal\Tests\UnitTestCase;
12 use Prophecy\Argument;
13 use Symfony\Component\Routing\Route;
14 use Symfony\Component\Routing\RouteCollection;
15
16 /**
17  * @coversDefaultClass \Drupal\Core\Routing\Router
18  * @group Routing
19  */
20 class RouterTest extends UnitTestCase {
21
22   /**
23    * @covers ::applyFitOrder
24    */
25   public function testMatchesWithDifferentFitOrder() {
26     $route_provider = $this->prophesize(RouteProviderInterface::class);
27
28     $route_collection = new RouteCollection();
29
30     $route = new Route('/user/{user}');
31     $route->setOption('compiler_class', RouteCompiler::class);
32     $route_collection->add('user_view', $route);
33
34     $route = new Route('/user/login');
35     $route->setOption('compiler_class', RouteCompiler::class);
36     $route_collection->add('user_login', $route);
37
38     $route_provider->getRouteCollectionForRequest(Argument::any())
39       ->willReturn($route_collection);
40
41     $url_generator = $this->prophesize(UrlGeneratorInterface::class);
42     $current_path_stack = $this->prophesize(CurrentPathStack::class);
43     $router = new Router($route_provider->reveal(), $current_path_stack->reveal(), $url_generator->reveal());
44
45     $request_context = $this->prophesize(RequestContext::class);
46     $request_context->getScheme()->willReturn('http');
47     $router->setContext($request_context->reveal());
48
49     $current_path_stack->getPath(Argument::any())->willReturn('/user/1');
50     $result = $router->match('/user/1');
51
52     $this->assertEquals('user_view', $result['_route']);
53
54     $current_path_stack->getPath(Argument::any())->willReturn('/user/login');
55     $result = $router->match('/user/login');
56
57     $this->assertEquals('user_login', $result['_route']);
58   }
59
60 }