core/modules/node/src/Tests/NodeCacheTagsTest.php | 7 +++++++ .../src/Tests/Entity/EntityCacheTagsTestBase.php | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/modules/node/src/Tests/NodeCacheTagsTest.php b/core/modules/node/src/Tests/NodeCacheTagsTest.php index 6da02d0..c18f15b 100644 --- a/core/modules/node/src/Tests/NodeCacheTagsTest.php +++ b/core/modules/node/src/Tests/NodeCacheTagsTest.php @@ -58,4 +58,11 @@ protected function getAdditionalCacheTagsForEntity(EntityInterface $node) { return array('user:' . $node->getOwnerId(), 'user_view'); } + /** + * {@inheritdoc} + */ + protected function getAdditionalCacheContextsForEntityListing() { + return ['node_view_grants']; + } + } diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index aa4faff..f060034 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -159,6 +159,16 @@ protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) { /** * Returns the additional cache tags for the tested entity's listing by type. * + * @return string[] + * An array of the additional cache contexts. + */ + protected function getAdditionalCacheContextsForEntityListing() { + return []; + } + + /** + * Returns the additional cache tags for the tested entity's listing by type. + * * Necessary when there are unavoidable default entities of this type, e.g. * the anonymous and administrator User entities always exist. * @@ -378,21 +388,21 @@ public function testReferencedEntity() { $this->pass("Test empty listing.", 'Debug'); - // @todo verify ::getListCacheTags() are present, blocked on - // https://www.drupal.org/node/2445761 // Prime the page cache for the empty listing. $this->verifyPageCache($empty_entity_listing_url, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. $this->verifyPageCache($empty_entity_listing_url, 'HIT', $empty_entity_listing_cache_tags); + // Verify the entity type's list cache contexts are present. + $this->assertEqual($this->getAdditionalCacheContextsForEntityListing(), explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Contexts'))); $this->pass("Test listing containing referenced entity.", 'Debug'); - // @todo verify ::getListCacheTags() are present, blocked on - // https://www.drupal.org/node/2445761 // Prime the page cache for the listing containing the referenced entity. - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); + $this->verifyPageCache($nonempty_entity_listing_url, 'MISS', $nonempty_entity_listing_cache_tags); // Verify a cache hit, but also the presence of the correct cache tags. $this->verifyPageCache($nonempty_entity_listing_url, 'HIT', $nonempty_entity_listing_cache_tags); + // Verify the entity type's list cache contexts are present. + $this->assertEqual($this->getAdditionalCacheContextsForEntityListing(), explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Contexts'))); // Verify that after modifying the referenced entity, there is a cache miss