function AssertContentTrait::assertLink
Same name in other branches
- 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertLink()
- 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertLink()
- 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertLink()
Passes if a link with the specified label is found.
An optional link index may be passed.
Parameters
string|\Drupal\Component\Render\MarkupInterface $label: Text between the anchor tags.
int $index: Link position counting from zero.
string $message: (optional) A message to display with the assertion. Do not translate messages: use strtr() to embed variables in the message text, not t(). If left blank, a default message will be displayed.
Return value
bool TRUE if the assertion succeeded.
2 calls to AssertContentTrait::assertLink()
- CommentUserNameTest::testUsername in core/
modules/ comment/ tests/ src/ Kernel/ Views/ CommentUserNameTest.php - Tests the username formatter.
- StringFormatterTest::testStringFormatter in core/
modules/ field/ tests/ src/ Kernel/ KernelString/ StringFormatterTest.php - Tests string formatter output.
File
-
core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php, line 283
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\KernelTestsCode
protected function assertLink($label, $index = 0, $message = '') : bool {
// Cast MarkupInterface objects to string.
$label = (string) $label;
$links = $this->xpath('//a[normalize-space(text())=:label]', [
':label' => $label,
]);
$message = $message ? $message : strtr('Link with label %label found.', [
'%label' => $label,
]);
$this->assertArrayHasKey($index, $links, $message);
return TRUE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.