You are here

public function CurrentRouteMatchTest::testGetRouteMatchFromRequest in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php \Drupal\Tests\Core\Routing\CurrentRouteMatchTest::testGetRouteMatchFromRequest()
  2. 10 core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php \Drupal\Tests\Core\Routing\CurrentRouteMatchTest::testGetRouteMatchFromRequest()

@covers ::getRouteMatchFromRequest

File

core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php, line 92

Class

CurrentRouteMatchTest
@coversDefaultClass \Drupal\Core\Routing\CurrentRouteMatch @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testGetRouteMatchFromRequest() {
  $request_stack = new RequestStack();
  $request = new Request();
  $request_stack
    ->push($request);
  $route = new Route('/test-route/{foo}');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_OBJECT, $route);
  $request->attributes
    ->set('foo', '1');
  $current_route_match = new CurrentRouteMatch($request_stack);
  $route_match = $current_route_match
    ->getRouteMatchFromRequest($request);
  $this
    ->assertEquals('test_route', $route_match
    ->getRouteName());
  $this
    ->assertEquals($route, $route_match
    ->getRouteObject());
}