Newer
Older
catch
committed
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\ShortcutCacheTagsTest.
*/
namespace Drupal\shortcut\Tests;
Angie Byron
committed
use Drupal\shortcut\Entity\Shortcut;
catch
committed
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
catch
committed
/**
* Tests the Shortcut entity's cache tags.
*
* @group shortcut
catch
committed
*/
class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('shortcut');
/**
* {@inheritdoc}
*/
Alex Pott
committed
protected function setUp() {
catch
committed
parent::setUp();
// Give anonymous users permission to customize shortcut links, so that we
// can verify the cache tags of cached versions of shortcuts.
$user_role = Role::load(DRUPAL_ANONYMOUS_RID);
catch
committed
$user_role->grantPermission('customize shortcut links');
Alex Pott
committed
$user_role->grantPermission('access shortcuts');
catch
committed
$user_role->save();
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Llama" shortcut.
Angie Byron
committed
$shortcut = Shortcut::create(array(
catch
committed
'set' => 'default',
'title' => t('Llama'),
'weight' => 0,
'path' => 'admin',
));
$shortcut->save();
return $shortcut;
}
/**
* Tests that when creating a shortcut, the shortcut set tag is invalidated.
*/
public function testEntityCreation() {
// Create a cache entry that is tagged with a shortcut set cache tag.
$cache_tags = ['config:shortcut.set.default'];
catch
committed
\Drupal::cache('render')->set('foo', 'bar', \Drupal\Core\Cache\CacheBackendInterface::CACHE_PERMANENT, $cache_tags);
// Verify a cache hit.
$this->verifyRenderCache('foo', $cache_tags);
catch
committed
// Now create a shortcut entity in that shortcut set.
$this->createEntity();
// Verify a cache miss.
$this->assertFalse(\Drupal::cache('render')->get('foo'), 'Creating a new shortcut invalidates the cache tag of the shortcut set.');
}
}