3 namespace Drupal\Tests\aggregator\Functional;
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\aggregator\Entity\Item;
7 use Drupal\Core\Cache\CacheBackendInterface;
8 use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
9 use Drupal\user\Entity\Role;
10 use Drupal\user\RoleInterface;
13 * Tests the Item entity's cache tags.
17 class ItemCacheTagsTest extends EntityCacheTagsTestBase {
22 public static $modules = ['aggregator'];
27 protected function setUp() {
30 // Give anonymous users permission to access feeds, so that we can verify
31 // the cache tags of cached versions of feed items.
32 $user_role = Role::load(RoleInterface::ANONYMOUS_ID);
33 $user_role->grantPermission('access news feeds');
40 protected function createEntity() {
41 // Create a "Camelids" feed.
42 $feed = Feed::create([
43 'title' => 'Camelids',
44 'url' => 'https://groups.drupal.org/not_used/167169',
46 'checked' => 1389919932,
47 'description' => 'Drupal Core Group feed',
51 // Create a "Llama" aggregator feed item.
52 $item = Item::create([
54 'title' => t('Llama'),
55 'path' => 'https://www.drupal.org/',
63 * Tests that when creating a feed item, the feed tag is invalidated.
65 public function testEntityCreation() {
66 // Create a cache entry that is tagged with a feed cache tag.
67 \Drupal::cache('render')->set('foo', 'bar', CacheBackendInterface::CACHE_PERMANENT, $this->entity->getCacheTags());
69 // Verify a cache hit.
70 $this->verifyRenderCache('foo', ['aggregator_feed:1']);
72 // Now create a feed item in that feed.
74 'fid' => $this->entity->getFeedId(),
75 'title' => t('Llama 2'),
76 'path' => 'https://groups.drupal.org/',
79 // Verify a cache miss.
80 $this->assertFalse(\Drupal::cache('render')->get('foo'), 'Creating a new feed item invalidates the cache tag of the feed.');