You are here

public function RouteProviderTest::testGetAllRoutes in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testGetAllRoutes()

Confirms RouteProvider::getAllRoutes() extracts information correctly from the database.

File

core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php, line 299
Contains \Drupal\KernelTests\Core\Routing\RouteProviderTest.

Class

RouteProviderTest
Confirm that the default route provider is working correctly.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testGetAllRoutes() {
  $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();
  $sample_routes = $this->fixtures
    ->staticSampleRouteCollection();
  $returned_routes = $provider
    ->getAllRoutes();
  $this
    ->assertInstanceOf(\Iterator::class, $returned_routes);
  $this
    ->assertSameSize($sample_routes, $returned_routes);
  foreach ($returned_routes as $route_name => $route) {
    $this
      ->assertArrayHasKey($route_name, $sample_routes);
    $this
      ->assertEquals($route
      ->getPath(), $sample_routes[$route_name]['path']);
  }
}