function ShortcutCacheTagsTest::testEntityCreation

Tests that when creating a shortcut, the shortcut set tag is invalidated.

File

core/modules/shortcut/tests/src/Kernel/ShortcutCacheTagsTest.php, line 93

Class

ShortcutCacheTagsTest
Tests the Shortcut entity's cache tags.

Namespace

Drupal\Tests\shortcut\Kernel

Code

public function testEntityCreation() : void {
  $cache_bin = $this->getDefaultVariationCache();
  // Create a cache entry that is tagged with a shortcut set cache tag.
  $cache_tags = [
    'config:shortcut.set.' . $this->shortcutSet
      ->id(),
  ];
  $cacheability = new CacheableMetadata();
  $cacheability->addCacheTags($cache_tags);
  $cache_bin->set([
    'foo',
  ], 'bar', $cacheability, $cacheability);
  // Verify a cache hit.
  $this->verifyDefaultCache([
    'foo',
  ], $cache_tags, $cacheability);
  // Now create a shortcut entity in that shortcut set.
  $this->createShortcutEntity();
  // Verify a cache miss.
  $this->assertFalse($cache_bin->get([
    'foo',
  ], $cacheability), 'Creating a new shortcut invalidates the cache tag of the shortcut set.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.