public function RouteProviderTest::testRouteByName in Drupal 8
Same name and namespace in other branches
- 9 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()
Test RouteProvider::getRouteByName() and RouteProvider::getRoutesByNames().
File
- core/
tests/ Drupal/ KernelTests/ Core/ Routing/ RouteProviderTest.php, line 616 - Contains \Drupal\KernelTests\Core\Routing\RouteProviderTest.
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
->assertEqual($route
->getPath(), '/path/one', 'The right route pattern was found.');
$this
->assertEqual($route
->getMethods(), [
'GET',
], 'The right route method was found.');
$route = $provider
->getRouteByName('route_b');
$this
->assertEqual($route
->getPath(), '/path/one', 'The right route pattern was found.');
$this
->assertEqual($route
->getMethods(), [
'PUT',
], '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
->assertEqual($routes['route_c']
->getPath(), '/path/two');
$this
->assertEqual($routes['route_d']
->getPath(), '/path/three');
}