diff --git a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php index 3d94f52..e5ef136 100644 --- a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php +++ b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php @@ -7,6 +7,7 @@ namespace Drupal\node\Form; +use Drupal\Core\Cache\Cache; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityManager; @@ -123,6 +124,7 @@ public function submitForm(array &$form, array &$form_state) { $count = count($this->nodes); watchdog('content', 'Deleted @count posts.', array('@count' => $count)); drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.')); + Cache::invalidateTags(array('content' => TRUE)); } $form_state['redirect'] = 'admin/content'; } diff --git a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php index e6e469a..11eb3f3 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php @@ -7,6 +7,7 @@ namespace Drupal\node\Form; +use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\ContentEntityConfirmFormBase; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; @@ -95,6 +96,7 @@ public function submit(array $form, array &$form_state) { watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); $node_type = $this->nodeTypeStorage->load($this->entity->bundle())->label(); drupal_set_message(t('@type %title has been deleted.', array('@type' => $node_type, '%title' => $this->entity->label()))); + Cache::invalidateTags(array('content' => TRUE)); $form_state['redirect'] = ''; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodePageCacheTest.php b/core/modules/node/lib/Drupal/node/Tests/NodePageCacheTest.php new file mode 100644 index 0000000..4a2385c --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodePageCacheTest.php @@ -0,0 +1,90 @@ + 'Node page cache test', + 'description' => 'Test cache invalidation of node operations.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(); + + $this->container->get('config.factory')->get('system.performance') + ->set('cache.page.use_internal', 1) + ->set('cache.page.max_age', 300) + ->save(); + + $this->adminUser = $this->drupalCreateUser(array( + 'bypass node access', + 'access content overview', + 'administer nodes', + )); + } + + /** + * Tests deleting nodes clears page cache. + */ + public function testNodeDelete() { + $node_path = 'node/' . $this->drupalCreateNode()->id(); + + // Populate page cache. + $this->drupalGet($node_path); + + // Login and delete the node. + $this->drupalLogin($this->adminUser); + $this->drupalGet($node_path . '/delete'); + $this->drupalPostForm(NULL, array(), t('Delete')); + + // Logout and check the node is not available. + $this->drupalLogout(); + $this->drupalGet($node_path); + $this->assertResponse(404); + + // Create two new nodes. + $this->drupalCreateNode(); + $node_path = 'node/' . $this->drupalCreateNode()->id(); + + // Populate page cache. + $this->drupalGet($node_path); + + // Login and delete the nodes. + $this->drupalLogin($this->adminUser); + $this->drupalGet('admin/content'); + $edit = array( + 'action' => 'node_delete_action', + 'node_bulk_form[0]' => 1, + 'node_bulk_form[1]' => 1, + ); + $this->drupalPostForm(NULL, $edit, t('Apply')); + $this->drupalPostForm(NULL, array(), t('Delete')); + + // Logout and check the node is not available. + $this->drupalLogout(); + $this->drupalGet($node_path); + $this->assertResponse(404); + } + +}