3 namespace Drupal\Tests\workspaces\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
9 * Tests workspace switching functionality.
13 class WorkspaceSwitcherTest extends BrowserTestBase {
15 use AssertPageCacheContextsAndTagsTrait;
16 use WorkspaceTestUtilities;
21 public static $modules = ['block', 'workspaces'];
26 protected function setUp() {
33 'bypass entity access own workspace',
36 $this->setupWorkspaceSwitcherBlock();
38 $mayer = $this->drupalCreateUser($permissions);
39 $this->drupalLogin($mayer);
43 * Test switching workspace via the switcher block and admin page.
45 public function testSwitchingWorkspaces() {
46 $vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures');
47 $this->switchToWorkspace($vultures);
49 $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');
51 $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate');
53 $this->assertSession()->statusCodeEquals(200);
54 $page = $this->getSession()->getPage();
55 $page->findButton('Confirm')->click();
57 // Check that WorkspaceCacheContext provides the cache context used to
58 // support its functionality.
59 $this->assertCacheContext('session');
61 $page->findLink($gravity->label());
65 * Test switching workspace via a query parameter.
67 public function testQueryParameterNegotiator() {
68 $web_assert = $this->assertSession();
69 // Initially the default workspace should be active.
70 $web_assert->elementContains('css', '.block-workspace-switcher', 'Live');
72 // When adding a query parameter the workspace will be switched.
73 $this->drupalGet('<front>', ['query' => ['workspace' => 'stage']]);
74 $web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
76 // The workspace switching via query parameter should persist.
77 $this->drupalGet('<front>');
78 $web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
80 // Check that WorkspaceCacheContext provides the cache context used to
81 // support its functionality.
82 $this->assertCacheContext('session');