ShortcutCacheTagsTest.php in Zircon Profile 8
File
core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php
View source
<?php
namespace Drupal\shortcut\Tests;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
public static $modules = array(
'shortcut',
);
protected function setUp() {
parent::setUp();
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
$user_role
->grantPermission('customize shortcut links');
$user_role
->grantPermission('access shortcuts');
$user_role
->save();
}
protected function createEntity() {
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('Llama'),
'weight' => 0,
'link' => [
[
'uri' => 'internal:/admin',
],
],
));
$shortcut
->save();
return $shortcut;
}
public function testEntityCreation() {
$cache_tags = [
'config:shortcut.set.default',
];
\Drupal::cache('render')
->set('foo', 'bar', \Drupal\Core\Cache\CacheBackendInterface::CACHE_PERMANENT, $cache_tags);
$this
->verifyRenderCache('foo', $cache_tags);
$this
->createEntity();
$this
->assertFalse(\Drupal::cache('render')
->get('foo'), 'Creating a new shortcut invalidates the cache tag of the shortcut set.');
}
}