function CommentNonNodeTest::commentExists

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\CommentNonNodeTest::commentExists()
  2. 10 core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\CommentNonNodeTest::commentExists()
  3. 11.x core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\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/tests/src/Functional/CommentNonNodeTest.php
Tests anonymous comment functionality.

File

core/modules/comment/tests/src/Functional/CommentNonNodeTest.php, line 198

Class

CommentNonNodeTest
Tests commenting on a test entity.

Namespace

Drupal\Tests\comment\Functional

Code

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

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