protected function AssertContentTrait::assertNoDuplicateIds in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/AssertContentTrait.php \Drupal\simpletest\AssertContentTrait::assertNoDuplicateIds()
Asserts that each HTML ID is used for just a single element.
Parameters
string $message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed variables in the message text, not t(). If left blank, a default message will be displayed.
string $group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Other'; most tests do not override this default.
array $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
bool TRUE on pass, FALSE on fail.
1 call to AssertContentTrait::assertNoDuplicateIds()
- MultiFormTest::testMultiForm in core/
modules/ system/ src/ Tests/ Ajax/ MultiFormTest.php - Tests that pages with the 'node_page_form' included twice work correctly.
File
- core/
modules/ simpletest/ src/ AssertContentTrait.php, line 1454 - Contains \Drupal\simpletest\AssertContentTrait.
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\simpletestCode
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(SafeMarkup::format('The HTML ID %id is unique.', array(
'%id' => $id,
)), $group);
$status = FALSE;
}
$seen_ids[$id] = TRUE;
}
return $this
->assert($status, $message, $group);
}