function ModerationActionsTest::testNodeStatusActions

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php \Drupal\Tests\content_moderation\Functional\ModerationActionsTest::testNodeStatusActions()
  2. 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php \Drupal\Tests\content_moderation\Functional\ModerationActionsTest::testNodeStatusActions()
  3. 10 core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php \Drupal\Tests\content_moderation\Functional\ModerationActionsTest::testNodeStatusActions()

Tests the node status actions report moderation status to users correctly.

@dataProvider nodeStatusActionsTestCases

File

core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php, line 66

Class

ModerationActionsTest
Test the content moderation actions.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testNodeStatusActions($action, $bundle, $warning_appears, $starting_status, $final_status) : void {
    // Create and run an action on a node.
    $node = Node::create([
        'type' => $bundle,
        'title' => $this->randomString(),
        'status' => $starting_status,
    ]);
    if ($bundle == 'moderated_bundle') {
        $node->moderation_state->value = $starting_status ? 'published' : 'draft';
    }
    $node->save();
    $this->drupalGet('admin/content');
    $this->submitForm([
        'node_bulk_form[0]' => TRUE,
        'action' => $action,
    ], 'Apply to selected items');
    if ($warning_appears) {
        if ($action == 'node_publish_action') {
            $this->assertSession()
                ->statusMessageContains(node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly published.', 'warning');
        }
        else {
            $this->assertSession()
                ->statusMessageContains(node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly unpublished.', 'warning');
        }
    }
    else {
        $this->assertSession()
            ->statusMessageNotExists('warning');
    }
    // Ensure after the action has run, the node matches the expected status.
    $node = Node::load($node->id());
    $this->assertEquals($node->isPublished(), $final_status);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.