NodeAccessCacheabilityTest.php in Drupal 8
File
core/modules/node/tests/src/Functional/NodeAccessCacheabilityTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Url;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
class NodeAccessCacheabilityTest extends NodeTestBase {
use AssertPageCacheContextsAndTagsTrait;
public static $modules = [
'node_access_test',
'node_access_test_auto_bubbling',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
node_access_rebuild();
$this
->drupalCreateNode();
$this
->drupalCreateNode();
$this
->drupalCreateNode();
$this
->drupalCreateNode();
}
public function testNodeAccessCacheabilitySafeguard() {
$this->dumpHeaders = TRUE;
$this
->drupalGet(new Url('node_access_test_auto_bubbling'));
$this
->assertCacheContext('user.node_grants:view');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet(new Url('node_access_test_auto_bubbling'));
$this
->assertNoCacheContext('user.node_grants:view');
$this
->drupalLogout();
$this->container
->get('module_installer')
->uninstall([
'node_access_test',
]);
$this
->rebuildContainer();
$this
->drupalGet(new Url('node_access_test_auto_bubbling'));
$this
->assertNoCacheContext('user.node_grants:view');
}
public function testNodeAccessCacheContext() {
$test_user1 = $this
->drupalCreateUser([
'access content',
'edit own page content',
'delete own page content',
]);
$this
->drupalLogin($test_user1);
$node1 = $this
->createNode([
'type' => 'page',
]);
$this
->drupalGet('node/' . $node1
->id() . '/edit');
$this
->assertCacheContext('user');
$this
->drupalGet('node/' . $node1
->id() . '/delete');
$this
->assertCacheContext('user');
$test_user2 = $this
->drupalCreateUser([
'access content',
]);
$this
->drupalLogin($test_user2);
$node2 = $this
->createNode([
'type' => 'page',
]);
$this
->drupalGet('node/' . $node2
->id() . '/edit');
$this
->assertCacheContext('user.permissions');
$this
->drupalGet('node/' . $node2
->id() . '/delete');
$this
->assertCacheContext('user.permissions');
}
}