You are here

protected function WorkspaceTestTrait::switchToWorkspace in Drupal 10

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

Sets a given workspace as active.

Parameters

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

File

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

Class

WorkspaceTestTrait
A trait with common workspaces testing functionality.

Namespace

Drupal\Tests\workspaces\Kernel

Code

protected function switchToWorkspace($workspace_id) {

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