You are here

function RouteProviderTest::testOutlinePathMatch 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::testOutlinePathMatch()

Confirms that we can find routes whose pattern would match the request.

File

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

Class

RouteProviderTest
Confirm that the default route provider is working correctly.

Namespace

Drupal\system\Tests\Routing

Code

function testOutlinePathMatch() {
  $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
    ->complexRouteCollection());
  $dumper
    ->dump();
  $path = '/path/1/one';
  $request = Request::create($path, 'GET');
  $routes = $provider
    ->getRouteCollectionForRequest($request);

  // All of the matching paths have the correct pattern.
  foreach ($routes as $route) {
    $this
      ->assertEqual($route
      ->compile()
      ->getPatternOutline(), '/path/%/one', 'Found path has correct pattern');
  }
  $this
    ->assertEqual(count($routes), 2, 'The correct number of routes was found.');
  $this
    ->assertNotNull($routes
    ->get('route_a'), 'The first matching route was found.');
  $this
    ->assertNotNull($routes
    ->get('route_b'), 'The second matching route was not found.');
}