function FileFieldDisplayTest::assertNoDuplicateIds

Asserts that each HTML ID is used for just a single element on the page.

Parameters

string $message: (optional) A message to display with the assertion.

1 call to FileFieldDisplayTest::assertNoDuplicateIds()
FileFieldDisplayTest::testNodeDisplay in core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
Tests normal formatter display on node display.

File

core/modules/file/tests/src/Functional/FileFieldDisplayTest.php, line 238

Class

FileFieldDisplayTest
Tests the display of file fields in node and views.

Namespace

Drupal\Tests\file\Functional

Code

protected function assertNoDuplicateIds($message = '') {
    $args = [
        '@url' => $this->getUrl(),
    ];
    if (!($elements = $this->xpath('//*[@id]'))) {
        $this->fail(new FormattableMarkup('The page @url contains no HTML IDs.', $args));
        return;
    }
    $message = $message ?: new FormattableMarkup('The page @url does not contain duplicate HTML IDs', $args);
    $seen_ids = [];
    foreach ($elements as $element) {
        $id = $element->getAttribute('id');
        if (isset($seen_ids[$id])) {
            $this->fail($message);
            return;
        }
        $seen_ids[$id] = TRUE;
    }
    $this->assertTrue(TRUE, $message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.