diff --git a/core/modules/node/node.services.yml b/core/modules/node/node.services.yml index 9ef729444a7115193febf8d5c4793a51c4253c27..25759b3be176d0d7a3d0f570d2394bfefa1f49ab 100644 --- a/core/modules/node/node.services.yml +++ b/core/modules/node/node.services.yml @@ -40,6 +40,7 @@ services: public: false tags: - { name: page_cache_response_policy } + - { name: dynamic_page_cache_response_policy } cache_context.user.node_grants: class: Drupal\node\Cache\NodeAccessGrantsCacheContext arguments: ['@current_user'] diff --git a/core/modules/node/tests/src/Functional/PagePreviewTest.php b/core/modules/node/tests/src/Functional/PagePreviewTest.php index 5597a4e147b459817e3871de60397c73ce96d642..8864e66fab6a84783954eaccef58dc7305993a6a 100644 --- a/core/modules/node/tests/src/Functional/PagePreviewTest.php +++ b/core/modules/node/tests/src/Functional/PagePreviewTest.php @@ -13,6 +13,7 @@ use Drupal\taxonomy\Entity\Vocabulary; use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\Tests\TestFileCreationTrait; +use Drupal\user\RoleInterface; /** * Tests the node entity preview functionality. @@ -500,4 +501,27 @@ public function testSimultaneousPreview() { $this->assertText($edit2[$title_key]); } + /** + * Tests node preview with dynamic_page_cache and anonymous users. + */ + public function testPagePreviewCache() { + \Drupal::service('module_installer')->uninstall(['node_test']); + $this->drupalLogout(); + $title_key = 'title[0][value]'; + user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['create page content', 'access content']); + $edit = [ + $title_key => $this->randomMachineName(8), + ]; + $this->drupalGet('/node/add/page'); + $this->submitForm($edit, 'Preview'); + $this->assertSession()->pageTextContains($edit[$title_key]); + $this->clickLink(t('Back to content editing')); + + $edit = [ + $title_key => $this->randomMachineName(8), + ]; + $this->submitForm($edit, 'Preview'); + $this->assertSession()->pageTextContains($edit[$title_key]); + } + }