Pull merge.
[yaffs-website] / web / core / modules / workspaces / tests / src / Functional / WorkspaceSwitcherTest.php
1 <?php
2
3 namespace Drupal\Tests\workspaces\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
7
8 /**
9  * Tests workspace switching functionality.
10  *
11  * @group workspaces
12  */
13 class WorkspaceSwitcherTest extends BrowserTestBase {
14
15   use AssertPageCacheContextsAndTagsTrait;
16   use WorkspaceTestUtilities;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['block', 'workspaces'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28
29     $permissions = [
30       'create workspace',
31       'edit own workspace',
32       'view own workspace',
33       'bypass entity access own workspace',
34     ];
35
36     $this->setupWorkspaceSwitcherBlock();
37
38     $mayer = $this->drupalCreateUser($permissions);
39     $this->drupalLogin($mayer);
40   }
41
42   /**
43    * Test switching workspace via the switcher block and admin page.
44    */
45   public function testSwitchingWorkspaces() {
46     $vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures');
47     $this->switchToWorkspace($vultures);
48
49     $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');
50
51     $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate');
52
53     $this->assertSession()->statusCodeEquals(200);
54     $page = $this->getSession()->getPage();
55     $page->findButton('Confirm')->click();
56
57     // Check that WorkspaceCacheContext provides the cache context used to
58     // support its functionality.
59     $this->assertCacheContext('session');
60
61     $page->findLink($gravity->label());
62   }
63
64   /**
65    * Test switching workspace via a query parameter.
66    */
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');
71
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');
75
76     // The workspace switching via query parameter should persist.
77     $this->drupalGet('<front>');
78     $web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
79
80     // Check that WorkspaceCacheContext provides the cache context used to
81     // support its functionality.
82     $this->assertCacheContext('session');
83   }
84
85 }