You are here

function CommentNotifyTestCase::commentExists in Comment Notify 7

Same name and namespace in other branches
  1. 6 comment_notify.test \CommentNotifyTestCase::commentExists()

Checks current page for specified comment.

Parameters

object $comment: Comment object.

bool $reply: The comment is a reply to another comment.

Return value

bool Comment found.

File

./comment_notify.test, line 181
Creates tests for comment_notify module.

Class

CommentNotifyTestCase
@file Creates tests for comment_notify module.

Code

function commentExists($comment, $reply = FALSE) {
  if ($comment && is_object($comment)) {
    $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');

    // Comment anchor.
    $regex .= '<a id="comment-' . $comment->id . '"(.*?)';

    // Begin in comment div.
    $regex .= '<div(.*?)';

    // Match subject.
    $regex .= $comment->subject . '(.*?)';

    // Match comment.
    $regex .= $comment->comment . '(.*?)';

    // Dot matches newlines and ensure that match doesn't bleed outside
    // comment div.
    $regex .= '<\\/div>/s';
    return (bool) preg_match($regex, $this
      ->drupalGetContent());
  }
  else {
    return FALSE;
  }
}