function CommentActionsTest::testCommentUnpublishByKeyword

Same name in other branches
  1. 9 core/modules/comment/tests/src/Kernel/CommentActionsTest.php \Drupal\Tests\comment\Kernel\CommentActionsTest::testCommentUnpublishByKeyword()
  2. 8.9.x core/modules/comment/tests/src/Functional/CommentActionsTest.php \Drupal\Tests\comment\Functional\CommentActionsTest::testCommentUnpublishByKeyword()
  3. 11.x 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 136

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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.