function RouteProviderTest::testOutlinePathMatchDefaultsCollision

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testOutlinePathMatchDefaultsCollision()
  2. 10 core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testOutlinePathMatchDefaultsCollision()
  3. 11.x core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php \Drupal\KernelTests\Core\Routing\RouteProviderTest::testOutlinePathMatchDefaultsCollision()

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

File

core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php, line 364

Class

RouteProviderTest
Confirm that the default route provider is working correctly.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testOutlinePathMatchDefaultsCollision() {
    $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}', [
        'value' => 'poink',
    ]));
    $collection->add('narf', new Route('/some/path/here'));
    $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
    $dumper->addRoutes($collection);
    $dumper->dump();
    $path = '/some/path';
    $request = Request::create($path, 'GET');
    try {
        $routes = $provider->getRouteCollectionForRequest($request);
        // All of the matching paths have the correct pattern.
        foreach ($routes as $route) {
            $this->assertEqual($route->compile()
                ->getPatternOutline(), '/some/path', 'Found path has correct pattern');
        }
        $this->assertCount(1, $routes, 'The correct number of routes was found.');
        $this->assertNotNull($routes->get('poink'), 'The first matching route was found.');
    } catch (ResourceNotFoundException $e) {
        $this->fail('No matching route found with default argument value.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.