You are here

class NodeCacheTagsTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeCacheTagsTest.php \Drupal\Tests\node\Functional\NodeCacheTagsTest
  2. 9 core/modules/node/tests/src/Functional/NodeCacheTagsTest.php \Drupal\Tests\node\Functional\NodeCacheTagsTest

Tests the Node entity's cache tags.

@group node

Hierarchy

Expanded class hierarchy of NodeCacheTagsTest

File

core/modules/node/tests/src/Functional/NodeCacheTagsTest.php, line 15

Namespace

Drupal\Tests\node\Functional
View source
class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function createEntity() {

    // Create a "Camelids" node type.
    NodeType::create([
      'name' => 'Camelids',
      'type' => 'camelids',
    ])
      ->save();

    // Create a "Llama" node.
    $node = Node::create([
      'type' => 'camelids',
    ]);
    $node
      ->setTitle('Llama')
      ->setPublished()
      ->save();
    return $node;
  }

  /**
   * {@inheritdoc}
   */
  protected function getAdditionalCacheContextsForEntity(EntityInterface $entity) {
    return [
      'timezone',
    ];
  }

  /**
   * {@inheritdoc}
   *
   * Each node must have an author.
   */
  protected function getAdditionalCacheTagsForEntity(EntityInterface $node) {
    return [
      'user:' . $node
        ->getOwnerId(),
      'user_view',
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getAdditionalCacheContextsForEntityListing() {
    return [
      'user.node_grants:view',
    ];
  }

}

Members