3 namespace Drupal\Tests\node\Functional;
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\node\Entity\Node;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
11 * Tests the Node entity's cache tags.
15 class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase {
20 public static $modules = ['node'];
25 protected function createEntity() {
26 // Create a "Camelids" node type.
32 // Create a "Llama" node.
33 $node = Node::create(['type' => 'camelids']);
34 $node->setTitle('Llama')
44 protected function getDefaultCacheContexts() {
45 $defaults = parent::getDefaultCacheContexts();
46 // @see \Drupal\node\Controller\NodeViewController::view()
47 $defaults[] = 'user.roles:anonymous';
54 protected function getAdditionalCacheContextsForEntity(EntityInterface $entity) {
61 * Each node must have an author.
63 protected function getAdditionalCacheTagsForEntity(EntityInterface $node) {
64 return ['user:' . $node->getOwnerId(), 'user_view'];
70 protected function getAdditionalCacheContextsForEntityListing() {
71 return ['user.node_grants:view'];