function CommentActionsTest::testCommentUnpublishByKeyword

Tests the unpublish comment by keyword action.

File

drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php, line 53
Definition of Drupal\comment\Tests\CommentActionsTest.

Class

CommentActionsTest
Tests actions provided by the Comment module.

Namespace

Drupal\comment\Tests

Code

function testCommentUnpublishByKeyword() {
  $this
    ->drupalLogin($this->admin_user);
  $keyword_1 = $this
    ->randomName();
  $keyword_2 = $this
    ->randomName();
  $action = entity_create('action', array(
    'id' => 'comment_unpublish_by_keyword_action',
    'label' => $this
      ->randomName(),
    'type' => 'comment',
    'configuration' => array(
      'keywords' => array(
        $keyword_1,
        $keyword_2,
      ),
    ),
    'plugin' => 'comment_unpublish_by_keyword_action',
  ));
  $action
    ->save();
  $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.');
  $action
    ->execute(array(
    $comment,
  ));
  $this
    ->assertTrue($comment->status->value == COMMENT_NOT_PUBLISHED, 'The comment status was set to not published.');
}