Chris@18: drupalCreateNode(); Chris@18: $this->drupalCreateNode(); Chris@18: $this->drupalCreateNode(); Chris@18: $this->drupalCreateNode(); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Tests that the node grants cache context is auto-added, only when needed. Chris@18: * Chris@18: * @see node_query_node_access_alter() Chris@18: */ Chris@18: public function testNodeAccessCacheabilitySafeguard() { Chris@18: $this->dumpHeaders = TRUE; Chris@18: Chris@18: // The node grants cache context should be added automatically. Chris@18: $this->drupalGet(new Url('node_access_test_auto_bubbling')); Chris@18: $this->assertCacheContext('user.node_grants:view'); Chris@18: Chris@18: // The root user has the 'bypass node access' permission, which means the Chris@18: // node grants cache context is not necessary. Chris@18: $this->drupalLogin($this->rootUser); Chris@18: $this->drupalGet(new Url('node_access_test_auto_bubbling')); Chris@18: $this->assertNoCacheContext('user.node_grants:view'); Chris@18: $this->drupalLogout(); Chris@18: Chris@18: // Uninstall the module with the only hook_node_grants() implementation. Chris@18: $this->container->get('module_installer')->uninstall(['node_access_test']); Chris@18: $this->rebuildContainer(); Chris@18: Chris@18: // Because there are no node grants defined, there also is no need for the Chris@18: // node grants cache context to be bubbled. Chris@18: $this->drupalGet(new Url('node_access_test_auto_bubbling')); Chris@18: $this->assertNoCacheContext('user.node_grants:view'); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Tests that the user cache contexts are correctly set. Chris@18: */ Chris@18: public function testNodeAccessCacheContext() { Chris@18: // Create a user, with edit/delete own content permission. Chris@18: $test_user1 = $this->drupalCreateUser([ Chris@18: 'access content', Chris@18: 'edit own page content', Chris@18: 'delete own page content', Chris@18: ]); Chris@18: Chris@18: $this->drupalLogin($test_user1); Chris@18: Chris@18: $node1 = $this->createNode(['type' => 'page']); Chris@18: Chris@18: // User should be able to edit/delete their own content. Chris@18: // Therefore after the access check in node_node_access the user cache Chris@18: // context should be added. Chris@18: $this->drupalGet('node/' . $node1->id() . '/edit'); Chris@18: $this->assertCacheContext('user'); Chris@18: $this->drupalGet('node/' . $node1->id() . '/delete'); Chris@18: $this->assertCacheContext('user'); Chris@18: Chris@18: // Create a user without edit/delete permission. Chris@18: $test_user2 = $this->drupalCreateUser([ Chris@18: 'access content', Chris@18: ]); Chris@18: Chris@18: $this->drupalLogin($test_user2); Chris@18: Chris@18: $node2 = $this->createNode(['type' => 'page']); Chris@18: Chris@18: // The user shouldn't have access to the node edit/delete pages. Chris@18: // Therefore after the access check in node_node_access the user permissions Chris@18: // cache context should be added. Chris@18: $this->drupalGet('node/' . $node2->id() . '/edit'); Chris@18: $this->assertCacheContext('user.permissions'); Chris@18: $this->drupalGet('node/' . $node2->id() . '/delete'); Chris@18: $this->assertCacheContext('user.permissions'); Chris@18: } Chris@18: Chris@18: }