function WebTestBase::assertUrl

Passes if the internal browser's URL matches the given path.

Parameters

\Drupal\Core\Url|string $path: The expected system path or URL.

$options: (optional) Any additional options to pass for $path to the url generator.

$message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Render\FormattableMarkup to embed variables in the message text, not t(). If left blank, a default message will be displayed.

$group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Other'; most tests do not override this default.

Return value

TRUE on pass, FALSE on fail.

File

core/modules/simpletest/src/WebTestBase.php, line 1929

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function assertUrl($path, array $options = [], $message = '', $group = 'Other') {
    if ($path instanceof Url) {
        $url_obj = $path;
    }
    elseif (UrlHelper::isExternal($path)) {
        $url_obj = Url::fromUri($path, $options);
    }
    else {
        $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
        // This is needed for language prefixing.
        $options['path_processing'] = TRUE;
        $url_obj = Url::fromUri($uri, $options);
    }
    $url = $url_obj->setAbsolute()
        ->toString();
    if (!$message) {
        $message = new FormattableMarkup('Expected @url matches current URL (@current_url).', [
            '@url' => var_export($url, TRUE),
            '@current_url' => $this->getUrl(),
        ]);
    }
    // Paths in query strings can be encoded or decoded with no functional
    // difference, decode them for comparison purposes.
    $actual_url = urldecode($this->getUrl());
    $expected_url = urldecode($url);
    return $this->assertEqual($actual_url, $expected_url, $message, $group);
}

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