You are here

function CommentTestBase::commentExists in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentTestBase.php \Drupal\comment\Tests\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.

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

... See full list

File

core/modules/comment/src/Tests/CommentTestBase.php, line 192
Contains \Drupal\comment\Tests\CommentTestBase.

Class

CommentTestBase
Provides setup and helper methods for comment tests.

Namespace

Drupal\comment\Tests

Code

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