3 namespace Drupal\Tests\Core\Routing;
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;
17 * @coversDefaultClass \Drupal\Core\Routing\Router
20 class RouterTest extends UnitTestCase {
23 * @covers ::applyFitOrder
25 public function testMatchesWithDifferentFitOrder() {
26 $route_provider = $this->prophesize(RouteProviderInterface::class);
28 $route_collection = new RouteCollection();
30 $route = new Route('/user/{user}');
31 $route->setOption('compiler_class', RouteCompiler::class);
32 $route_collection->add('user_view', $route);
34 $route = new Route('/user/login');
35 $route->setOption('compiler_class', RouteCompiler::class);
36 $route_collection->add('user_login', $route);
38 $route_provider->getRouteCollectionForRequest(Argument::any())
39 ->willReturn($route_collection);
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());
45 $request_context = $this->prophesize(RequestContext::class);
46 $request_context->getScheme()->willReturn('http');
47 $router->setContext($request_context->reveal());
49 $current_path_stack->getPath(Argument::any())->willReturn('/user/1');
50 $result = $router->match('/user/1');
52 $this->assertEquals('user_view', $result['_route']);
54 $current_path_stack->getPath(Argument::any())->willReturn('/user/login');
55 $result = $router->match('/user/login');
57 $this->assertEquals('user_login', $result['_route']);