function WorkspacesContentModerationStateTest::testContentModerationWithoutDefaultRevisionsInWorkspaces

Same name in other branches
  1. 11.x core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\WorkspacesContentModerationStateTest::testContentModerationWithoutDefaultRevisionsInWorkspaces()

Publish a workspace with workflows including no tracked default revisions.

File

core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php, line 179

Class

WorkspacesContentModerationStateTest
Tests that Workspaces and Content Moderation work together properly.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testContentModerationWithoutDefaultRevisionsInWorkspaces() : void {
    $access_handler = $this->container
        ->get('entity_type.manager')
        ->getAccessControlHandler('workspace');
    // Create a workflow which has the same states as the 'editorial' one,
    // but it doesn't create any default revisions. This covers the case when a
    // workspace is published containing no tracked types. This has to be the
    // only workflow.
    $editorial = $this->createEditorialWorkflow();
    $type_settings = $editorial->get('type_settings');
    $type_settings['states']['draft']['default_revision'] = FALSE;
    $type_settings['states']['archived']['default_revision'] = FALSE;
    $this->workspaceManager
        ->executeOutsideWorkspace(function () use ($editorial) {
        $editorial->save();
    });
    // Create an node bundle 'note' that uses non-default workflow.
    $this->createContentType([
        'type' => 'note',
    ]);
    // Create content in all states none with default revisions.
    $note_archived = Node::create([
        'type' => 'note',
        'title' => 'Test note - archived',
        'moderation_state' => 'archived',
    ]);
    $note_archived->save();
    $note_draft = Node::create([
        'type' => 'note',
        'title' => 'Test note - draft',
        'moderation_state' => 'draft',
    ]);
    $note_draft->save();
    $note_published = Node::create([
        'type' => 'note',
        'title' => 'Test note - published',
        'moderation_state' => 'published',
    ]);
    $note_published->save();
    // Check workspace can be published.
    $access_handler->resetCache();
    $this->workspaces['stage']
        ->publish();
}

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