protected function RouteProviderTest::testRouteByName

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

File

drupal/core/modules/system/lib/Drupal/system/Tests/Routing/RouteProviderTest.php, line 361
Contains Drupal\system\Tests\Routing\RouteProviderTest.

Class

RouteProviderTest
Basic tests for the RouteProvider.

Namespace

Drupal\system\Tests\Routing

Code

protected function testRouteByName() {
  $connection = Database::getConnection();
  $provider = new RouteProvider($connection, 'test_routes');
  $this->fixtures
    ->createTables($connection);
  $dumper = new MatcherDumper($connection, 'test_routes');
  $dumper
    ->addRoutes($this->fixtures
    ->sampleRouteCollection());
  $dumper
    ->dump();
  $route = $provider
    ->getRouteByName('route_a');
  $this
    ->assertEqual($route
    ->getPattern(), '/path/one', 'The right route pattern was found.');
  $this
    ->assertEqual($route
    ->getRequirement('_method'), 'GET', 'The right route method was found.');
  $route = $provider
    ->getRouteByName('route_b');
  $this
    ->assertEqual($route
    ->getPattern(), '/path/one', 'The right route pattern was found.');
  $this
    ->assertEqual($route
    ->getRequirement('_method'), '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
      ->randomName(),
  ));
  $this
    ->assertEqual(count($routes), 2, 'Only two valid routes found.');
  $this
    ->assertEqual($routes['route_c']
    ->getPattern(), '/path/two');
  $this
    ->assertEqual($routes['route_d']
    ->getPattern(), '/path/three');
}