You are here

public function CommentActionsTest::testCommentUnpublishByKeyword in Drupal 8

Tests the unpublish comment by keyword action.

File

core/modules/comment/tests/src/Functional/CommentActionsTest.php, line 50

Class

CommentActionsTest
Tests actions provided by the Comment module.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCommentUnpublishByKeyword() {
  $this
    ->drupalLogin($this->adminUser);
  $keyword_1 = $this
    ->randomMachineName();
  $keyword_2 = $this
    ->randomMachineName();
  $action = Action::create([
    'id' => 'comment_unpublish_by_keyword_action',
    'label' => $this
      ->randomMachineName(),
    'type' => 'comment',
    'configuration' => [
      'keywords' => [
        $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([
    $comment,
  ]);
  $this
    ->assertTrue($comment
    ->isPublished() === FALSE, 'The comment status was set to not published.');
}