You are here

public function ItemCacheTagsTest::testEntityCreation in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php \Drupal\Tests\aggregator\Functional\ItemCacheTagsTest::testEntityCreation()

Tests that when creating a feed item, the feed tag is invalidated.

File

core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php, line 70

Class

ItemCacheTagsTest
Tests the Item entity's cache tags.

Namespace

Drupal\Tests\aggregator\Functional

Code

public function testEntityCreation() {

  // Create a cache entry that is tagged with a feed cache tag.
  \Drupal::cache('render')
    ->set('foo', 'bar', CacheBackendInterface::CACHE_PERMANENT, $this->entity
    ->getCacheTags());

  // Verify a cache hit.
  $this
    ->verifyRenderCache('foo', [
    'aggregator_feed:1',
  ]);

  // Now create a feed item in that feed.
  Item::create([
    'fid' => $this->entity
      ->getFeedId(),
    'title' => t('Llama 2'),
    'path' => 'https://groups.drupal.org/',
  ])
    ->save();

  // Verify a cache miss.
  $this
    ->assertFalse(\Drupal::cache('render')
    ->get('foo'), 'Creating a new feed item invalidates the cache tag of the feed.');
}