You are here

public function WebAssert::pageContainsNoDuplicateId in Drupal 10

Same name and namespace in other branches
  1. 9 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 710

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;
  }
}