function HtmlTest::testHtmlGetUniqueIdWithAjaxIds
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::testHtmlGetUniqueIdWithAjaxIds()
- 8.9.x core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::testHtmlGetUniqueIdWithAjaxIds()
- 10 core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::testHtmlGetUniqueIdWithAjaxIds()
Tests the Html::getUniqueId() method.
@dataProvider providerTestHtmlGetUniqueIdWithAjaxIds
@covers ::getUniqueId
Parameters
string $expected: The expected result.
string $source: The string being transformed to an ID.
File
-
core/
tests/ Drupal/ Tests/ Component/ Utility/ HtmlTest.php, line 162
Class
Namespace
Drupal\Tests\Component\UtilityCode
public function testHtmlGetUniqueIdWithAjaxIds($expected, $source) : void {
Html::setIsAjax(TRUE);
$id = Html::getUniqueId($source);
// Note, we truncate two hyphens at the end.
// @see \Drupal\Component\Utility\Html::getId()
if (str_contains($source, '--')) {
$random_suffix = substr($id, strlen($source) + 1);
}
else {
$random_suffix = substr($id, strlen($source) + 2);
}
$expected = $expected . $random_suffix;
$this->assertSame($expected, $id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.