comparison core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
7
8 /**
9 * Tests the node access automatic cacheability bubbling logic.
10 *
11 * @group node
12 * @group Cache
13 * @group cacheability_safeguards
14 */
15 class NodeAccessAutoBubblingTest extends NodeTestBase {
16
17 use AssertPageCacheContextsAndTagsTrait;
18
19 /**
20 * Modules to enable.
21 *
22 * @var array
23 */
24 public static $modules = ['node_access_test', 'node_access_test_auto_bubbling'];
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function setUp() {
30 parent::setUp();
31
32 node_access_rebuild();
33
34 // Create some content.
35 $this->drupalCreateNode();
36 $this->drupalCreateNode();
37 $this->drupalCreateNode();
38 $this->drupalCreateNode();
39 }
40
41 /**
42 * Tests that the node grants cache context is auto-added, only when needed.
43 *
44 * @see node_query_node_access_alter()
45 */
46 public function testNodeAccessCacheabilitySafeguard() {
47 $this->dumpHeaders = TRUE;
48
49 // The node grants cache context should be added automatically.
50 $this->drupalGet(new Url('node_access_test_auto_bubbling'));
51 $this->assertCacheContext('user.node_grants:view');
52
53 // The root user has the 'bypass node access' permission, which means the
54 // node grants cache context is not necessary.
55 $this->drupalLogin($this->rootUser);
56 $this->drupalGet(new Url('node_access_test_auto_bubbling'));
57 $this->assertNoCacheContext('user.node_grants:view');
58 $this->drupalLogout();
59
60 // Uninstall the module with the only hook_node_grants() implementation.
61 $this->container->get('module_installer')->uninstall(['node_access_test']);
62 $this->rebuildContainer();
63
64 // Because there are no node grants defined, there also is no need for the
65 // node grants cache context to be bubbled.
66 $this->drupalGet(new Url('node_access_test_auto_bubbling'));
67 $this->assertNoCacheContext('user.node_grants:view');
68 }
69
70 }