function CommentActionsTestCase::testCommentPublishUnpublishHooks
Test comment publish and unpublish hooks.
File
-
modules/
comment/ comment.test, line 2034
Class
- CommentActionsTestCase
- Test actions provided by the comment module.
Code
function testCommentPublishUnpublishHooks() {
$this->drupalLogin($this->web_user);
module_enable(array(
'comment_hook_test',
));
$_SESSION['comment_hook_test'] = array();
// Publishing a comment should trigger hook_comment_publish().
$comment = (object) array(
'cid' => NULL,
'nid' => $this->node->nid,
'node_type' => $this->node->type,
'pid' => 0,
'uid' => $this->loggedInUser->uid,
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => ip_address(),
'language' => LANGUAGE_NONE,
'comment_body' => array(
LANGUAGE_NONE => array(
$this->randomName(),
),
),
);
comment_save($comment);
$this->assertHookMessage('comment_hook_test_comment_publish called');
// Unpublishing a comment should trigger hook_comment_unpublish().
$comment = comment_load($comment->cid);
$comment->status = COMMENT_NOT_PUBLISHED;
comment_save($comment);
$this->assertHookMessage('comment_hook_test_comment_unpublish called');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.