ItemCacheTagsTest.php in Drupal 8
File
core/modules/aggregator/tests/src/Functional/ItemCacheTagsTest.php
View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
class ItemCacheTagsTest extends EntityCacheTagsTestBase {
public static $modules = [
'aggregator',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
$user_role
->grantPermission('access news feeds');
$user_role
->save();
}
protected function createEntity() {
$feed = Feed::create([
'title' => 'Camelids',
'url' => 'https://groups.drupal.org/not_used/167169',
'refresh' => 900,
'checked' => 1389919932,
'description' => 'Drupal Core Group feed',
]);
$feed
->save();
$item = Item::create([
'fid' => $feed
->id(),
'title' => t('Llama'),
'path' => 'https://www.drupal.org/',
]);
$item
->save();
return $item;
}
public function testEntityCreation() {
\Drupal::cache('render')
->set('foo', 'bar', CacheBackendInterface::CACHE_PERMANENT, $this->entity
->getCacheTags());
$this
->verifyRenderCache('foo', [
'aggregator_feed:1',
]);
Item::create([
'fid' => $this->entity
->getFeedId(),
'title' => t('Llama 2'),
'path' => 'https://groups.drupal.org/',
])
->save();
$this
->assertFalse(\Drupal::cache('render')
->get('foo'), 'Creating a new feed item invalidates the cache tag of the feed.');
}
}