3 namespace Drupal\comment\Tests;
5 use Drupal\comment\Entity\Comment;
6 use Drupal\system\Entity\Action;
9 * Tests actions provided by the Comment module.
13 class CommentActionsTest extends CommentTestBase {
20 public static $modules = ['dblog', 'action'];
23 * Tests comment publish and unpublish actions.
25 public function testCommentPublishUnpublishActions() {
26 $this->drupalLogin($this->webUser);
27 $comment_text = $this->randomMachineName();
28 $subject = $this->randomMachineName();
29 $comment = $this->postComment($this->node, $comment_text, $subject);
31 // Unpublish a comment.
32 $action = Action::load('comment_unpublish_action');
33 $action->execute([$comment]);
34 $this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
37 $action = Action::load('comment_publish_action');
38 $action->execute([$comment]);
39 $this->assertTrue($comment->isPublished() === TRUE, 'Comment was published');
43 * Tests the unpublish comment by keyword action.
45 public function testCommentUnpublishByKeyword() {
46 $this->drupalLogin($this->adminUser);
47 $keyword_1 = $this->randomMachineName();
48 $keyword_2 = $this->randomMachineName();
49 $action = Action::create([
50 'id' => 'comment_unpublish_by_keyword_action',
51 'label' => $this->randomMachineName(),
54 'keywords' => [$keyword_1, $keyword_2],
56 'plugin' => 'comment_unpublish_by_keyword_action',
60 $comment = $this->postComment($this->node, $keyword_2, $this->randomMachineName());
62 // Load the full comment so that status is available.
63 $comment = Comment::load($comment->id());
65 $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.');
67 $action->execute([$comment]);
68 $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.');