CommentActionsTest.php in Drupal 8
File
core/modules/comment/tests/src/Functional/CommentActionsTest.php
View source
<?php
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Entity\Comment;
use Drupal\system\Entity\Action;
class CommentActionsTest extends CommentTestBase {
public static $modules = [
'dblog',
'action',
];
protected $defaultTheme = 'stark';
public function testCommentPublishUnpublishActions() {
$this
->drupalLogin($this->webUser);
$comment_text = $this
->randomMachineName();
$subject = $this
->randomMachineName();
$comment = $this
->postComment($this->node, $comment_text, $subject);
$action = Action::load('comment_unpublish_action');
$action
->execute([
$comment,
]);
$this
->assertTrue($comment
->isPublished() === FALSE, 'Comment was unpublished');
$this
->assertArraySubset([
'module' => [
'comment',
],
], $action
->getDependencies());
$action = Action::load('comment_publish_action');
$action
->execute([
$comment,
]);
$this
->assertTrue($comment
->isPublished() === TRUE, 'Comment was published');
}
public function testCommentUnpublishByKeyword() {
$this
->drupalLogin($this->adminUser);
$keyword_1 = $this
->randomMachineName();
$keyword_2 = $this
->randomMachineName();
$action = Action::create([
'id' => 'comment_unpublish_by_keyword_action',
'label' => $this
->randomMachineName(),
'type' => 'comment',
'configuration' => [
'keywords' => [
$keyword_1,
$keyword_2,
],
],
'plugin' => 'comment_unpublish_by_keyword_action',
]);
$action
->save();
$comment = $this
->postComment($this->node, $keyword_2, $this
->randomMachineName());
$comment = Comment::load($comment
->id());
$this
->assertTrue($comment
->isPublished() === TRUE, 'The comment status was set to published.');
$action
->execute([
$comment,
]);
$this
->assertTrue($comment
->isPublished() === FALSE, 'The comment status was set to not published.');
}
}