You are here

public function RouteProviderTest::testRouteByName in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Routing/RouteProviderTest.php \Drupal\system\Tests\Routing\RouteProviderTest::testRouteByName()

Test RouteProvider::getRouteByName() and RouteProvider::getRoutesByNames().

File

core/modules/system/src/Tests/Routing/RouteProviderTest.php, line 498
Contains \Drupal\system\Tests\Routing\RouteProviderTest.

Class

RouteProviderTest
Confirm that the default route provider is working correctly.

Namespace

Drupal\system\Tests\Routing

Code

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(array(
    'route_c',
    'route_d',
    $this
      ->randomMachineName(),
  ));
  $this
    ->assertEqual(count($routes), 2, 'Only two valid routes found.');
  $this
    ->assertEqual($routes['route_c']
    ->getPath(), '/path/two');
  $this
    ->assertEqual($routes['route_d']
    ->getPath(), '/path/three');
}