protected function AssertContentTrait::assertLink in Drupal 9
Same name and namespace in other branches
- 8 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.
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.
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/ String/ StringFormatterTest.php - Tests string formatter output.
File
- core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php, line 296
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\KernelTestsCode
protected function assertLink($label, $index = 0, $message = '', $group = 'Other') {
// 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;
}