function WebAssert::cleanUrl
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::cleanUrl()
- 10 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::cleanUrl()
- 11.x core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::cleanUrl()
2 calls to WebAssert::cleanUrl()
- WebAssert::addressEquals in core/
tests/ Drupal/ Tests/ WebAssert.php - WebAssert::addressNotEquals in core/
tests/ Drupal/ Tests/ WebAssert.php
File
-
core/
tests/ Drupal/ Tests/ WebAssert.php, line 49
Class
- WebAssert
- Defines a class with methods for asserting presence of elements during tests.
Namespace
Drupal\TestsCode
protected function cleanUrl($url, $include_query = FALSE) {
if ($url instanceof Url) {
$url = $url->setAbsolute()
->toString();
}
// Strip the base URL from the beginning for absolute URLs.
if ($this->baseUrl !== '' && strpos($url, $this->baseUrl) === 0) {
$url = substr($url, strlen($this->baseUrl));
}
$parts = parse_url($url);
// Make sure there is a forward slash at the beginning of relative URLs for
// consistency.
if (empty($parts['host']) && strpos($url, '/') !== 0) {
$parts['path'] = '/' . $parts['path'];
}
$fragment = empty($parts['fragment']) ? '' : '#' . $parts['fragment'];
$path = empty($parts['path']) ? '/' : $parts['path'];
$query = $include_query && !empty($parts['query']) ? '?' . $parts['query'] : '';
return preg_replace('/^\\/[^\\.\\/]+\\.php\\//', '/', $path) . $query . $fragment;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.