.../Core/Asset/LibraryDiscoveryCollector.php | 2 +- core/lib/Drupal/Core/Cache/ApcuBackend.php | 37 +++-------------- core/lib/Drupal/Core/Cache/Cache.php | 39 +++++++++++++----- core/lib/Drupal/Core/Cache/CacheCollector.php | 3 +- core/lib/Drupal/Core/Cache/DatabaseBackend.php | 3 ++ core/lib/Drupal/Core/Cache/MemoryBackend.php | 1 + core/lib/Drupal/Core/Cache/PhpBackend.php | 1 + core/lib/Drupal/Core/Config/CachedStorage.php | 8 ++-- core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 4 +- .../MenuRouterRebuildSubscriber.php | 2 +- core/lib/Drupal/Core/Extension/ThemeHandler.php | 2 +- core/lib/Drupal/Core/Menu/MenuTreeStorage.php | 2 +- .../Drupal/Core/Plugin/DefaultPluginManager.php | 1 + core/lib/Drupal/Core/Theme/Registry.php | 6 +-- .../src/Tests/AggregatorRenderingTest.php | 8 ++-- core/modules/block/src/Tests/BlockTest.php | 29 +++++++------ core/modules/breakpoint/src/BreakpointManager.php | 4 +- .../src/Tests/EditorFileReferenceFilterTest.php | 13 +++--- .../src/Tests/EntityReferenceFormatterTest.php | 15 ++++--- core/modules/filter/filter.module | 2 +- core/modules/filter/src/FilterProcessResult.php | 3 +- core/modules/filter/src/Tests/FilterAPITest.php | 10 ++--- .../src/Plugin/Filter/FilterTestCacheTags.php | 4 +- .../src/Plugin/Block/SystemBrandingBlock.php | 6 +-- .../system/src/Tests/Bootstrap/PageCacheTest.php | 10 ++--- .../src/Tests/Cache/DatabaseBackendTagTest.php | 8 ++-- .../Cache/GenericCacheBackendUnitTestBase.php | 48 +++++++++++----------- .../system/src/Tests/Theme/RegistryTest.php | 4 +- .../src/Controller/SystemTestController.php | 2 +- .../text/src/Tests/Formatter/TextFormatterTest.php | 6 +-- .../toolbar/src/Tests/ToolbarAdminMenuTest.php | 2 +- .../src/Plugin/views/cache/CachePluginBase.php | 4 +- .../Core/Asset/LibraryDiscoveryCollectorTest.php | 2 +- .../Drupal/Tests/Core/Cache/CacheCollectorTest.php | 2 +- .../Tests/Core/Menu/LocalTaskIntegrationTest.php | 2 +- .../Tests/Core/Menu/LocalTaskManagerTest.php | 4 +- .../Tests/Core/Plugin/DefaultPluginManagerTest.php | 4 +- 37 files changed, 151 insertions(+), 152 deletions(-) diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php index e174a17..dfac4fa 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php @@ -57,7 +57,7 @@ class LibraryDiscoveryCollector extends CacheCollector { * The library discovery parser. */ public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, LibraryDiscoveryParser $discovery_parser) { - parent::__construct($this->cacheKey, $cache, $lock, array($this->cacheKey => array(TRUE))); + parent::__construct($this->cacheKey, $cache, $lock, array($this->cacheKey)); $this->discoveryParser = $discovery_parser; } diff --git a/core/lib/Drupal/Core/Cache/ApcuBackend.php b/core/lib/Drupal/Core/Cache/ApcuBackend.php index 0ec166f..f787401 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackend.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackend.php @@ -189,11 +189,12 @@ protected function prepareItem($cache, $allow_invalid) { * {@inheritdoc} */ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) { + Cache::validateTags($tags); $cache = new \stdClass(); $cache->cid = $cid; $cache->created = round(microtime(TRUE), 3); $cache->expire = $expire; - $cache->tags = implode(' ', $this->flattenTags($tags)); + $cache->tags = implode(' ', $tags); $checksum = $this->checksumTags($tags); $cache->checksum_invalidations = $checksum['invalidations']; $cache->checksum_deletions = $checksum['deletions']; @@ -285,7 +286,7 @@ public function invalidateAll() { * {@inheritdoc} */ public function deleteTags(array $tags) { - foreach ($this->flattenTags($tags) as $tag) { + foreach ($tags as $tag) { apc_inc($this->deletionsTagsPrefix . $tag, 1, $success); if (!$success) { apc_store($this->deletionsTagsPrefix . $tag, 1); @@ -297,7 +298,7 @@ public function deleteTags(array $tags) { * {@inheritdoc} */ public function invalidateTags(array $tags) { - foreach ($this->flattenTags($tags) as $tag) { + foreach ($tags as $tag) { apc_inc($this->invalidationsTagsPrefix . $tag, 1, $success); if (!$success) { apc_store($this->invalidationsTagsPrefix . $tag, 1); @@ -306,34 +307,6 @@ public function invalidateTags(array $tags) { } /** - * Flattens a tags array into a numeric array suitable for string storage. - * - * @param array $tags - * Associative array of tags to flatten. - * - * @return array - * Indexed array of flattened tag identifiers. - */ - protected function flattenTags(array $tags) { - if (isset($tags[0])) { - return $tags; - } - - $flat_tags = array(); - foreach ($tags as $namespace => $values) { - if (is_array($values)) { - foreach ($values as $value) { - $flat_tags[] = "$namespace:$value"; - } - } - else { - $flat_tags[] = "$namespace:$values"; - } - } - return $flat_tags; - } - - /** * Returns the sum total of validations for a given set of tags. * * @param array $tags @@ -346,7 +319,7 @@ protected function checksumTags(array $tags) { $checksum = array('invalidations' => 0, 'deletions' => 0); $query_tags = array('invalidations' => array(), 'deletions' => array()); - foreach ($this->flattenTags($tags) as $tag) { + foreach ($tags as $tag) { foreach (array('deletions', 'invalidations') as $type) { if (isset(static::$tagCache[$type][$tag])) { $checksum[$type] += static::$tagCache[$type][$tag]; diff --git a/core/lib/Drupal/Core/Cache/Cache.php b/core/lib/Drupal/Core/Cache/Cache.php index 895d8ec..68d316c 100644 --- a/core/lib/Drupal/Core/Cache/Cache.php +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -22,7 +22,7 @@ class Cache { const PERMANENT = CacheBackendInterface::CACHE_PERMANENT; /** - * Merges sets of cache tags. + * Merges arrays of cache tags. * * The cache tags array is returned in a format that is valid for * \Drupal\Core\Cache\CacheBackendInterface::set(). @@ -40,18 +40,35 @@ class Cache { */ public static function mergeTags() { $cache_tag_arrays = func_get_args(); - $result = []; + $cache_tags = []; foreach ($cache_tag_arrays as $tags) { - foreach ($tags as $value) { - if (!is_string($value)) { - throw new \LogicException('Cache tags must be strings, ' . gettype($value) . ' given.'); - } + static::validateTags($tags); + $cache_tags = array_merge($cache_tags, $tags); + } + $cache_tags = array_unique($cache_tags); + sort($cache_tags); + return $cache_tags; + } + + /** + * Validates an array of cache tags. + * + * Can be called before using cache tags in operations, to ensure validity. + * + * @param array $tags + * An array of cache tags. + * + * @throws \LogicException + */ + public static function validateTags(array $tags) { + if (empty($tags)) { + return; + } + foreach ($tags as $value) { + if (!is_string($value)) { + throw new \LogicException('Cache tags must be strings, ' . gettype($value) . ' given.'); } - $result = array_merge($result, $tags); } - $result = array_unique($result); - sort($result); - return $result; } /** @@ -68,6 +85,7 @@ public static function mergeTags() { * The list of tags to delete cache items for. */ public static function deleteTags(array $tags) { + static::validateTags($tags); foreach (static::getBins() as $cache_backend) { $cache_backend->deleteTags($tags); } @@ -87,6 +105,7 @@ public static function deleteTags(array $tags) { * The list of tags to invalidate cache items for. */ public static function invalidateTags(array $tags) { + static::validateTags($tags); foreach (static::getBins() as $cache_backend) { $cache_backend->invalidateTags($tags); } diff --git a/core/lib/Drupal/Core/Cache/CacheCollector.php b/core/lib/Drupal/Core/Cache/CacheCollector.php index b90327e..d1689af 100644 --- a/core/lib/Drupal/Core/Cache/CacheCollector.php +++ b/core/lib/Drupal/Core/Cache/CacheCollector.php @@ -114,7 +114,8 @@ * @param array $tags * (optional) The tags to specify for the cache item. */ - public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, $tags = array()) { + public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, array $tags = array()) { + Cache::validateTags($tags); $this->cid = $cid; $this->cache = $cache; $this->tags = $tags; diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index 250a8a9..b243967 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -147,6 +147,7 @@ protected function prepareItem($cache, $allow_invalid) { * Implements Drupal\Core\Cache\CacheBackendInterface::set(). */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { + Cache::validateTags($tags); $try_again = FALSE; try { // The bin might not yet exist. @@ -233,6 +234,8 @@ public function setMultiple(array $items) { 'tags' => array(), ); + Cache::validateTags($item['tags']); + // Remove tags that were already deleted or invalidated during this // request from the static caches so that another deletion or // invalidation can occur. diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index 34f2853..a8814ac 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -107,6 +107,7 @@ protected function prepareItem($cache, $allow_invalid) { * Implements Drupal\Core\Cache\CacheBackendInterface::set(). */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { + Cache::validateTags($tags); $this->cache[$cid] = (object) array( 'cid' => $cid, 'data' => serialize($data), diff --git a/core/lib/Drupal/Core/Cache/PhpBackend.php b/core/lib/Drupal/Core/Cache/PhpBackend.php index 3ac9934..26117f3 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackend.php +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php @@ -140,6 +140,7 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array 'expire' => $expire, 'tags' => $tags, ); + Cache::validateTags($item['tags']); $this->writeItem($this->normalizeCid($cid), $item); } diff --git a/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php index 0b089ca..b657f66 100644 --- a/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -131,7 +131,7 @@ public function write($name, array $data) { // While not all written data is read back, setting the cache instead of // just deleting it avoids cache rebuild stampedes. $this->cache->set($this->getCacheKey($name), $data); - Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); + Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG)); $this->findByPrefixCache = array(); return TRUE; } @@ -146,7 +146,7 @@ public function delete($name) { // rebuilding the cache before the storage is gone. if ($this->storage->delete($name)) { $this->cache->delete($this->getCacheKey($name)); - Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); + Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG)); $this->findByPrefixCache = array(); return TRUE; } @@ -162,7 +162,7 @@ public function rename($name, $new_name) { if ($this->storage->rename($name, $new_name)) { $this->cache->delete($this->getCacheKey($name)); $this->cache->delete($this->getCacheKey($new_name)); - Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); + Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG)); $this->findByPrefixCache = array(); return TRUE; } @@ -224,7 +224,7 @@ protected function findByPrefix($prefix) { 'find:' . $cache_key, $this->findByPrefixCache[$cache_key], Cache::PERMANENT, - array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE) + array($this::FIND_BY_PREFIX_CACHE_TAG) ); } } diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 3bfe032..e989182 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -352,9 +352,9 @@ public function getCacheTag() { public function resetCache(array $entities = NULL) { if (isset($entities)) { // Always invalidate the ENTITY_TYPE_list tag. - $tags = array($this->entityTypeId . '_list' => TRUE); + $tags = array($this->entityTypeId . '_list'); foreach ($entities as $entity) { - $tags = NestedArray::mergeDeep($tags, $entity->getCacheTag()); + $tags = Cache::mergeTags($tags, $entity->getCacheTag()); } Cache::invalidateTags($tags); } diff --git a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php index 4b0b41f..41b5a87 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @@ -57,7 +57,7 @@ public function __construct(LockBackendInterface $lock, MenuLinkManagerInterface */ public function onRouterRebuild(Event $event) { $this->menuLinksRebuild(); - Cache::deleteTags(array('local_task' => 1)); + Cache::deleteTags(array('local_task')); } /** diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index a4a086a..0425df5 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -643,7 +643,7 @@ protected function resetSystem() { // @todo It feels wrong to have the requirement to clear the local tasks // cache here. - Cache::deleteTags(array('local_task' => 1)); + Cache::deleteTags(array('local_task')); $this->themeRegistryRebuild(); } diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index 422ec5c..b7e525f 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -845,7 +845,7 @@ public function loadTreeData($menu_name, MenuTreeParameters $parameters) { $data['tree'] = $this->doBuildTreeData($links, $parameters->activeTrail, $parameters->minDepth); $data['definitions'] = array(); $data['route_names'] = $this->collectRoutesAndDefinitions($data['tree'], $data['definitions']); - $this->menuCacheBackend->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name)); + $this->menuCacheBackend->set($tree_cid, $data, Cache::PERMANENT, array('menu:' . $menu_name)); // The definitions were already added to $this->definitions in // $this->doBuildTreeData() unset($data['definitions']); diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index a2d4cf2..5828d33 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -125,6 +125,7 @@ public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInte * definitions should be cleared along with other, related cache entries. */ public function setCacheBackend(CacheBackendInterface $cache_backend, $cache_key, array $cache_tags = array()) { + Cache::validateTags($cache_tags); $this->cacheBackend = $cache_backend; $this->cacheKey = $cache_key; $this->cacheTags = $cache_tags; diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 59f9761..da3122c 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -235,7 +235,7 @@ public function get() { public function getRuntime() { $this->init($this->themeName); if (!isset($this->runtimeRegistry)) { - $this->runtimeRegistry = new ThemeRegistry('theme_registry:runtime:' . $this->theme->getName(), $this->cache, $this->lock, array('theme_registry' => TRUE), $this->moduleHandler->isLoaded()); + $this->runtimeRegistry = new ThemeRegistry('theme_registry:runtime:' . $this->theme->getName(), $this->cache, $this->lock, array('theme_registry'), $this->moduleHandler->isLoaded()); } return $this->runtimeRegistry; } @@ -244,7 +244,7 @@ public function getRuntime() { * Persists the theme registry in the cache backend. */ protected function setCache() { - $this->cache->set('theme_registry:' . $this->theme->getName(), $this->registry, Cache::PERMANENT, array('theme_registry' => TRUE)); + $this->cache->set('theme_registry:' . $this->theme->getName(), $this->registry, Cache::PERMANENT, array('theme_registry')); } /** @@ -318,7 +318,7 @@ protected function build() { } // Only cache this registry if all modules are loaded. if ($this->moduleHandler->isLoaded()) { - $this->cache->set("theme_registry:build:modules", $cache, Cache::PERMANENT, array('theme_registry' => TRUE)); + $this->cache->set("theme_registry:build:modules", $cache, Cache::PERMANENT, array('theme_registry')); } } diff --git a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php index d967d1b..22515a3 100644 --- a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php +++ b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php @@ -67,8 +67,8 @@ public function testBlockLinks() { $this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.'); $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); $this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags)); - $this->assertTrue(in_array('aggregator_feed_view:1', $cache_tags)); - $this->assertTrue(in_array('aggregator_item_view:1', $cache_tags)); + $this->assertTrue(in_array('aggregator_feed_view', $cache_tags)); + $this->assertTrue(in_array('aggregator_item_view', $cache_tags)); // Set the number of news items to 0 to test that the block does not show // up. @@ -119,8 +119,8 @@ public function testFeedPage() { $this->assertTrue(!empty($elements), 'Individual source page contains a pager.'); $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); $this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags)); - $this->assertTrue(in_array('aggregator_feed_view:1', $cache_tags)); - $this->assertTrue(in_array('aggregator_item_view:1', $cache_tags)); + $this->assertTrue(in_array('aggregator_feed_view', $cache_tags)); + $this->assertTrue(in_array('aggregator_item_view', $cache_tags)); } } diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php index 6240fcd..c560236 100644 --- a/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -294,21 +294,23 @@ public function testBlockCacheTags() { $cache_entry = \Drupal::cache('render')->get($cid); $expected_cache_tags = array( 'theme:stark', - 'theme_global_settings:1', - 'block_view:1', + 'theme_global_settings', + 'block_view', 'block:powered', 'block_plugin:system_powered_by_block', - 'rendered:1', + 'rendered', ); + sort($expected_cache_tags); $this->assertIdentical($cache_entry->tags, $expected_cache_tags); $cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:en:stark'); $expected_cache_tags = array( - 'block_view:1', + 'block_view', 'block:powered', 'theme:stark', 'block_plugin:system_powered_by_block', - 'rendered:1', + 'rendered', ); + sort($expected_cache_tags); $this->assertIdentical($cache_entry->tags, $expected_cache_tags); // The "Powered by Drupal" block is modified; verify a cache miss. @@ -334,30 +336,33 @@ public function testBlockCacheTags() { $cache_entry = \Drupal::cache('render')->get($cid); $expected_cache_tags = array( 'theme:stark', - 'theme_global_settings:1', - 'block_view:1', + 'theme_global_settings', + 'block_view', 'block:powered-2', 'block:powered', 'block_plugin:system_powered_by_block', - 'rendered:1', + 'rendered', ); + sort($expected_cache_tags); $this->assertEqual($cache_entry->tags, $expected_cache_tags); $expected_cache_tags = array( - 'block_view:1', + 'block_view', 'block:powered', 'theme:stark', 'block_plugin:system_powered_by_block', - 'rendered:1', + 'rendered', ); + sort($expected_cache_tags); $cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:en:stark'); $this->assertIdentical($cache_entry->tags, $expected_cache_tags); $expected_cache_tags = array( - 'block_view:1', + 'block_view', 'block:powered-2', 'theme:stark', 'block_plugin:system_powered_by_block', - 'rendered:1', + 'rendered', ); + sort($expected_cache_tags); $cache_entry = \Drupal::cache('render')->get('entity_view:block:powered-2:en:stark'); $this->assertIdentical($cache_entry->tags, $expected_cache_tags); diff --git a/core/modules/breakpoint/src/BreakpointManager.php b/core/modules/breakpoint/src/BreakpointManager.php index 289170b..3187912 100644 --- a/core/modules/breakpoint/src/BreakpointManager.php +++ b/core/modules/breakpoint/src/BreakpointManager.php @@ -176,7 +176,7 @@ public function getBreakpointsByGroup($group) { } } uasort($breakpoints, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); - $this->cacheBackend->set($this->cacheKey . ':' . $group, $breakpoints, Cache::PERMANENT, array('breakpoints' => TRUE)); + $this->cacheBackend->set($this->cacheKey . ':' . $group, $breakpoints, Cache::PERMANENT, array('breakpoints')); $this->breakpointsByGroup[$group] = $breakpoints; } } @@ -205,7 +205,7 @@ public function getGroups() { $groups[$plugin_definition['group']] = $plugin_definition['group']; } } - $this->cacheBackend->set($this->cacheKey . '::groups', $groups, Cache::PERMANENT, array('breakpoints' => TRUE)); + $this->cacheBackend->set($this->cacheKey . '::groups', $groups, Cache::PERMANENT, array('breakpoints')); } // Get the labels. This is not cacheable due to translation. $group_labels = array(); diff --git a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php index e03066e..7fa1813 100644 --- a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php +++ b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php @@ -7,6 +7,7 @@ namespace Drupal\editor\Tests; +use Drupal\Core\Cache\Cache; use Drupal\simpletest\KernelTestBase; use Drupal\filter\FilterBag; @@ -58,12 +59,14 @@ function testEditorFileReferenceFilter() { $image->save(); $id = $image->id(); $uuid = $image->uuid(); + $cache_tag = ['file:' . $id]; file_put_contents('public://alpaca.jpg', $this->randomMachineName()); $image_2 = entity_create('file', array('uri' => 'public://alpaca.jpg')); $image_2->save(); $id_2 = $image_2->id(); $uuid_2 = $image_2->uuid(); + $cache_tag_2 = ['file:' . $id_2]; $this->pass('No data-editor-file-uuid attribute.'); $input = ''; @@ -74,19 +77,19 @@ function testEditorFileReferenceFilter() { $input = ''; $output = $test($input); $this->assertIdentical($input, $output->getProcessedText()); - $this->assertEqual(array('file' => array($id)), $output->getCacheTags()); + $this->assertEqual($cache_tag, $output->getCacheTags()); $this->pass('One data-editor-file-uuid attribute with odd capitalization.'); $input = ''; $output = $test($input); $this->assertIdentical($input, $output->getProcessedText()); - $this->assertEqual(array('file' => array($id)), $output->getCacheTags()); + $this->assertEqual($cache_tag, $output->getCacheTags()); $this->pass('One data-editor-file-uuid attribute on a non-image tag.'); $input = ''; $output = $test($input); $this->assertIdentical($input, $output->getProcessedText()); - $this->assertEqual(array('file' => array($id)), $output->getCacheTags()); + $this->assertEqual($cache_tag, $output->getCacheTags()); $this->pass('One data-editor-file-uuid attribute with an invalid value.'); $input = ''; @@ -99,14 +102,14 @@ function testEditorFileReferenceFilter() { $input .= ''; $output = $test($input); $this->assertIdentical($input, $output->getProcessedText()); - $this->assertEqual(array('file' => array($id, $id_2)), $output->getCacheTags()); + $this->assertEqual(Cache::mergeTags($cache_tag, $cache_tag_2), $output->getCacheTags()); $this->pass('Two identical data-editor-file-uuid attributes.'); $input = ''; $input .= ''; $output = $test($input); $this->assertIdentical($input, $output->getProcessedText()); - $this->assertEqual(array('file' => array($id)), $output->getCacheTags()); + $this->assertEqual($cache_tag, $output->getCacheTags()); } } diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php index 33b4af0..ed4d65e 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php @@ -7,6 +7,8 @@ namespace Drupal\entity_reference\Tests; +use Drupal\Core\Cache\Cache; +use Drupal\filter\Entity\FilterFormat; use Drupal\system\Tests\Entity\EntityUnitTestBase; /** @@ -141,10 +143,7 @@ public function testIdFormatter() { $build = $items->view(array('type' => $formatter)); $this->assertEqual($build[0]['#markup'], $this->referencedEntity->id(), format_string('The markup returned by the @formatter formatter is correct.', array('@formatter' => $formatter))); - $expected_cache_tags = array( - $this->entityType => array($this->referencedEntity->id()), - ); - $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter))); + $this->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity->getCacheTag(), format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter))); } @@ -180,10 +179,10 @@ public function testEntityFormatter() { '; drupal_render($build[0]); $this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field . $expected_rendered_body_field, format_string('The markup returned by the @formatter formatter is correct.', array('@formatter' => $formatter))); - $expected_cache_tags = array( - $this->entityType . '_view' => TRUE, - $this->entityType => array($this->referencedEntity->id()), - 'filter_format' => array('full_html' => 'full_html'), + $expected_cache_tags = Cache::mergeTags( + \Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTag(), + $this->referencedEntity->getCacheTag(), + FilterFormat::load('full_html')->getCacheTag() ); $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter))); } diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 39da725..320f492 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -250,7 +250,7 @@ function filter_formats(AccountInterface $account = NULL) { else { $formats['all'] = \Drupal::entityManager()->getStorage('filter_format')->loadByProperties(array('status' => TRUE)); uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); - \Drupal::cache()->set("filter_formats:{$language_interface->id}", $formats['all'], Cache::PERMANENT, array('filter_formats' => TRUE)); + \Drupal::cache()->set("filter_formats:{$language_interface->id}", $formats['all'], Cache::PERMANENT, array('filter_formats')); } } diff --git a/core/modules/filter/src/FilterProcessResult.php b/core/modules/filter/src/FilterProcessResult.php index 71edc45..5597271 100644 --- a/core/modules/filter/src/FilterProcessResult.php +++ b/core/modules/filter/src/FilterProcessResult.php @@ -8,6 +8,7 @@ namespace Drupal\filter; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Cache\Cache; /** * Used to return values from a text filter plugin's processing method. @@ -155,7 +156,7 @@ public function getCacheTags() { * @return $this */ public function addCacheTags(array $cache_tags) { - $this->cacheTags = drupal_merge_attached($this->cacheTags, $cache_tags); + $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags); return $this; } diff --git a/core/modules/filter/src/Tests/FilterAPITest.php b/core/modules/filter/src/Tests/FilterAPITest.php index 7c513a4..b09bfb2 100644 --- a/core/modules/filter/src/Tests/FilterAPITest.php +++ b/core/modules/filter/src/Tests/FilterAPITest.php @@ -246,14 +246,10 @@ function testProcessedTextElement() { $this->assertEqual($expected_assets, $build['#attached'], 'Expected assets present'); $expected_cache_tags = array( // The cache tag set by the processed_text element itself. - 'filter_format' => array( - 'element_test', - ), + 'filter_format:element_test', // The cache tags set by the filter_test_cache_tags filter. - 'foo' => array( - 'bar', - 'baz', - ), + 'foo:bar', + 'foo:baz', ); $this->assertEqual($expected_cache_tags, $build['#cache']['tags'], 'Expected cache tags present.'); $expected_markup = '
Hello, world!
This is a dynamic llama.
'; diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php index 3c03c3f..aa04616 100644 --- a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php +++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php @@ -27,8 +27,8 @@ class FilterTestCacheTags extends FilterBase { */ public function process($text, $langcode) { $result = new FilterProcessResult($text); - $result->addCacheTags(array('foo' => array('bar'))); - $result->addCacheTags(array('foo' => array('baz'))); + $result->addCacheTags(array('foo:bar')); + $result->addCacheTags(array('foo:baz')); return $result; } diff --git a/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php b/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php index f50a287..e65109e 100644 --- a/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -192,10 +193,7 @@ public function build() { public function getCacheTags() { // The theme-specific cache tag is set automatically for each block, but the // output of this block also depends on the global theme settings. - $tags = array( - 'theme_global_setting' => TRUE, - ); - return NestedArray::mergeDeep(parent::getCacheTags(), $tags); + return Cache::mergeTags(parent::getCacheTags(), ['theme_global_setting']); } /** diff --git a/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php index 262be48..ebf2b97 100644 --- a/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php @@ -50,7 +50,7 @@ function testPageCacheTags() { $config->save(); $path = 'system-test/cache_tags_page'; - $tags = array('system_test_cache_tags_page' => TRUE); + $tags = array('system_test_cache_tags_page'); $this->drupalGet($path); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); @@ -62,11 +62,11 @@ function testPageCacheTags() { $cache_entry = \Drupal::cache('render')->get($cid); sort($cache_entry->tags); $expected_tags = array( - 'pre_render:1', - 'rendered:1', - 'system_test_cache_tags_page:1', + 'pre_render', + 'rendered', + 'system_test_cache_tags_page', 'theme:stark', - 'theme_global_settings:1', + 'theme_global_settings', ); $this->assertIdentical($cache_entry->tags, $expected_tags); diff --git a/core/modules/system/src/Tests/Cache/DatabaseBackendTagTest.php b/core/modules/system/src/Tests/Cache/DatabaseBackendTagTest.php index e654dc2..c832ded 100644 --- a/core/modules/system/src/Tests/Cache/DatabaseBackendTagTest.php +++ b/core/modules/system/src/Tests/Cache/DatabaseBackendTagTest.php @@ -40,7 +40,7 @@ public function containerBuild(ContainerBuilder $container) { public function testTagInvalidations() { // Create cache entry in multiple bins. - $tags = array('test_tag' => array(1, 2, 3)); + $tags = array('test_tag:1', 'test_tag:2', 'test_tag:3'); $bins = array('data', 'bootstrap', 'render'); foreach ($bins as $bin) { $bin = \Drupal::cache($bin); @@ -62,9 +62,9 @@ public function testTagInvalidations() { $this->assertEqual($invalidations_after, $invalidations_before + 1, 'Only one addition cache tag invalidation has occurred after invalidating a tag used in multiple bins.'); } - public function testTagDeletetions() { + public function testTagDeletions() { // Create cache entry in multiple bins. - $tags = array('test_tag' => array(1, 2, 3)); + $tags = array('test_tag:1', 'test_tag:2', 'test_tag:3'); $bins = array('data', 'bootstrap', 'render'); foreach ($bins as $bin) { $bin = \Drupal::cache($bin); @@ -73,7 +73,7 @@ public function testTagDeletetions() { } $deletions_before = intval(db_select('cachetags')->fields('cachetags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField()); - Cache::deleteTags(array('test_tag' => array(2))); + Cache::deleteTags(array('test_tag:2')); // Test that cache entry has been deleted in multiple bins. foreach ($bins as $bin) { diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php index 54c548e..44e6a94 100644 --- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php @@ -452,38 +452,38 @@ function testDeleteTags() { $backend = $this->getCacheBackend(); // Create two cache entries with the same tag and tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag' => 2)); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag' => 2)); + $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); + $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); // Delete test_tag of value 1. This should delete both entries. - $backend->deleteTags(array('test_tag' => 2)); + $backend->deleteTags(array('test_tag:2')); $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two cache items invalidated after deleting a cache tag.'); $this->assertFalse($backend->get('test_cid_invalidate1', TRUE) || $backend->get('test_cid_invalidate2', TRUE), 'Two cache items deleted after deleting a cache tag.'); // Create two cache entries with the same tag and an array tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(1))); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(1))); + $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); + $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); // Delete test_tag of value 1. This should delete both entries. - $backend->deleteTags(array('test_tag' => array(1))); + $backend->deleteTags(array('test_tag:1')); $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two cache items invalidated after deleted a cache tag.'); $this->assertFalse($backend->get('test_cid_invalidate1', TRUE) || $backend->get('test_cid_invalidate2', TRUE), 'Two cache items deleted after deleting a cache tag.'); // Create three cache entries with a mix of tags and tag values. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(1))); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(2))); - $backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, array('test_tag_foo' => array(3))); + $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); + $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); + $backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, array('test_tag_foo:3')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2') && $backend->get('test_cid_invalidate3'), 'Three cached items were created.'); - $backend->deleteTags(array('test_tag_foo' => array(3))); + $backend->deleteTags(array('test_tag_foo:3')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Cached items not matching the tag were not deleted.'); $this->assertFalse($backend->get('test_cid_invalidated3', TRUE), 'Cache item matching the tag was deleted.'); // Create cache entry in multiple bins. Two cache entries // (test_cid_invalidate1 and test_cid_invalidate2) still exist from previous // tests. - $tags = array('test_tag' => array(1, 2, 3)); + $tags = array('test_tag:1', 'test_tag:2', 'test_tag:3'); $bins = array('path', 'bootstrap', 'page'); foreach ($bins as $bin) { $this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags); @@ -492,7 +492,7 @@ function testDeleteTags() { // Delete tag in mulitple bins. foreach ($bins as $bin) { - $this->getCacheBackend($bin)->deleteTags(array('test_tag' => array(2))); + $this->getCacheBackend($bin)->deleteTags(array('test_tag:2')); } // Test that cache entry has been deleted in multple bins. @@ -564,38 +564,38 @@ function testInvalidateTags() { $backend = $this->getCacheBackend(); // Create two cache entries with the same tag and tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag' => 2)); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag' => 2)); + $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); + $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); // Invalidate test_tag of value 1. This should invalidate both entries. - $backend->invalidateTags(array('test_tag' => 2)); + $backend->invalidateTags(array('test_tag:2')); $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two cache items invalidated after invalidating a cache tag.'); $this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.'); // Create two cache entries with the same tag and an array tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(1))); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(1))); + $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); + $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); // Invalidate test_tag of value 1. This should invalidate both entries. - $backend->invalidateTags(array('test_tag' => array(1))); + $backend->invalidateTags(array('test_tag:1')); $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two caches removed after invalidating a cache tag.'); $this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.'); // Create three cache entries with a mix of tags and tag values. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(1))); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag' => array(2))); - $backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, array('test_tag_foo' => array(3))); + $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); + $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); + $backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, array('test_tag_foo:3')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2') && $backend->get('test_cid_invalidate3'), 'Three cached items were created.'); - $backend->invalidateTags(array('test_tag_foo' => array(3))); + $backend->invalidateTags(array('test_tag_foo:3')); $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Cache items not matching the tag were not invalidated.'); $this->assertFalse($backend->get('test_cid_invalidated3'), 'Cached item matching the tag was removed.'); // Create cache entry in multiple bins. Two cache entries // (test_cid_invalidate1 and test_cid_invalidate2) still exist from previous // tests. - $tags = array('test_tag' => array(1, 2, 3)); + $tags = array('test_tag:1', 'test_tag:2', 'test_tag:3'); $bins = array('path', 'bootstrap', 'page'); foreach ($bins as $bin) { $this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags); @@ -604,7 +604,7 @@ function testInvalidateTags() { // Invalidate tag in mulitple bins. foreach ($bins as $bin) { - $this->getCacheBackend($bin)->invalidateTags(array('test_tag' => array(2))); + $this->getCacheBackend($bin)->invalidateTags(array('test_tag:2')); } // Test that cache entry has been invalidated in multple bins. diff --git a/core/modules/system/src/Tests/Theme/RegistryTest.php b/core/modules/system/src/Tests/Theme/RegistryTest.php index cb4de8d..8851ebb 100644 --- a/core/modules/system/src/Tests/Theme/RegistryTest.php +++ b/core/modules/system/src/Tests/Theme/RegistryTest.php @@ -38,7 +38,7 @@ function testRaceCondition() { // entry to be written in __construct(). $cache = \Drupal::cache(); $lock_backend = \Drupal::lock(); - $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry' => TRUE), $this->container->get('module_handler')->isLoaded()); + $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded()); $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.'); @@ -58,7 +58,7 @@ function testRaceCondition() { // Create a new instance of the class. Confirm that both the offset // requested previously, and one that has not yet been requested are both // available. - $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry' => TRUE), $this->container->get('module_handler')->isLoaded()); + $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded()); $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry'); $this->assertTrue($registry->get('theme_test_template_test_2'), 'Offset was returned correctly from the theme registry'); } diff --git a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php index 787d0c4..c5a10b8 100644 --- a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php +++ b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php @@ -58,7 +58,7 @@ public function system_test_cache_tags_page() { * Sets a cache tag on an element to help test #pre_render and cache tags. */ public static function preRenderCacheTags($elements) { - $elements['#cache']['tags']['pre_render'] = TRUE; + $elements['#cache']['tags'][] = 'pre_render'; return $elements; } diff --git a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php index c9e0422..9a6d0ab 100644 --- a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php +++ b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php @@ -7,6 +7,7 @@ namespace Drupal\text\Tests\Formatter; +use Drupal\filter\Entity\FilterFormat; use Drupal\system\Tests\Entity\EntityUnitTestBase; /** @@ -91,10 +92,7 @@ public function testFormatters() { $build = $entity->get('formatted_text')->view(array('type' => $formatter)); drupal_render($build[0]); $this->assertEqual($build[0]['#markup'], "Hello, world!
\n"); - $expected_cache_tags = array( - 'filter_format' => array('my_text_format'), - ); - $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter))); + $this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTag(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter))); } } diff --git a/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php b/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php index fefb74b..14454dd 100644 --- a/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php +++ b/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php @@ -267,7 +267,7 @@ function testCacheClearByCacheTag() { // Log in admin_user and clear the caches for this user using a tag. $this->drupalLogin($this->admin_user); - Cache::deleteTags(array('user' => array($admin_user_id))); + Cache::deleteTags(array('user:' . $admin_user_id)); // Assert that no toolbar cache exists for admin_user against the // language "en". diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index b2eb20f..9eb822a 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -353,14 +353,14 @@ public function generateOutputKey() { */ protected function getCacheTags() { $id = $this->view->storage->id(); - $tags = array('view' => array($id => $id)); + $tags = array('view:' . $id); $entity_information = $this->view->query->getEntityTableInfo(); if (!empty($entity_information)) { // Add an ENTITY_TYPE_list tag for each entity type used by this view. foreach (array_keys($entity_information) as $entity_type) { - $tags[$entity_type . '_list'] = TRUE; + $tags[] = $entity_type . '_list'; } } diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php index 690d302..5993669 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php @@ -107,7 +107,7 @@ public function testDestruct() { ->will($this->returnValue(FALSE)); $this->cache->expects($this->once()) ->method('set') - ->with('library_info', array('test' => $this->libraryData), Cache::PERMANENT, array('library_info' => array(TRUE))); + ->with('library_info', array('test' => $this->libraryData), Cache::PERMANENT, array('library_info')); $this->lock->expects($this->once()) ->method('release') ->with($lock_key); diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php index cc8012d..cf5b3f1 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php @@ -389,7 +389,7 @@ public function testUpdateCacheClear() { public function testUpdateCacheClearTags() { $key = $this->randomMachineName(); $value = $this->randomMachineName(); - $tags = array($this->randomMachineName() => TRUE); + $tags = array($this->randomMachineName()); $this->collector = new CacheCollectorHelper($this->cid, $this->cache, $this->lock, $tags); // Set the data and request it. diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php index 8470a6f..baa7584 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php @@ -123,7 +123,7 @@ protected function getLocalTaskManager($module_dirs, $route_name, $route_params) $property->setValue($manager, $factory); $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $manager->setCacheBackend($cache_backend, 'local_task.en', array('local_task' => 1)); + $manager->setCacheBackend($cache_backend, 'local_task.en', array('local_task')); return $manager; } diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 2d6390c..e94660d 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -185,7 +185,7 @@ public function testGetLocalTaskForRouteWithEmptyCache() { $this->cacheBackend->expects($this->at(3)) ->method('set') - ->with('local_task:en:menu_local_task_test_tasks_view', $expected_set, Cache::PERMANENT, array('local_task' => 1)); + ->with('local_task:en:menu_local_task_test_tasks_view', $expected_set, Cache::PERMANENT, array('local_task')); $local_tasks = $this->manager->getLocalTasksForRoute('menu_local_task_test_tasks_view'); $this->assertEquals($result, $local_tasks); @@ -280,7 +280,7 @@ protected function setupLocalTaskManager() { ->method('getCurrentLanguage') ->will($this->returnValue(new Language(array('id' => 'en')))); - $this->manager->setCacheBackend($this->cacheBackend, 'local_task:en', array('local_task' => 1)); + $this->manager->setCacheBackend($this->cacheBackend, 'local_task:en', array('local_task')); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 274d46d..9d7f08f 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -196,7 +196,7 @@ public function testCacheClearWithTags() { $cache_backend ->expects($this->once()) ->method('deleteTags') - ->with(array('tag' => TRUE)); + ->with(array('tag')); $cache_backend ->expects($this->never()) ->method('deleteMultiple'); @@ -204,7 +204,7 @@ public function testCacheClearWithTags() { $this->getContainerWithCacheBins($cache_backend); $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, NULL, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); - $plugin_manager->setCacheBackend($cache_backend, $cid, array('tag' => TRUE)); + $plugin_manager->setCacheBackend($cache_backend, $cid, array('tag')); $plugin_manager->clearCachedDefinitions(); }