function WorkspaceTestTrait::switchToWorkspace

Same name in other branches
  1. 9 core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php \Drupal\Tests\workspaces\Kernel\WorkspaceTestTrait::switchToWorkspace()
  2. 8.9.x core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php \Drupal\Tests\workspaces\Kernel\WorkspaceTestTrait::switchToWorkspace()
  3. 10 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.

25 calls to WorkspaceTestTrait::switchToWorkspace()
EntityReferenceSupportedNewEntitiesConstraintValidatorTest::testNewEntitiesForbiddenInNonDefaultWorkspace in core/modules/workspaces/tests/src/Kernel/EntityReferenceSupportedNewEntitiesConstraintValidatorTest.php
@covers ::validate
EntityWorkspaceConflictConstraintValidatorTest::testNewEntitiesAllowedInDefaultWorkspace in core/modules/workspaces/tests/src/Kernel/EntityWorkspaceConflictConstraintValidatorTest.php
@covers ::validate
WorkspaceAssociationTest::testWorkspaceAssociation in core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php
Tests the revisions tracked by a workspace.
WorkspaceContentTranslationTest::testTranslations in core/modules/workspaces/tests/src/Kernel/WorkspaceContentTranslationTest.php
Tests translations created in a workspace.
WorkspaceEntityDeleteTest::testEntityDeletion in core/modules/workspaces/tests/src/Kernel/WorkspaceEntityDeleteTest.php
Test entity deletion in a workspace.

... 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) {
    // 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.