function UnpublishByKeywordCommentTest::testCommentUnpublishByKeyword

Tests the unpublish comment by keyword action.

See also

\Drupal\comment\Plugin\Action\UnpublishByKeywordComment

File

core/modules/action/tests/src/Kernel/UnpublishByKeywordCommentTest.php, line 138

Class

UnpublishByKeywordCommentTest
@group action

Namespace

Drupal\Tests\action\Kernel

Code

public function testCommentUnpublishByKeyword() : void {
    $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.