You are here

protected function DrupalWebTestCase::assertNoDuplicateIds in SimpleTest 7.2

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalWebTestCase::assertNoDuplicateIds()

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

Parameters

$message: Message to display.

$group: The group this message belongs to.

$ids_to_skip: An optional array of ids to skip when checking for duplicates. It is always a bug to have duplicate HTML IDs, so this parameter is to enable incremental fixing of core code. Whenever a test passes this parameter, it should add a "todo" comment above the call to this function explaining the legacy bug that the test wishes to ignore and including a link to an issue that is working to fix that legacy bug.

Return value

TRUE on pass, FALSE on fail.

File

./drupal_web_test_case.php, line 3273
Provides DrupalTestCase, DrupalUnitTestCase, and DrupalWebTestCase classes.

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function assertNoDuplicateIds($message = '', $group = 'Other', $ids_to_skip = array()) {
  $status = TRUE;
  foreach ($this
    ->xpath('//*[@id]') as $element) {
    $id = (string) $element['id'];
    if (isset($seen_ids[$id]) && !in_array($id, $ids_to_skip)) {
      $this
        ->fail(t('The HTML ID %id is unique.', array(
        '%id' => $id,
      )), $group);
      $status = FALSE;
    }
    $seen_ids[$id] = TRUE;
  }
  return $this
    ->assert($status, $message, $group);
}