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