function WorkspaceIntegrationTest::testDisallowedEntityDeleteInNonDefaultWorkspace

Same name and namespace in other branches
  1. 8.9.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testDisallowedEntityDeleteInNonDefaultWorkspace()
  2. 10 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testDisallowedEntityDeleteInNonDefaultWorkspace()
  3. 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testDisallowedEntityDeleteInNonDefaultWorkspace()

Tests DELETE operations for unsupported entity types.

@dataProvider providerTestAllowedEntityCrudInNonDefaultWorkspace

File

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

Class

WorkspaceIntegrationTest
Tests a complete publishing scenario across different workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

public function testDisallowedEntityDeleteInNonDefaultWorkspace($entity_type_id, $allowed) {
    $this->initializeWorkspacesModule();
    
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager
        ->getStorage($entity_type_id);
    // Create the entity in the default workspace.
    $this->workspaceManager
        ->switchToLive();
    $entity = $storage->createWithSampleValues($entity_type_id);
    if ($entity_type_id === 'workspace') {
        $entity->id = 'test';
    }
    $entity->save();
    // Switch to a non-default workspace and check whether deleting the entity
    // is allowed.
    $this->switchToWorkspace('stage');
    if (!$allowed) {
        $this->expectException(EntityStorageException::class);
        $this->expectExceptionMessage('This entity can only be deleted in the default workspace.');
    }
    $entity->delete();
}

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