Commit 06449a5a authored by catch's avatar catch

Issue #1461732 by filijonka, marcingy, Cottser, udaksh, swentel: Fixed PHP...

Issue #1461732 by filijonka, marcingy, Cottser, udaksh, swentel: Fixed PHP error while publishing comment.
parent 716c5abe
......@@ -1944,8 +1944,9 @@ function comment_unpublish_action(Comment $comment = NULL, $context = array()) {
* @see comment_unpublish_by_keyword_action_submit()
*/
function comment_unpublish_by_keyword_action(Comment $comment, $context) {
$build = comment_view($comment);
$text = drupal_render($build);
foreach ($context['keywords'] as $keyword) {
$text = drupal_render($comment);
if (strpos($text, $keyword) !== FALSE) {
$comment->status->value = COMMENT_NOT_PUBLISHED;
watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject->value));
......
......@@ -17,7 +17,7 @@ class CommentActionsTest extends CommentTestBase {
*
* @var array
*/
public static $modules = array('dblog');
public static $modules = array('dblog', 'action');
public static function getInfo() {
return array(
......@@ -60,6 +60,28 @@ function testCommentPublishUnpublishActions() {
$this->clearWatchdog();
}
/**
* Tests the unpublish comment by keyword action.
*/
function testCommentUnpublishByKeyword() {
$this->drupalLogin($this->admin_user);
$keyword_1 = $this->randomName();
$keyword_2 = $this->randomName();
$aid = action_save('comment_unpublish_by_keyword_action', 'comment', array('keywords' => array($keyword_1, $keyword_2)), $this->randomName());
$this->assertTrue(action_load($aid), 'The action could be loaded.');
$comment = $this->postComment($this->node, $keyword_2, $this->randomName());
// Load the full comment so that status is available.
$comment = comment_load($comment->id());
$this->assertTrue($comment->status->value == COMMENT_PUBLISHED, 'The comment status was set to published.');
actions_do($aid, $comment, array());
$this->assertTrue($comment->status->value == COMMENT_NOT_PUBLISHED, 'The comment status was set to not published.');
}
/**
* Verifies that a watchdog message has been entered.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment