function RouteProviderTest::testRouteByName
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testRouteByName()
- 10 core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testRouteByName()
- 11.x core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testRouteByName()
Tests RouteProvider::getRouteByName() & RouteProvider::getRoutesByNames().
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Routing/ RouteProviderTest.php, line 650
Class
- RouteProviderTest
- Confirm that the default route provider is working correctly.
Namespace
Drupal\KernelTests\Core\RoutingCode
public function testRouteByName() {
$connection = Database::getConnection();
$provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');
$this->fixtures
->createTables($connection);
$dumper = new MatcherDumper($connection, $this->state, 'test_routes');
$dumper->addRoutes($this->fixtures
->sampleRouteCollection());
$dumper->dump();
$route = $provider->getRouteByName('route_a');
$this->assertEquals('/path/one', $route->getPath(), 'The right route pattern was found.');
$this->assertEquals([
'GET',
], $route->getMethods(), 'The right route method was found.');
$route = $provider->getRouteByName('route_b');
$this->assertEquals('/path/one', $route->getPath(), 'The right route pattern was found.');
$this->assertEquals([
'PUT',
], $route->getMethods(), 'The right route method was found.');
$exception_thrown = FALSE;
try {
$provider->getRouteByName('invalid_name');
} catch (RouteNotFoundException $e) {
$exception_thrown = TRUE;
}
$this->assertTrue($exception_thrown, 'Random route was not found.');
$routes = $provider->getRoutesByNames([
'route_c',
'route_d',
$this->randomMachineName(),
]);
$this->assertCount(2, $routes, 'Only two valid routes found.');
$this->assertEquals('/path/two', $routes['route_c']->getPath());
$this->assertEquals('/path/three', $routes['route_d']->getPath());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.