function WorkspaceTestTrait::switchToWorkspace

Sets a given workspace as active.

Parameters

string $workspace_id: The ID of the workspace to switch to.

34 calls to WorkspaceTestTrait::switchToWorkspace()
EntityReferenceSupportedNewEntitiesConstraintValidatorTest::testNewEntitiesForbiddenInNonDefaultWorkspace in core/modules/workspaces/tests/src/Kernel/EntityReferenceSupportedNewEntitiesConstraintValidatorTest.php
Tests new entities forbidden in non default workspace.
EntityWorkspaceConflictConstraintValidatorTest::testNewEntitiesAllowedInDefaultWorkspace in core/modules/workspaces/tests/src/Kernel/EntityWorkspaceConflictConstraintValidatorTest.php
Tests new entities allowed in default workspace.
WorkspaceAssociationTest::testMoveAllTrackedEntities in core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php
Tests moving all tracked entities of all types between workspaces.
WorkspaceAssociationTest::testMoveTrackedEntitiesOfSpecificType in core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php
Tests moving all entities of a specific type while leaving others.
WorkspaceAssociationTest::testMoveTrackedEntitiesWithMultipleRevisions in core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php
Tests moving an entity with multiple revisions between workspaces.

... See full list

File

core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php, line 71

Class

WorkspaceTestTrait
A trait with common workspaces testing functionality.

Namespace

Drupal\Tests\workspaces\Kernel

Code

protected function switchToWorkspace($workspace_id) : void {
  // Switch the test runner's context to the specified workspace.
  $workspace = $this->entityTypeManager
    ->getStorage('workspace')
    ->load($workspace_id);
  \Drupal::service('workspaces.manager')->setActiveWorkspace($workspace);
}

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