function UrlTest::testFromRoutedPathWithInvalidRoute

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testFromRoutedPathWithInvalidRoute()
  2. 8.9.x core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testFromRoutedPathWithInvalidRoute()
  3. 10 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testFromRoutedPathWithInvalidRoute()

Tests fromUri() method with a user-entered path not matching any route.

@covers ::fromUri

File

core/tests/Drupal/Tests/Core/UrlTest.php, line 204

Class

UrlTest
@coversDefaultClass \Drupal\Core\Url @group UrlTest

Namespace

Drupal\Tests\Core

Code

public function testFromRoutedPathWithInvalidRoute() : void {
    $this->pathValidator
        ->expects($this->once())
        ->method('getUrlIfValidWithoutAccessCheck')
        ->with('invalid-path')
        ->willReturn(FALSE);
    $url = Url::fromUri('internal:/invalid-path');
    $this->assertFalse($url->isRouted());
    $this->assertSame('base:invalid-path', $url->getUri());
}

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