.../cacheability_safeguards.info.yml} | 3 +- .../src/CacheabilityBubblingNodeGrantStorage.php | 4 +- .../src/CacheabilitySafeguardsServiceProvider.php} | 8 +-- .../Tests/NodeAccessCacheabilitySafeguardTest.php | 73 ++++++++++++++++++++++ .../node_access_test_auto_bubbling.info.yml | 0 .../node_access_test_auto_bubbling.routing.yml | 0 .../NodeAccessTestAutoBubblingController.php | 0 .../src/Tests/NodeAccessGrantsCacheContextTest.php | 36 ----------- 8 files changed, 80 insertions(+), 44 deletions(-) diff --git a/core/modules/cache_context_safeguards/cache_context_safeguards.info.yml b/core/modules/cacheability_safeguards/cacheability_safeguards.info.yml similarity index 62% rename from core/modules/cache_context_safeguards/cache_context_safeguards.info.yml rename to core/modules/cacheability_safeguards/cacheability_safeguards.info.yml index dc6f1f8..94f3498 100644 --- a/core/modules/cache_context_safeguards/cache_context_safeguards.info.yml +++ b/core/modules/cacheability_safeguards/cacheability_safeguards.info.yml @@ -1,6 +1,5 @@ -name: Cache Context Safeguards +name: Cacheability Safeguards type: module -description: "…" package: Core core: 8.x required: true diff --git a/core/modules/cache_context_safeguards/src/CacheabilityBubblingNodeGrantStorage.php b/core/modules/cacheability_safeguards/src/CacheabilityBubblingNodeGrantStorage.php similarity index 96% rename from core/modules/cache_context_safeguards/src/CacheabilityBubblingNodeGrantStorage.php rename to core/modules/cacheability_safeguards/src/CacheabilityBubblingNodeGrantStorage.php index e279a62..890e968 100644 --- a/core/modules/cache_context_safeguards/src/CacheabilityBubblingNodeGrantStorage.php +++ b/core/modules/cacheability_safeguards/src/CacheabilityBubblingNodeGrantStorage.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\cache_context_safeguards\CacheabilityBubblingNodeGrantStorage. + * Contains \Drupal\cacheability_safeguards\CacheabilityBubblingNodeGrantStorage. */ -namespace Drupal\cache_context_safeguards; +namespace Drupal\cacheability_safeguards; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Session\AccountInterface; diff --git a/core/modules/cache_context_safeguards/src/CacheContextSafeguardsServiceProvider.php b/core/modules/cacheability_safeguards/src/CacheabilitySafeguardsServiceProvider.php similarity index 81% rename from core/modules/cache_context_safeguards/src/CacheContextSafeguardsServiceProvider.php rename to core/modules/cacheability_safeguards/src/CacheabilitySafeguardsServiceProvider.php index 552f2db..83d69be 100644 --- a/core/modules/cache_context_safeguards/src/CacheContextSafeguardsServiceProvider.php +++ b/core/modules/cacheability_safeguards/src/CacheabilitySafeguardsServiceProvider.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\cache_context_safeguards\CacheContextSafeguardsServiceProvider. + * Contains \Drupal\cacheability_safeguards\CacheContextSafeguardsServiceProvider. */ -namespace Drupal\cache_context_safeguards; +namespace Drupal\cacheability_safeguards; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceModifierInterface; @@ -14,7 +14,7 @@ /** * … */ -class CacheContextSafeguardsServiceProvider implements ServiceModifierInterface { +class CacheabilitySafeguardsServiceProvider implements ServiceModifierInterface { /** * {@inheritdoc} @@ -35,7 +35,7 @@ public function alter(ContainerBuilder $container) { $container->setDefinition('node.grant_storage.non_bubbling', $container->getDefinition('node.grant_storage')) ->setPublic(FALSE); $container->register('node.grant_storage') - ->setClass('\Drupal\cache_context_safeguards\CacheabilityBubblingNodeGrantStorage') + ->setClass('\Drupal\cacheability_safeguards\CacheabilityBubblingNodeGrantStorage') ->addArgument(new Reference('node.grant_storage.non_bubbling')) ->addMethodCall('setContainer', [new Reference('service_container')]); } diff --git a/core/modules/cacheability_safeguards/src/Tests/NodeAccessCacheabilitySafeguardTest.php b/core/modules/cacheability_safeguards/src/Tests/NodeAccessCacheabilitySafeguardTest.php new file mode 100644 index 0000000..97628f1 --- /dev/null +++ b/core/modules/cacheability_safeguards/src/Tests/NodeAccessCacheabilitySafeguardTest.php @@ -0,0 +1,73 @@ +drupalCreateNode(); + $this->drupalCreateNode(); + $this->drupalCreateNode(); + $this->drupalCreateNode(); + } + + /** + * Tests that the node grants cache context is auto-added, only when needed. + * + * @see \Drupal\cacheability_safeguards\CacheabilityBubblingNodeGrantStorage + */ + public function testNodeAccessCacheabilitySafeguard() { + $this->dumpHeaders = TRUE; + + // The node grants cache context should be added automatically. + $this->drupalGet(new Url('node_access_test_auto_bubbling')); + $this->assertCacheContext('user.node_grants:view'); + + // The root user has the 'bypass node access' permission, which means the + // node grants cache context is not necessary. + $this->drupalLogin($this->rootUser); + $this->drupalGet(new Url('node_access_test_auto_bubbling')); + $this->assertNoCacheContext('user.node_grants:view'); + $this->drupalLogout(); + + // Uninstall the module with the only hook_node_grants() implementation. + $this->container->get('module_installer')->uninstall(['node_access_test']); + $this->rebuildContainer(); + + // Because there are no node grants defined, there also is no need for the + // node grants cache context to be bubbled. + $this->drupalGet(new Url('node_access_test_auto_bubbling')); + $this->assertNoCacheContext('user.node_grants:view'); + } + +} diff --git a/core/modules/node/tests/modules/node_access_test_auto_bubbling/node_access_test_auto_bubbling.info.yml b/core/modules/cacheability_safeguards/tests/node_access_test_auto_bubbling/node_access_test_auto_bubbling.info.yml similarity index 100% rename from core/modules/node/tests/modules/node_access_test_auto_bubbling/node_access_test_auto_bubbling.info.yml rename to core/modules/cacheability_safeguards/tests/node_access_test_auto_bubbling/node_access_test_auto_bubbling.info.yml diff --git a/core/modules/node/tests/modules/node_access_test_auto_bubbling/node_access_test_auto_bubbling.routing.yml b/core/modules/cacheability_safeguards/tests/node_access_test_auto_bubbling/node_access_test_auto_bubbling.routing.yml similarity index 100% rename from core/modules/node/tests/modules/node_access_test_auto_bubbling/node_access_test_auto_bubbling.routing.yml rename to core/modules/cacheability_safeguards/tests/node_access_test_auto_bubbling/node_access_test_auto_bubbling.routing.yml diff --git a/core/modules/node/tests/modules/node_access_test_auto_bubbling/src/Controller/NodeAccessTestAutoBubblingController.php b/core/modules/cacheability_safeguards/tests/node_access_test_auto_bubbling/src/Controller/NodeAccessTestAutoBubblingController.php similarity index 100% rename from core/modules/node/tests/modules/node_access_test_auto_bubbling/src/Controller/NodeAccessTestAutoBubblingController.php rename to core/modules/cacheability_safeguards/tests/node_access_test_auto_bubbling/src/Controller/NodeAccessTestAutoBubblingController.php diff --git a/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php b/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php index b8fad35..1d34bc1 100644 --- a/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php +++ b/core/modules/node/src/Tests/NodeAccessGrantsCacheContextTest.php @@ -7,8 +7,6 @@ namespace Drupal\node\Tests; -use Drupal\Core\Url; - /** * Tests the node access grants cache context service. * @@ -142,38 +140,4 @@ public function testCacheContext() { ]); } - /** - * Tests that the node grants cache context is auto-added, only when needed. - * - * @see node_query_node_access_alter() - */ - public function testAutomaticNodeAccessGrantsCacheContextBubbling() { - $this->dumpHeaders = TRUE; - - // Install the module that contains our test route and controller. - $this->container->get('module_installer')->install(['node_access_test_auto_bubbling']); - $this->rebuildContainer(); - $this->container->get('router.builder')->rebuild(); - - // The node grants cache context should be added automatically. - $this->drupalGet(new Url('node_access_test_auto_bubbling')); - $this->assertCacheContext('user.node_grants:view'); - - // The root user has the 'bypass node access' permission, which means the - // node grants cache context is not necessary. - $this->drupalLogin($this->rootUser); - $this->drupalGet(new Url('node_access_test_auto_bubbling')); - $this->assertNoCacheContext('user.node_grants:view'); - $this->drupalLogout(); - - // Uninstall the module with the only hook_node_grants() implementation. - $this->container->get('module_installer')->uninstall(['node_access_test']); - $this->rebuildContainer(); - - // Because there are no node grants defined, there also is no need for the - // node grants cache context to be bubbled. - $this->drupalGet(new Url('node_access_test_auto_bubbling')); - $this->assertNoCacheContext('user.node_grants:view'); - } - }