comparison core/modules/comment/tests/src/Functional/CommentActionsTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\comment\Functional;
4
5 use Drupal\comment\Entity\Comment;
6 use Drupal\system\Entity\Action;
7
8 /**
9 * Tests actions provided by the Comment module.
10 *
11 * @group comment
12 */
13 class CommentActionsTest extends CommentTestBase {
14
15 /**
16 * Modules to install.
17 *
18 * @var array
19 */
20 public static $modules = ['dblog', 'action'];
21
22 /**
23 * Tests comment publish and unpublish actions.
24 */
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);
30
31 // Unpublish a comment.
32 $action = Action::load('comment_unpublish_action');
33 $action->execute([$comment]);
34 $this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
35
36 // Publish a comment.
37 $action = Action::load('comment_publish_action');
38 $action->execute([$comment]);
39 $this->assertTrue($comment->isPublished() === TRUE, 'Comment was published');
40 }
41
42 /**
43 * Tests the unpublish comment by keyword action.
44 */
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(),
52 'type' => 'comment',
53 'configuration' => [
54 'keywords' => [$keyword_1, $keyword_2],
55 ],
56 'plugin' => 'comment_unpublish_by_keyword_action',
57 ]);
58 $action->save();
59
60 $comment = $this->postComment($this->node, $keyword_2, $this->randomMachineName());
61
62 // Load the full comment so that status is available.
63 $comment = Comment::load($comment->id());
64
65 $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.');
66
67 $action->execute([$comment]);
68 $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.');
69 }
70
71 }