annotate core/modules/comment/tests/src/Functional/CommentActionsTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\comment\Functional;
Chris@0 4
Chris@0 5 use Drupal\comment\Entity\Comment;
Chris@0 6 use Drupal\system\Entity\Action;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Tests actions provided by the Comment module.
Chris@0 10 *
Chris@0 11 * @group comment
Chris@0 12 */
Chris@0 13 class CommentActionsTest extends CommentTestBase {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * Modules to install.
Chris@0 17 *
Chris@0 18 * @var array
Chris@0 19 */
Chris@0 20 public static $modules = ['dblog', 'action'];
Chris@0 21
Chris@0 22 /**
Chris@0 23 * Tests comment publish and unpublish actions.
Chris@0 24 */
Chris@0 25 public function testCommentPublishUnpublishActions() {
Chris@0 26 $this->drupalLogin($this->webUser);
Chris@0 27 $comment_text = $this->randomMachineName();
Chris@0 28 $subject = $this->randomMachineName();
Chris@0 29 $comment = $this->postComment($this->node, $comment_text, $subject);
Chris@0 30
Chris@0 31 // Unpublish a comment.
Chris@0 32 $action = Action::load('comment_unpublish_action');
Chris@0 33 $action->execute([$comment]);
Chris@0 34 $this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
Chris@14 35 $this->assertArraySubset(['module' => ['comment']], $action->getDependencies());
Chris@0 36 // Publish a comment.
Chris@0 37 $action = Action::load('comment_publish_action');
Chris@0 38 $action->execute([$comment]);
Chris@0 39 $this->assertTrue($comment->isPublished() === TRUE, 'Comment was published');
Chris@0 40 }
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Tests the unpublish comment by keyword action.
Chris@0 44 */
Chris@0 45 public function testCommentUnpublishByKeyword() {
Chris@0 46 $this->drupalLogin($this->adminUser);
Chris@0 47 $keyword_1 = $this->randomMachineName();
Chris@0 48 $keyword_2 = $this->randomMachineName();
Chris@0 49 $action = Action::create([
Chris@0 50 'id' => 'comment_unpublish_by_keyword_action',
Chris@0 51 'label' => $this->randomMachineName(),
Chris@0 52 'type' => 'comment',
Chris@0 53 'configuration' => [
Chris@0 54 'keywords' => [$keyword_1, $keyword_2],
Chris@0 55 ],
Chris@0 56 'plugin' => 'comment_unpublish_by_keyword_action',
Chris@0 57 ]);
Chris@0 58 $action->save();
Chris@0 59
Chris@0 60 $comment = $this->postComment($this->node, $keyword_2, $this->randomMachineName());
Chris@0 61
Chris@0 62 // Load the full comment so that status is available.
Chris@0 63 $comment = Comment::load($comment->id());
Chris@0 64
Chris@0 65 $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.');
Chris@0 66
Chris@0 67 $action->execute([$comment]);
Chris@0 68 $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.');
Chris@0 69 }
Chris@0 70
Chris@0 71 }