You are here

public function CommentTestBase::commentExists in Drupal 9

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

Checks current page for specified comment.

Parameters

\Drupal\comment\CommentInterface $comment: The comment object.

bool $reply: Boolean indicating whether the comment is a reply to another comment.

Return value

bool Boolean indicating whether the comment was found.

11 calls to CommentTestBase::commentExists()
CommentAdminTest::testApprovalAdminInterface in core/modules/comment/tests/src/Functional/CommentAdminTest.php
Tests comment approval functionality through admin/content/comment.
CommentAdminTest::testApprovalAdminInterface in core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php
Tests comment approval functionality through admin/content/comment.
CommentAdminTest::testApprovalNodeInterface in core/modules/comment/tests/src/Functional/CommentAdminTest.php
Tests comment approval functionality through the node interface.
CommentAnonymousTest::testAnonymous in core/modules/comment/tests/src/Functional/CommentAnonymousTest.php
Tests anonymous comment functionality.
CommentInterfaceTest::testAutoFilledSubject in core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
Tests that the subject is automatically filled if disabled or left blank.

... See full list

File

core/modules/comment/tests/src/Functional/CommentTestBase.php, line 199

Class

CommentTestBase
Provides setup and helper methods for comment tests.

Namespace

Drupal\Tests\comment\Functional

Code

public function commentExists(CommentInterface $comment = NULL, $reply = FALSE) {
  if ($comment) {
    $comment_element = $this
      ->cssSelect('.comment-wrapper ' . ($reply ? '.indented ' : '') . 'article#comment-' . $comment
      ->id());
    if (empty($comment_element)) {
      return FALSE;
    }
    $comment_title = $comment_element[0]
      ->find('xpath', 'div/h3/a');
    if (empty($comment_title) || $comment_title
      ->getText() !== $comment
      ->getSubject()) {
      return FALSE;
    }
    $comment_body = $comment_element[0]
      ->find('xpath', 'div/div/p');
    if (empty($comment_body) || $comment_body
      ->getText() !== $comment->comment_body->value) {
      return FALSE;
    }
    return TRUE;
  }
  else {
    return FALSE;
  }
}