You are here

function CommentActionsTest::testCommentUnpublishByKeyword in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentActionsTest.php \Drupal\comment\Tests\CommentActionsTest::testCommentUnpublishByKeyword()

Tests the unpublish comment by keyword action.

File

core/modules/comment/src/Tests/CommentActionsTest.php, line 49
Contains \Drupal\comment\Tests\CommentActionsTest.

Class

CommentActionsTest
Tests actions provided by the Comment module.

Namespace

Drupal\comment\Tests

Code

function testCommentUnpublishByKeyword() {
  $this
    ->drupalLogin($this->adminUser);
  $keyword_1 = $this
    ->randomMachineName();
  $keyword_2 = $this
    ->randomMachineName();
  $action = entity_create('action', array(
    'id' => 'comment_unpublish_by_keyword_action',
    'label' => $this
      ->randomMachineName(),
    '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
    ->randomMachineName());

  // Load the full comment so that status is available.
  $comment = Comment::load($comment
    ->id());
  $this
    ->assertTrue($comment
    ->isPublished() === TRUE, 'The comment status was set to published.');
  $action
    ->execute(array(
    $comment,
  ));
  $this
    ->assertTrue($comment
    ->isPublished() === FALSE, 'The comment status was set to not published.');
}