function WebAssert::pageContainsNoDuplicateId

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::pageContainsNoDuplicateId()
  2. 10 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::pageContainsNoDuplicateId()

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

Throws

\Behat\Mink\Exception\ExpectationException

File

core/tests/Drupal/Tests/WebAssert.php, line 750

Class

WebAssert
Defines a class with methods for asserting presence of elements during tests.

Namespace

Drupal\Tests

Code

public function pageContainsNoDuplicateId() {
    $seen_ids = [];
    foreach ($this->session
        ->getPage()
        ->findAll('xpath', '//*[@id]') as $element) {
        $id = $element->getAttribute('id');
        if (isset($seen_ids[$id])) {
            throw new ExpectationException(sprintf('The page contains a duplicate HTML ID "%s".', $id), $this->session
                ->getDriver());
        }
        $seen_ids[$id] = TRUE;
    }
}

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