You are here

public function CurrentRouteMatchTest::testResetRouteMatch in Drupal 10

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

@covers ::resetRouteMatch

File

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

Class

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

Namespace

Drupal\Tests\Core\Routing

Code

public function testResetRouteMatch() {
  $route = new Route('/test-route/{foo}');
  $request = new Request();
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_OBJECT, $route);
  $request_stack = new RequestStack();
  $request_stack
    ->push($request);
  $current_route_match = new CurrentRouteMatch($request_stack);
  $route_name = $current_route_match
    ->getRouteName();
  $this
    ->assertSame('test_route', $route_name);

  // Replace the matched route on the request.
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_NAME, NULL);
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_OBJECT, NULL);

  // Reset the route match.
  $current_route_match
    ->resetRouteMatch();
  $route_name = $current_route_match
    ->getRouteName();
  $this
    ->assertNull($route_name);
}