function CommentActionsTest::testCommentUnpublishByKeyword
Same name in other branches
- 8.9.x core/modules/comment/tests/src/Functional/CommentActionsTest.php \Drupal\Tests\comment\Functional\CommentActionsTest::testCommentUnpublishByKeyword()
- 10 core/modules/comment/tests/src/Kernel/CommentActionsTest.php \Drupal\Tests\comment\Kernel\CommentActionsTest::testCommentUnpublishByKeyword()
- 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 135
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.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.