function AssertContentTrait::assertNoLink

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertNoLink()
  2. 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertNoLink()
  3. 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertNoLink()

Passes if a link with the specified label is not found.

Parameters

string|\Drupal\Component\Render\MarkupInterface $label: Text between the anchor tags.

string $message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Render\FormattableMarkup 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.

1 call to AssertContentTrait::assertNoLink()
CommentUserNameTest::testUsername in core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
Tests the username formatter.

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 304

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function assertNoLink($label, $message = '') {
    // Cast MarkupInterface objects to string.
    $label = (string) $label;
    $links = $this->xpath('//a[normalize-space(text())=:label]', [
        ':label' => $label,
    ]);
    $message = $message ? $message : new FormattableMarkup('Link with label %label not found.', [
        '%label' => $label,
    ]);
    $this->assertEmpty($links, $message);
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.