Commit 7a615251 authored by plach's avatar plach
Browse files

Issue #2934354 by amateescu, Fabianx, alexpott: Expose cacheability metadata...

Issue #2934354 by amateescu, Fabianx, alexpott: Expose cacheability metadata in WorkspaceCacheContext
parent cf458f2e
...@@ -47,7 +47,11 @@ public function getContext() { ...@@ -47,7 +47,11 @@ public function getContext() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCacheableMetadata($type = NULL) { public function getCacheableMetadata($type = NULL) {
return new CacheableMetadata(); // The active workspace will always be stored in the user's session.
$cacheability = new CacheableMetadata();
$cacheability->addCacheContexts(['session']);
return $cacheability;
} }
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\Tests\workspace\Functional; namespace Drupal\Tests\workspace\Functional;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
/** /**
* Tests workspace switching functionality. * Tests workspace switching functionality.
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
*/ */
class WorkspaceSwitcherTest extends BrowserTestBase { class WorkspaceSwitcherTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use WorkspaceTestUtilities; use WorkspaceTestUtilities;
/** /**
...@@ -52,6 +54,10 @@ public function testSwitchingWorkspaces() { ...@@ -52,6 +54,10 @@ public function testSwitchingWorkspaces() {
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$page->findButton('Confirm')->click(); $page->findButton('Confirm')->click();
// Check that WorkspaceCacheContext provides the cache context used to
// support its functionality.
$this->assertCacheContext('session');
$page->findLink($gravity->label()); $page->findLink($gravity->label());
} }
...@@ -70,6 +76,10 @@ public function testQueryParameterNegotiator() { ...@@ -70,6 +76,10 @@ public function testQueryParameterNegotiator() {
// The workspace switching via query parameter should persist. // The workspace switching via query parameter should persist.
$this->drupalGet('<front>'); $this->drupalGet('<front>');
$web_assert->elementContains('css', '.block-workspace-switcher', 'Stage'); $web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
// Check that WorkspaceCacheContext provides the cache context used to
// support its functionality.
$this->assertCacheContext('session');
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment