function UrlTest::testFromUserInput

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

Tests the fromUserInput method with valid paths.

@covers ::fromUserInput @dataProvider providerFromValidInternalUri

File

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

Class

UrlTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Url.php/class/Url/9" title="Defines an object that holds information about a URL." class="local">\Drupal\Core\Url</a> @group UrlTest

Namespace

Drupal\Tests\Core

Code

public function testFromUserInput($path) {
    $url = Url::fromUserInput($path);
    $uri = $url->getUri();
    $this->assertInstanceOf('Drupal\\Core\\Url', $url);
    $this->assertFalse($url->isRouted());
    $this->assertStringStartsWith('base:', $uri);
    $parts = UrlHelper::parse($path);
    $options = $url->getOptions();
    if (!empty($parts['fragment'])) {
        $this->assertSame($parts['fragment'], $options['fragment']);
    }
    else {
        $this->assertArrayNotHasKey('fragment', $options);
    }
    if (!empty($parts['query'])) {
        $this->assertEquals($parts['query'], $options['query']);
    }
    else {
        $this->assertArrayNotHasKey('query', $options);
    }
}

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