Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Functional / NodeCacheTagsTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\node\Entity\Node;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
9
10 /**
11  * Tests the Node entity's cache tags.
12  *
13  * @group node
14  */
15 class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['node'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function createEntity() {
26     // Create a "Camelids" node type.
27     NodeType::create([
28       'name' => 'Camelids',
29       'type' => 'camelids',
30     ])->save();
31
32     // Create a "Llama" node.
33     $node = Node::create(['type' => 'camelids']);
34     $node->setTitle('Llama')
35       ->setPublished()
36       ->save();
37
38     return $node;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   protected function getDefaultCacheContexts() {
45     $defaults = parent::getDefaultCacheContexts();
46     // @see \Drupal\node\Controller\NodeViewController::view()
47     $defaults[] = 'user.roles:anonymous';
48     return $defaults;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   protected function getAdditionalCacheContextsForEntity(EntityInterface $entity) {
55     return ['timezone'];
56   }
57
58   /**
59    * {@inheritdoc}
60    *
61    * Each node must have an author.
62    */
63   protected function getAdditionalCacheTagsForEntity(EntityInterface $node) {
64     return ['user:' . $node->getOwnerId(), 'user_view'];
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   protected function getAdditionalCacheContextsForEntityListing() {
71     return ['user.node_grants:view'];
72   }
73
74 }