You are here

function RouteProviderTest::testOutlinePathMatchDefaultsCollision2 in Zircon Profile 8

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

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

File

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

Class

RouteProviderTest
Confirm that the default route provider is working correctly.

Namespace

Drupal\system\Tests\Routing

Code

function testOutlinePathMatchDefaultsCollision2() {
  $connection = Database::getConnection();
  $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');
  $this->fixtures
    ->createTables($connection);
  $collection = new RouteCollection();
  $collection
    ->add('poink', new Route('/some/path/{value}', array(
    'value' => 'poink',
  )));
  $collection
    ->add('narf', new Route('/some/path/here'));
  $collection
    ->add('eep', new Route('/something/completely/different'));
  $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
  $dumper
    ->addRoutes($collection);
  $dumper
    ->dump();
  $path = '/some/path/here';
  $request = Request::create($path, 'GET');
  try {
    $routes = $provider
      ->getRouteCollectionForRequest($request);
    $routes_array = $routes
      ->all();
    $this
      ->assertEqual(count($routes), 2, 'The correct number of routes was found.');
    $this
      ->assertEqual(array(
      'narf',
      'poink',
    ), array_keys($routes_array), 'Ensure the fitness was taken into account.');
    $this
      ->assertNotNull($routes
      ->get('narf'), 'The first matching route was found.');
    $this
      ->assertNotNull($routes
      ->get('poink'), 'The second matching route was found.');
    $this
      ->assertNull($routes
      ->get('eep'), 'Non-matching route was not found.');
  } catch (ResourceNotFoundException $e) {
    $this
      ->fail('No matching route found with default argument value.');
  }
}