function HtmlTest::testHtmlGetUniqueIdWithAjaxIds

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::testHtmlGetUniqueIdWithAjaxIds()
  2. 10 core/tests/Drupal/Tests/Component/Utility/HtmlTest.php \Drupal\Tests\Component\Utility\HtmlTest::testHtmlGetUniqueIdWithAjaxIds()
  3. 11.x 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

HtmlTest
Tests \Drupal\Component\Utility\Html.

Namespace

Drupal\Tests\Component\Utility

Code

public function testHtmlGetUniqueIdWithAjaxIds($expected, $source) {
    Html::setIsAjax(TRUE);
    $id = Html::getUniqueId($source);
    // Note, we truncate two hyphens at the end.
    // @see \Drupal\Component\Utility\Html::getId()
    if (strpos($source, '--') !== FALSE) {
        $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.