function WorkspaceIntegrationTest::testWorkspaceAssociationDataIntegrity

Same name in other branches
  1. 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testWorkspaceAssociationDataIntegrity()

Tests the workspace association data integrity for entity CRUD operations.

@covers ::workspaces_entity_presave @covers ::workspaces_entity_insert @covers ::workspaces_entity_delete @covers ::workspaces_entity_revision_delete

File

core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php, line 380

Class

WorkspaceIntegrationTest
Tests a complete publishing scenario across different workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

public function testWorkspaceAssociationDataIntegrity() : void {
    $this->initializeWorkspacesModule();
    // Check the initial empty state.
    $expected_workspace_association = [
        'stage' => [],
    ];
    $this->assertWorkspaceAssociation($expected_workspace_association, 'node');
    // Add a new unpublished node in 'stage' and check that new revision is
    // tracked in the workspace association data.
    $this->switchToWorkspace('stage');
    $unpublished_node = $this->createNode([
        'title' => 'stage - 3 - r3 - unpublished',
        'created' => $this->createdTimestamp++,
        'status' => FALSE,
    ]);
    $expected_workspace_association = [
        'stage' => [
            3,
        ],
    ];
    $this->assertWorkspaceAssociation($expected_workspace_association, 'node');
    // Add a new revision for the unpublished node.
    $unpublished_node->title = 'stage - 3 - r4 - unpublished';
    $unpublished_node->save();
    $expected_workspace_association = [
        'stage' => [
            4,
        ],
    ];
    $this->assertWorkspaceAssociation($expected_workspace_association, 'node');
    // Delete the unpublished node and check that the association data has been
    // updated.
    $unpublished_node->delete();
    $expected_workspace_association = [
        'stage' => [],
    ];
    $this->assertWorkspaceAssociation($expected_workspace_association, 'node');
    // Add a new published node in 'stage' and check that new workspace-specific
    // revision is tracked in the workspace association data. Note that revision
    // '5' has been created as an unpublished default revision in Live, so it is
    // not tracked.
    $node = $this->createNode([
        'title' => 'stage - 4 - r6 - published',
        'created' => $this->createdTimestamp++,
        'status' => TRUE,
    ]);
    $expected_workspace_association = [
        'stage' => [
            6,
        ],
    ];
    $this->assertWorkspaceAssociation($expected_workspace_association, 'node');
    // Check that the entity object that was saved has been updated to point to
    // the workspace-specific revision.
    $this->assertEquals(6, $node->getRevisionId());
    // Delete revision '6' and check that the workspace association does not
    // track it anymore.
    $this->entityTypeManager
        ->getStorage('node')
        ->deleteRevision(6);
    $expected_workspace_association = [
        'stage' => [],
    ];
    $this->assertWorkspaceAssociation($expected_workspace_association, 'node');
}

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