You are here

protected function WebTestBase::buildUrl in Drupal 8

Builds an a absolute URL from a system path or a URL object.

Parameters

string|\Drupal\Core\Url $path: A system path or a URL.

array $options: Options to be passed to Url::fromUri().

Return value

string An absolute URL string.

5 calls to WebTestBase::buildUrl()
RESTTestBase::httpRequest in core/modules/rest/src/Tests/RESTTestBase.php
Helper function to issue a HTTP request with simpletest's cURL.
UITestBase::drupalGet in core/modules/views_ui/src/Tests/UITestBase.php
Retrieves a Drupal path or an absolute path.
WebTestBase::drupalGet in core/modules/simpletest/src/WebTestBase.php
Retrieves a Drupal path or an absolute path.
WebTestBase::drupalHead in core/modules/simpletest/src/WebTestBase.php
Retrieves only the headers for a Drupal path or an absolute path.
WebTestBase::drupalPost in core/modules/simpletest/src/WebTestBase.php
Perform a POST HTTP request.

File

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

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function buildUrl($path, array $options = []) {
  if ($path instanceof Url) {
    $url_options = $path
      ->getOptions();
    $options = $url_options + $options;
    $path
      ->setOptions($options);
    return $path
      ->setAbsolute()
      ->toString(TRUE)
      ->getGeneratedUrl();
  }
  elseif ($this->container
    ->has('url_generator')) {
    $force_internal = isset($options['external']) && $options['external'] == FALSE;
    if (!$force_internal && UrlHelper::isExternal($path)) {
      return Url::fromUri($path, $options)
        ->toString();
    }
    else {
      $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;

      // Path processing is needed for language prefixing.  Skip it when a
      // path that may look like an external URL is being used as internal.
      $options['path_processing'] = !$force_internal;
      return Url::fromUri($uri, $options)
        ->setAbsolute()
        ->toString();
    }
  }
  else {
    return $this
      ->getAbsoluteUrl($path);
  }
}