You are here

public function CommentActionsTest::testCommentUnpublishByKeyword in Drupal 10

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

Tests the unpublish comment by keyword action.

See also

\Drupal\comment\Plugin\Action\UnpublishByKeywordComment

File

core/modules/comment/tests/src/Kernel/CommentActionsTest.php, line 135

Class

CommentActionsTest
Tests actions provided by the Comment module.

Namespace

Drupal\Tests\comment\Kernel

Code

public function testCommentUnpublishByKeyword() {
  $this->comment
    ->save();
  $action = Action::create([
    'id' => 'comment_unpublish_by_keyword_action',
    'label' => $this
      ->randomMachineName(),
    'type' => 'comment',
    'plugin' => 'comment_unpublish_by_keyword_action',
  ]);

  // Tests no keywords.
  $action
    ->execute([
    $this->comment,
  ]);
  $this
    ->assertTrue($this->comment
    ->isPublished(), 'The comment status was set to published.');

  // Tests keyword in subject.
  $action
    ->set('configuration', [
    'keywords' => [
      $this->keywords[0],
    ],
  ]);
  $action
    ->execute([
    $this->comment,
  ]);
  $this
    ->assertFalse($this->comment
    ->isPublished(), 'The comment status was set to not published.');

  // Tests keyword in comment body.
  $this->comment
    ->setPublished();
  $action
    ->set('configuration', [
    'keywords' => [
      $this->keywords[1],
    ],
  ]);
  $action
    ->execute([
    $this->comment,
  ]);
  $this
    ->assertFalse($this->comment
    ->isPublished(), 'The comment status was set to not published.');
}