public function CommentActionsTest::testCommentUnpublishByKeyword in Drupal 9
Same name and namespace in other branches
- 10 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 134
Class
- CommentActionsTest
- Tests actions provided by the Comment module.
Namespace
Drupal\Tests\comment\KernelCode
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.');
}