summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-12-29 14:51:49 -0500
committerDavid Rothstein <drothstein@gmail.com>2013-12-29 14:51:49 -0500
commitdf93dd273a4bda078dff60488388961d4d4da048 (patch)
treeb75d510ad204ecdd125b926c4fe20d48b6f20f8e
parentd453b28cbadaa5d6688837543c85dda8cc785047 (diff)
downloadbrdo-df93dd273a4bda078dff60488388961d4d4da048.tar.gz
brdo-df93dd273a4bda078dff60488388961d4d4da048.tar.bz2
Issue #1841900 by olli, herom, Sheldon Rampton: Node deletion should clear page cache.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--modules/node/node.admin.inc1
-rw-r--r--modules/node/node.pages.inc1
-rw-r--r--modules/node/node.test75
4 files changed, 79 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index db3aed9ba..b9a8daa56 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,8 @@
Drupal 7.25, xxxx-xx-xx (development version)
-----------------------
+- Fixed a bug in which caches were not properly cleared when a node was deleted
+ via the administrative interface.
- Changed the Bartik theme to render content contained in <pre>, <code> and
similar tags in a larger font size, so it is easier to read.
- Fixed a bug in the Search module that caused exceptions to be thrown during
diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc
index be09b37cc..0d0bbc091 100644
--- a/modules/node/node.admin.inc
+++ b/modules/node/node.admin.inc
@@ -695,6 +695,7 @@ function node_multiple_delete_confirm($form, &$form_state, $nodes) {
function node_multiple_delete_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
node_delete_multiple(array_keys($form_state['values']['nodes']));
+ cache_clear_all();
$count = count($form_state['values']['nodes']);
watchdog('content', 'Deleted @count posts.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index 75ed0ddb8..626746362 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -542,6 +542,7 @@ function node_delete_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
$node = node_load($form_state['values']['nid']);
node_delete($form_state['values']['nid']);
+ cache_clear_all();
watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title)));
}
diff --git a/modules/node/node.test b/modules/node/node.test
index b1d78fa1d..3cafefa1d 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -2755,3 +2755,78 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase {
$this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
}
}
+
+/**
+ * Tests the cache invalidation of node operations.
+ */
+class NodePageCacheTest extends NodeWebTestCase {
+
+ /**
+ * An admin user with administrative permissions for nodes.
+ */
+ protected $admin_user;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Node page cache test',
+ 'description' => 'Test cache invalidation of node operations.',
+ 'group' => 'Node',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ variable_set('cache', 1);
+ variable_set('page_cache_maximum_age', 300);
+
+ $this->admin_user = $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()->nid;
+
+ // Populate page cache.
+ $this->drupalGet($node_path);
+
+ // Login and delete the node.
+ $this->drupalLogin($this->admin_user);
+ $this->drupalPost($node_path . '/delete', array(), t('Delete'));
+
+ // Logout and check the node is not available.
+ $this->drupalLogout();
+ $this->drupalGet($node_path);
+ $this->assertResponse(404);
+
+ // Create two new nodes.
+ $nodes[0] = $this->drupalCreateNode();
+ $nodes[1] = $this->drupalCreateNode();
+ $node_path = 'node/' . $nodes[0]->nid;
+
+ // Populate page cache.
+ $this->drupalGet($node_path);
+
+ // Login and delete the nodes.
+ $this->drupalLogin($this->admin_user);
+ $this->drupalGet('admin/content');
+ $edit = array(
+ 'operation' => 'delete',
+ 'nodes[' . $nodes[0]->nid . ']' => TRUE,
+ 'nodes[' . $nodes[1]->nid . ']' => TRUE,
+ );
+ $this->drupalPost(NULL, $edit, t('Update'));
+ $this->drupalPost(NULL, array(), t('Delete'));
+
+ // Logout and check the node is not available.
+ $this->drupalLogout();
+ $this->drupalGet($node_path);
+ $this->assertResponse(404);
+ }
+}