You are here

protected function BrowserTestBase::getAbsoluteUrl in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/BrowserTestBase.php \Drupal\simpletest\BrowserTestBase::getAbsoluteUrl()

Takes a path and returns an absolute path.

Parameters

string $path: A path from the Mink controlled browser content.

Return value

string The $path with $base_url prepended, if necessary.

1 call to BrowserTestBase::getAbsoluteUrl()
BrowserTestBase::drupalGet in core/modules/simpletest/src/BrowserTestBase.php
Retrieves a Drupal path or an absolute path.

File

core/modules/simpletest/src/BrowserTestBase.php, line 505
Contains \Drupal\simpletest\BrowserTestBase.

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\simpletest

Code

protected function getAbsoluteUrl($path) {
  global $base_url, $base_path;
  $parts = parse_url($path);
  if (empty($parts['host'])) {

    // Ensure that we have a string (and no xpath object).
    $path = (string) $path;

    // Strip $base_path, if existent.
    $length = strlen($base_path);
    if (substr($path, 0, $length) === $base_path) {
      $path = substr($path, $length);
    }

    // Ensure that we have an absolute path.
    if (empty($path) || $path[0] !== '/') {
      $path = '/' . $path;
    }

    // Finally, prepend the $base_url.
    $path = $base_url . $path;
  }
  return $path;
}