You are here

function CommentNonNodeTest::commentExists in Zircon Profile 8

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

1 call to CommentNonNodeTest::commentExists()
CommentNonNodeTest::testCommentFunctionality in core/modules/comment/src/Tests/CommentNonNodeTest.php
Tests anonymous comment functionality.

File

core/modules/comment/src/Tests/CommentNonNodeTest.php, line 187
Contains \Drupal\comment\Tests\CommentNonNodeTest.

Class

CommentNonNodeTest
Tests commenting on a test entity.

Namespace

Drupal\comment\Tests

Code

function commentExists(CommentInterface $comment = NULL, $reply = FALSE) {
  if ($comment) {
    $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
    $regex .= '<a id="comment-' . $comment
      ->id() . '"(.*?)';
    $regex .= $comment
      ->getSubject() . '(.*?)';
    $regex .= $comment->comment_body->value . '(.*?)';
    $regex .= '/s';
    return (bool) preg_match($regex, $this
      ->getRawContent());
  }
  else {
    return FALSE;
  }
}