You are here

public function WorkspaceIntegrationTest::testDisallowedEntityCreateInNonDefaultWorkspace in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testDisallowedEntityCreateInNonDefaultWorkspace()
  2. 9 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testDisallowedEntityCreateInNonDefaultWorkspace()

Tests CREATE operations for unsupported entity types.

@dataProvider providerTestAllowedEntityCrudInNonDefaultWorkspace

File

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

Class

WorkspaceIntegrationTest
Tests a complete publishing scenario across different workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

public function testDisallowedEntityCreateInNonDefaultWorkspace($entity_type_id, $allowed) {
  $this
    ->initializeWorkspacesModule();

  /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
  $storage = $this->entityTypeManager
    ->getStorage($entity_type_id);

  // Switch to a non-default workspace and check whether creating a new entity
  // is allowed.
  $this
    ->switchToWorkspace('stage');
  $entity = $storage
    ->createWithSampleValues($entity_type_id);
  if ($entity_type_id === 'workspace') {
    $entity->id = 'test';
  }
  if (!$allowed) {
    $this
      ->expectException(EntityStorageException::class);
    $this
      ->expectExceptionMessage('This entity can only be saved in the default workspace.');
  }
  $entity
    ->save();
}