function CurrentRouteMatchTest::testResetRouteMatch
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php \Drupal\Tests\Core\Routing\CurrentRouteMatchTest::testResetRouteMatch()
- 8.9.x core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php \Drupal\Tests\Core\Routing\CurrentRouteMatchTest::testResetRouteMatch()
- 10 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 115
Class
- CurrentRouteMatchTest
- @coversDefaultClass \Drupal\Core\Routing\CurrentRouteMatch @group Routing
Namespace
Drupal\Tests\Core\RoutingCode
public function testResetRouteMatch() : void {
$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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.