Chris@0: drupalLogin($this->webUser); Chris@0: $comment_text = $this->randomMachineName(); Chris@0: $subject = $this->randomMachineName(); Chris@0: $comment = $this->postComment($this->node, $comment_text, $subject); Chris@0: Chris@0: // Unpublish a comment. Chris@0: $action = Action::load('comment_unpublish_action'); Chris@0: $action->execute([$comment]); Chris@0: $this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished'); Chris@14: $this->assertArraySubset(['module' => ['comment']], $action->getDependencies()); Chris@0: // Publish a comment. Chris@0: $action = Action::load('comment_publish_action'); Chris@0: $action->execute([$comment]); Chris@0: $this->assertTrue($comment->isPublished() === TRUE, 'Comment was published'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the unpublish comment by keyword action. Chris@0: */ Chris@0: public function testCommentUnpublishByKeyword() { Chris@0: $this->drupalLogin($this->adminUser); Chris@0: $keyword_1 = $this->randomMachineName(); Chris@0: $keyword_2 = $this->randomMachineName(); Chris@0: $action = Action::create([ Chris@0: 'id' => 'comment_unpublish_by_keyword_action', Chris@0: 'label' => $this->randomMachineName(), Chris@0: 'type' => 'comment', Chris@0: 'configuration' => [ Chris@0: 'keywords' => [$keyword_1, $keyword_2], Chris@0: ], Chris@0: 'plugin' => 'comment_unpublish_by_keyword_action', Chris@0: ]); Chris@0: $action->save(); Chris@0: Chris@0: $comment = $this->postComment($this->node, $keyword_2, $this->randomMachineName()); Chris@0: Chris@0: // Load the full comment so that status is available. Chris@0: $comment = Comment::load($comment->id()); Chris@0: Chris@0: $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.'); Chris@0: Chris@0: $action->execute([$comment]); Chris@0: $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.'); Chris@0: } Chris@0: Chris@0: }