summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Placella2018-07-03 22:02:04 (GMT)
committerFrancesco Placella2018-07-03 22:02:04 (GMT)
commit7a615251d8c2115b510dd47e2c6fe5b787990895 (patch)
tree2ec0fbd0cf242bb074ec48caf85ffe68968cc05b
parentcf458f2e04b593ca7f354d318f774a4490515c0c (diff)
Issue #2934354 by amateescu, Fabianx, alexpott: Expose cacheability metadata in WorkspaceCacheContext
-rw-r--r--core/modules/workspace/src/WorkspaceCacheContext.php6
-rw-r--r--core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php10
2 files changed, 15 insertions, 1 deletions
diff --git a/core/modules/workspace/src/WorkspaceCacheContext.php b/core/modules/workspace/src/WorkspaceCacheContext.php
index 14ce019..129be00 100644
--- a/core/modules/workspace/src/WorkspaceCacheContext.php
+++ b/core/modules/workspace/src/WorkspaceCacheContext.php
@@ -47,7 +47,11 @@ class WorkspaceCacheContext implements CacheContextInterface {
* {@inheritdoc}
*/
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;
}
}
diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php
index 22a51b3..245aba4 100644
--- a/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php
+++ b/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\workspace\Functional;
use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
/**
* Tests workspace switching functionality.
@@ -11,6 +12,7 @@ use Drupal\Tests\BrowserTestBase;
*/
class WorkspaceSwitcherTest extends BrowserTestBase {
+ use AssertPageCacheContextsAndTagsTrait;
use WorkspaceTestUtilities;
/**
@@ -52,6 +54,10 @@ class WorkspaceSwitcherTest extends BrowserTestBase {
$page = $this->getSession()->getPage();
$page->findButton('Confirm')->click();
+ // Check that WorkspaceCacheContext provides the cache context used to
+ // support its functionality.
+ $this->assertCacheContext('session');
+
$page->findLink($gravity->label());
}
@@ -70,6 +76,10 @@ class WorkspaceSwitcherTest extends BrowserTestBase {
// The workspace switching via query parameter should persist.
$this->drupalGet('<front>');
$web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
+
+ // Check that WorkspaceCacheContext provides the cache context used to
+ // support its functionality.
+ $this->assertCacheContext('session');
}
}