You are here

function CommentNotifyTestCase::postCommentNotifyComment in Comment Notify 7

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

Post comment.

Parameters

object $node: Node to post comment on.

string $subject: Comment subject.

string $comment: Comment body.

bool $preview: Should preview be required.

mixed $contact: Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.

1 call to CommentNotifyTestCase::postCommentNotifyComment()
CommentNotifyTestCase::testCommentNotifyAnonymousUserFunctionalTest in ./comment_notify.test
Test various behaviors for anonymous users.

File

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

Class

CommentNotifyTestCase
@file Creates tests for comment_notify module.

Code

function postCommentNotifyComment($node, $subject, $comment, $notify, $contact = NULL) {
  $langcode = LANGUAGE_NONE;
  $edit = array();
  $edit['subject'] = $subject;
  $edit['comment_body[' . $langcode . '][0][value]'] = $comment;
  if ($notify !== NULL && is_array($notify)) {
    $edit += $notify;
  }
  if ($contact !== NULL && is_array($contact)) {
    $edit += $contact;
  }
  $this
    ->drupalPost('node/' . $node->nid, $edit, t('Save'));
  $match = array();

  // Get comment ID.
  preg_match('/#comment-([^"]+)/', $this
    ->getURL(), $match);

  // Get comment.
  if (!empty($match[1])) {

    // If true then attempting to find error message.
    if ($subject) {
      $this
        ->assertText($subject, 'Comment subject posted.');
    }
    $this
      ->assertText($comment, 'Comment body posted.');
    $this
      ->assertTrue(!empty($match) && !empty($match[1]), t('Comment id found.'));
  }
  if (isset($match[1])) {
    return array(
      'id' => $match[1],
      'subject' => $subject,
      'comment' => $comment,
    );
  }
}