You are here

protected function WorkspaceTestUtilities::switchToWorkspace in Drupal 10

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

Sets a given workspace as "active" for subsequent requests.

This assumes that the switcher block has already been setup by calling setupWorkspaceSwitcherBlock().

Parameters

\Drupal\workspaces\WorkspaceInterface $workspace: The workspace to set active.

File

core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php, line 103

Class

WorkspaceTestUtilities
Utility methods for use in BrowserTestBase tests.

Namespace

Drupal\Tests\workspaces\Functional

Code

protected function switchToWorkspace(WorkspaceInterface $workspace) {
  $this
    ->assertTrue($this->switcher_block_configured, 'This test was not written correctly: you must call setupWorkspaceSwitcherBlock() before switchToWorkspace()');

  /** @var \Drupal\Tests\WebAssert $session */
  $session = $this
    ->assertSession();
  $session
    ->buttonExists('Activate');
  $this
    ->submitForm([
    'workspace_id' => $workspace
      ->id(),
  ], 'Activate');
  $session
    ->pageTextContains($workspace
    ->label() . ' is now the active workspace.');
}