function RouteProviderTest::testOutlinePathMatchDefaultsCollision2

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

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

File

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

Class

RouteProviderTest
Confirm that the default route provider is working correctly.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testOutlinePathMatchDefaultsCollision2() : void {
    $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('foo', new Route('/some/path/{value}', [
        'value' => 'foo',
    ]));
    $collection->add('Lassie', new Route('/some/path/here'));
    $collection->add('eep', new Route('/something/completely/different'));
    $dumper = new MatcherDumper($connection, $this->state, $this->logger, '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->assertCount(2, $routes, 'The correct number of routes was found.');
        $this->assertEquals([
            'Lassie',
            'foo',
        ], array_keys($routes_array), 'Ensure the fitness was taken into account.');
        $this->assertNotNull($routes->get('Lassie'), 'The first matching route was found.');
        $this->assertNotNull($routes->get('foo'), '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.');
    }
}

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