You are here

protected function WebTestBase::buildUrl in SimpleTest 8.3

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.

3 calls to WebTestBase::buildUrl()
WebTestBase::drupalGet in src/WebTestBase.php
Retrieves a Drupal path or an absolute path.
WebTestBase::drupalHead in src/WebTestBase.php
Retrieves only the headers for a Drupal path or an absolute path.
WebTestBase::drupalPost in src/WebTestBase.php
Perform a POST HTTP request.

File

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);
  }
}