Issue #1841900 by olli, Sheldon Rampton: Fixed Node deletion should clear page cache.

8.0.x
Alex Pott 2013-10-14 01:22:44 +01:00
parent ddaeead03e
commit f805ecfc75
3 changed files with 94 additions and 0 deletions

View File

@ -7,6 +7,7 @@
namespace Drupal\node\Form; namespace Drupal\node\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityManager;
@ -123,6 +124,7 @@ class DeleteMultiple extends ConfirmFormBase implements ContainerInjectionInterf
$count = count($this->nodes); $count = count($this->nodes);
watchdog('content', 'Deleted @count posts.', array('@count' => $count)); watchdog('content', 'Deleted @count posts.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.')); drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
Cache::invalidateTags(array('content' => TRUE));
} }
$form_state['redirect'] = 'admin/content'; $form_state['redirect'] = 'admin/content';
} }

View File

@ -7,6 +7,7 @@
namespace Drupal\node\Form; namespace Drupal\node\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityConfirmFormBase; use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Routing\UrlGeneratorInterface;
@ -95,6 +96,7 @@ class NodeDeleteForm extends ContentEntityConfirmFormBase {
watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
$node_type = $this->nodeTypeStorage->load($this->entity->bundle())->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()))); 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'] = '<front>'; $form_state['redirect'] = '<front>';
} }

View File

@ -0,0 +1,90 @@
<?php
/**
* @file
* Contains \Drupal\node\Tests\NodePageCacheTest.
*/
namespace Drupal\node\Tests;
/**
* Tests the cache invalidation of node operations.
*/
class NodePageCacheTest extends NodeTestBase {
/**
* An admin user with administrative permissions for nodes.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
public static $modules = array('views');
public static function getInfo() {
return array(
'name' => '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);
}
}