function WebAssert::pageContainsNoDuplicateId
Same name in other branches
- 9 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::pageContainsNoDuplicateId()
- 11.x 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 754
Class
- WebAssert
- Defines a class with methods for asserting presence of elements during tests.
Namespace
Drupal\TestsCode
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.