function RouterTest::testDuplicateRoutePaths

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testDuplicateRoutePaths()
  2. 8.9.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testDuplicateRoutePaths()
  3. 11.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testDuplicateRoutePaths()

Confirms that multiple routes with the same path do not cause an error.

File

core/modules/system/tests/src/Functional/Routing/RouterTest.php, line 123

Class

RouterTest
Functional class for the full integrated routing system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testDuplicateRoutePaths() : void {
    // Tests two routes with exactly the same path. The route with the maximum
    // fit and lowest sorting route name will match, regardless of the order the
    // routes are declared.
    // @see \Drupal\Core\Routing\RouteProvider::getRoutesByPath()
    $this->drupalGet('router-test/duplicate-path2');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains('router_test.two_duplicate1');
    // Tests three routes with same the path. One of the routes the path has a
    // different case.
    $this->drupalGet('router-test/case-sensitive-duplicate-path3');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains('router_test.case_sensitive_duplicate1');
    // While case-insensitive matching works, exact matches are preferred.
    $this->drupalGet('router-test/case-sensitive-Duplicate-PATH3');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains('router_test.case_sensitive_duplicate2');
    // Test that case-insensitive matching works, falling back to the first
    // route defined.
    $this->drupalGet('router-test/case-sensitive-Duplicate-Path3');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains('router_test.case_sensitive_duplicate1');
}

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