You are here

function VarnishTestCase::createComment in Varnish 6

Create a comment.

Parameters

array settings add whatever things you want on your comments.: here. You must at least specify a nid.

stdClass comment_user provide a user if you want it to: belong to certain user.

1 call to VarnishTestCase::createComment()
VarnishCacheInvalidationCase::testCommentCacheExpiration in ./varnish.test
Test that makes sure that the comment expiration works as expected.

File

./varnish.test, line 68
Tests the basic functionality of Varnish.

Class

VarnishTestCase
Base class for Varnish Test Cases.

Code

function createComment($settings, $comment_user = NULL) {
  global $user;
  $old_user = $user;
  if (!is_array($settings) && !is_numeric($settings['nid'])) {
    return FALSE;
  }
  if (isset($comment_user)) {
    $user = $comment_user;
  }
  $settings += array(
    'status' => COMMENT_PUBLISHED,
    'uid' => $user->uid,
    'pid' => 0,
    'subject' => $this
      ->randomName(),
    'format' => 1,
    'timestamp' => time(),
    'comment' => $this
      ->randomString(300),
    'cid' => 0,
  );
  $result = comment_save($settings);
  if ($result) {
    $settings['cid'] = $result;
    $result = $settings;
  }
  $user = $old_user;
  return $result;
}