You are here

protected function CommentThreadingTest::assertParentLink in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/comment/tests/src/Functional/CommentThreadingTest.php \Drupal\Tests\comment\Functional\CommentThreadingTest::assertParentLink()
  2. 9 core/modules/comment/tests/src/Functional/CommentThreadingTest.php \Drupal\Tests\comment\Functional\CommentThreadingTest::assertParentLink()

Asserts that the link to the specified parent comment is present.

@internal

Parameters

int $cid: The comment ID to check.

int $pid: The expected parent comment ID.

File

core/modules/comment/tests/src/Functional/CommentThreadingTest.php, line 137

Class

CommentThreadingTest
Tests to make sure the comment number increments properly.

Namespace

Drupal\Tests\comment\Functional

Code

protected function assertParentLink(int $cid, int $pid) : void {

  // This pattern matches a markup structure like:
  // @code
  // <article id="comment-2">
  //   <p>
  //     In reply to
  //     <a href="...comment-1"></a>
  //   </p>
  // </article>
  // @endcode
  $pattern = "//article[@id='comment-{$cid}']//p/a[contains(@href, 'comment-{$pid}')]";
  $this
    ->assertSession()
    ->elementExists('xpath', $pattern);

  // A parent link is always accompanied by the text "In reply to".
  // If we don't assert this text here, then the assertNoParentLink()
  // method is not effective.
  $pattern = "//article[@id='comment-{$cid}']";
  $this
    ->assertSession()
    ->elementTextContains('xpath', $pattern, 'In reply to');
}