diff options
author | David Rothstein <drothstein@gmail.com> | 2015-03-29 16:31:39 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2015-03-29 16:31:39 -0400 |
commit | ab192786436ba867cc84ad4caca26372561845fd (patch) | |
tree | 423ab2a12263818043bca90324263e09e9485eab /modules | |
parent | 26d794fac95c9bfbdffe24cd9028d7e338717159 (diff) | |
download | brdo-ab192786436ba867cc84ad4caca26372561845fd.tar.gz brdo-ab192786436ba867cc84ad4caca26372561845fd.tar.bz2 |
Issue #1461732 by filijonka, Cottser, dcam, marcingy, swentel, udaksh: Fatal error when using the Comment module's "Unpublish comment containing keyword(s)" action
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/comment.module | 7 | ||||
-rw-r--r-- | modules/comment/comment.test | 37 |
2 files changed, 41 insertions, 3 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 2972474c0..6f0df6cae 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -2607,7 +2607,7 @@ function comment_unpublish_action($comment, $context = array()) { /** * Unpublishes a comment if it contains certain keywords. * - * @param $comment + * @param object $comment * Comment object to modify. * @param array $context * Array with components: @@ -2619,10 +2619,13 @@ function comment_unpublish_action($comment, $context = array()) { * @see comment_unpublish_by_keyword_action_submit() */ function comment_unpublish_by_keyword_action($comment, $context) { + $node = node_load($comment->nid); + $build = comment_view($comment, $node); + $text = drupal_render($build); foreach ($context['keywords'] as $keyword) { - $text = drupal_render($comment); if (strpos($text, $keyword) !== FALSE) { $comment->status = COMMENT_NOT_PUBLISHED; + comment_save($comment); watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject)); break; } diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 9e69ba628..dc7aad3e1 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -13,7 +13,7 @@ class CommentHelperCase extends DrupalWebTestCase { function setUp() { parent::setUp('comment', 'search'); // Create users and test node. - $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks')); + $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks', 'administer actions')); $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments')); $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid)); } @@ -1974,6 +1974,41 @@ class CommentActionsTestCase extends CommentHelperCase { } /** + * Tests the unpublish comment by keyword action. + */ + public function testCommentUnpublishByKeyword() { + $this->drupalLogin($this->admin_user); + $callback = 'comment_unpublish_by_keyword_action'; + $hash = drupal_hash_base64($callback); + $comment_text = $keywords = $this->randomName(); + $edit = array( + 'actions_label' => $callback, + 'keywords' => $keywords, + ); + + $this->drupalPost("admin/config/system/actions/configure/$hash", $edit, t('Save')); + + $action = db_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE callback = :callback", array(':callback' => $callback))->fetchObject(); + + $this->assertTrue($action, 'The action could be loaded.'); + + $comment = $this->postComment($this->node, $comment_text, $this->randomName()); + + // Load the full comment so that status is available. + $comment = comment_load($comment->id); + + $this->assertTrue($comment->status == COMMENT_PUBLISHED, 'The comment status was set to published.'); + + comment_unpublish_by_keyword_action($comment, array('keywords' => array($keywords))); + + // We need to make sure that the comment has been saved with status + // unpublished. + $this->assertEqual(comment_load($comment->cid)->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished.'); + $this->assertWatchdogMessage('Unpublished comment %subject.', array('%subject' => $comment->subject), 'Found watchdog message.'); + $this->clearWatchdog(); + } + + /** * Verify that a watchdog message has been entered. * * @param $watchdog_message |