function HtmlTest::providerTestTransformRootRelativeUrlsToAbsolute
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::providerTestTransformRootRelativeUrlsToAbsolute()
- 10 core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::providerTestTransformRootRelativeUrlsToAbsolute()
- 11.x core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::providerTestTransformRootRelativeUrlsToAbsolute()
Provides test data for testTransformRootRelativeUrlsToAbsolute().
Return value
array Test data.
File
-
core/
tests/ Drupal/ Tests/ Component/ Utility/ HtmlTest.php, line 356
Class
Namespace
Drupal\Tests\Component\UtilityCode
public function providerTestTransformRootRelativeUrlsToAbsolute() {
$data = [];
// Random generator.
$random = new Random();
// One random tag name.
$tag_name = strtolower($random->name(8, TRUE));
// A site installed either in the root of a domain or a subdirectory.
$base_paths = [
'/',
'/subdir/' . $random->name(8, TRUE) . '/',
];
foreach ($base_paths as $base_path) {
// The only attribute that has more than just a URL as its value, is
// 'srcset', so special-case it.
$data += [
"{$tag_name}, srcset, {$base_path}: root-relative" => [
"<{$tag_name} srcset=\"http://example.com{$base_path}already-absolute 200w, {$base_path}root-relative 300w\">root-relative test</{$tag_name}>",
'http://example.com',
"<{$tag_name} srcset=\"http://example.com{$base_path}already-absolute 200w, http://example.com{$base_path}root-relative 300w\">root-relative test</{$tag_name}>",
],
"{$tag_name}, srcset, {$base_path}: protocol-relative" => [
"<{$tag_name} srcset=\"http://example.com{$base_path}already-absolute 200w, //example.com{$base_path}protocol-relative 300w\">protocol-relative test</{$tag_name}>",
'http://example.com',
FALSE,
],
"{$tag_name}, srcset, {$base_path}: absolute" => [
"<{$tag_name} srcset=\"http://example.com{$base_path}already-absolute 200w, http://example.com{$base_path}absolute 300w\">absolute test</{$tag_name}>",
'http://example.com',
FALSE,
],
];
foreach ([
'href',
'poster',
'src',
'cite',
'data',
'action',
'formaction',
'about',
] as $attribute) {
$data += [
"{$tag_name}, {$attribute}, {$base_path}: root-relative" => [
"<{$tag_name} {$attribute}=\"{$base_path}root-relative\">root-relative test</{$tag_name}>",
'http://example.com',
"<{$tag_name} {$attribute}=\"http://example.com{$base_path}root-relative\">root-relative test</{$tag_name}>",
],
"{$tag_name}, {$attribute}, {$base_path}: protocol-relative" => [
"<{$tag_name} {$attribute}=\"//example.com{$base_path}protocol-relative\">protocol-relative test</{$tag_name}>",
'http://example.com',
FALSE,
],
"{$tag_name}, {$attribute}, {$base_path}: absolute" => [
"<{$tag_name} {$attribute}=\"http://example.com{$base_path}absolute\">absolute test</{$tag_name}>",
'http://example.com',
FALSE,
],
];
}
}
return $data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.