Loading modules/comment/comment.module +3 −0 Changes for modules/comment/comment.module: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1591,6 +1591,9 @@ function comment_save($comment) { if ($comment->status == COMMENT_PUBLISHED) { module_invoke_all('comment_publish', $comment); } elseif ($comment->status == COMMENT_NOT_PUBLISHED) { module_invoke_all('comment_unpublish', $comment); } unset($comment->original); } catch (Exception $e) { Loading modules/comment/comment.test +52 −0 Changes for modules/comment/comment.test: 52 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2028,6 +2028,37 @@ class CommentActionsTestCase extends CommentHelperCase { $this->clearWatchdog(); } /** * Test comment publish and unpublish hooks. */ 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'); } /** * Verify that a watchdog message has been entered. * Loading @@ -2049,6 +2080,27 @@ class CommentActionsTestCase extends CommentHelperCase { function clearWatchdog() { db_truncate('watchdog')->execute(); } /** * Pass if the message $text was set by one of the comment hooks in * comment_hook_test.module, i.e., if the $text is an element of * $_SESSION['comment_hook_test']. * * @param $text * Plain text to look for. * @param $message * Message to display. * @param $group * The group this message belongs to, defaults to 'Other'. * @return * TRUE on pass, FALSE on fail. */ protected function assertHookMessage($text, $message = NULL, $group = 'Other') { if (!isset($message)) { $message = $text; } return $this->assertTrue(array_search($text, $_SESSION['comment_hook_test']) !== FALSE, $message, $group); } } /** Loading modules/comment/tests/comment_hook_test.info 0 → 100644 +6 −0 Changes for modules/comment/tests/comment_hook_test.info: 6 added lines, 0 removed lines. Original line number Diff line number Diff line name = "Comment Hooks Test" description = "Support module for comment hook tests." core = 7.x package = Testing version = VERSION hidden = TRUE modules/comment/tests/comment_hook_test.module 0 → 100644 +20 −0 Changes for modules/comment/tests/comment_hook_test.module: 20 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Test module for the comment hooks testing. */ /** * Implements hook_comment_publish(). */ function comment_hook_test_comment_publish($comment) { $_SESSION['comment_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_comment_unpublish(). */ function comment_hook_test_comment_unpublish($comment) { $_SESSION['comment_hook_test'][] = (__FUNCTION__ . ' called'); } Loading
modules/comment/comment.module +3 −0 Changes for modules/comment/comment.module: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1591,6 +1591,9 @@ function comment_save($comment) { if ($comment->status == COMMENT_PUBLISHED) { module_invoke_all('comment_publish', $comment); } elseif ($comment->status == COMMENT_NOT_PUBLISHED) { module_invoke_all('comment_unpublish', $comment); } unset($comment->original); } catch (Exception $e) { Loading
modules/comment/comment.test +52 −0 Changes for modules/comment/comment.test: 52 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2028,6 +2028,37 @@ class CommentActionsTestCase extends CommentHelperCase { $this->clearWatchdog(); } /** * Test comment publish and unpublish hooks. */ 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'); } /** * Verify that a watchdog message has been entered. * Loading @@ -2049,6 +2080,27 @@ class CommentActionsTestCase extends CommentHelperCase { function clearWatchdog() { db_truncate('watchdog')->execute(); } /** * Pass if the message $text was set by one of the comment hooks in * comment_hook_test.module, i.e., if the $text is an element of * $_SESSION['comment_hook_test']. * * @param $text * Plain text to look for. * @param $message * Message to display. * @param $group * The group this message belongs to, defaults to 'Other'. * @return * TRUE on pass, FALSE on fail. */ protected function assertHookMessage($text, $message = NULL, $group = 'Other') { if (!isset($message)) { $message = $text; } return $this->assertTrue(array_search($text, $_SESSION['comment_hook_test']) !== FALSE, $message, $group); } } /** Loading
modules/comment/tests/comment_hook_test.info 0 → 100644 +6 −0 Changes for modules/comment/tests/comment_hook_test.info: 6 added lines, 0 removed lines. Original line number Diff line number Diff line name = "Comment Hooks Test" description = "Support module for comment hook tests." core = 7.x package = Testing version = VERSION hidden = TRUE
modules/comment/tests/comment_hook_test.module 0 → 100644 +20 −0 Changes for modules/comment/tests/comment_hook_test.module: 20 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Test module for the comment hooks testing. */ /** * Implements hook_comment_publish(). */ function comment_hook_test_comment_publish($comment) { $_SESSION['comment_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_comment_unpublish(). */ function comment_hook_test_comment_unpublish($comment) { $_SESSION['comment_hook_test'][] = (__FUNCTION__ . ' called'); }