3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\node\Entity\Node;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\Tests\BrowserTestBase;
8 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
11 * Test the content moderation actions.
13 * @group content_moderation
15 class ModerationActionsTest extends BrowserTestBase {
17 use ContentTypeCreationTrait;
18 use ContentModerationTestTrait;
25 public static $modules = [
34 public function setUp() {
37 $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
38 $moderated_bundle->save();
39 $standard_bundle = $this->createContentType(['type' => 'standard_bundle']);
40 $standard_bundle->save();
42 $workflow = $this->createEditorialWorkflow();
43 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated_bundle');
46 $admin = $this->drupalCreateUser([
47 'access content overview',
51 $this->drupalLogin($admin);
55 * Test the node status actions report moderation status to users correctly.
57 * @dataProvider nodeStatusActionsTestCases
59 public function testNodeStatusActions($action, $bundle, $warning_appears, $starting_status, $final_status) {
60 // Create and run an action on a node.
61 $node = Node::create([
63 'title' => $this->randomString(),
64 'status' => $starting_status,
66 if ($bundle == 'moderated_bundle') {
67 $node->moderation_state->value = $starting_status ? 'published' : 'draft';
71 $this->drupalPostForm('admin/content', [
72 'node_bulk_form[0]' => TRUE,
74 ], 'Apply to selected items');
76 if ($warning_appears) {
77 if ($action == 'node_publish_action') {
78 $this->assertSession()
79 ->elementContains('css', '.messages--warning', node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly published.');
82 $this->assertSession()
83 ->elementContains('css', '.messages--warning', node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly unpublished.');
87 $this->assertSession()->elementNotExists('css', '.messages--warning');
90 // Ensure after the action has run, the node matches the expected status.
91 $node = Node::load($node->id());
92 $this->assertEquals($node->isPublished(), $final_status);
96 * Test cases for ::testNodeStatusActions.
99 * An array of test cases.
101 public function nodeStatusActionsTestCases() {
103 'Moderated bundle shows warning (publish action)' => [
104 'node_publish_action',
107 // If the node starts out unpublished, the action should not work.
111 'Moderated bundle shows warning (unpublish action)' => [
112 'node_unpublish_action',
115 // If the node starts out published, the action should not work.
119 'Normal bundle works (publish action)' => [
120 'node_publish_action',
123 // If the node starts out unpublished, the action should work.
127 'Normal bundle works (unpublish action)' => [
128 'node_unpublish_action',
131 // If the node starts out published, the action should work.