diff --git a/core/lib/Drupal/Core/Cache/BackendChain.php b/core/lib/Drupal/Core/Cache/BackendChain.php index 5a20ff6..82f4775 100644 --- a/core/lib/Drupal/Core/Cache/BackendChain.php +++ b/core/lib/Drupal/Core/Cache/BackendChain.php @@ -148,15 +148,6 @@ public function deleteMultiple(array $cids) { } /** - * Implements Drupal\Core\Cache\CacheBackendInterface::deleteTags(). - */ - public function deleteTags(array $tags) { - foreach ($this->backends as $backend) { - $backend->deleteTags($tags); - } - } - - /** * Implements Drupal\Core\Cache\CacheBackendInterface::deleteAll(). */ public function deleteAll() { @@ -184,15 +175,6 @@ public function invalidateMultiple(array $cids) { } /** - * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). - */ - public function invalidateTags(array $tags) { - foreach ($this->backends as $backend) { - $backend->invalidateTags($tags); - } - } - - /** * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). */ public function invalidateAll() { diff --git a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php index 58af9e9..c8b516f 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php @@ -43,15 +43,15 @@ * @endcode * * There are two ways to "remove" a cache item: - * - Deletion (using delete(), deleteMultiple(), deleteTags() or deleteAll()): + * - Deletion (using delete(), deleteMultiple() or deleteAll()): * Permanently removes the item from the cache. - * - Invalidation (using invalidate(), invalidateMultiple(), invalidateTags() - * or invalidateAll()): a "soft" delete that only marks the items as - * "invalid", meaning "not fresh" or "not fresh enough". Invalid items are - * not usually returned from the cache, so in most ways they behave as if they - * have been deleted. However, it is possible to retrieve the invalid entries, - * if they have not yet been permanently removed by the garbage collector, by - * passing TRUE as the second argument for get($cid, $allow_invalid). + * - Invalidation (using invalidate(), invalidateMultiple() or invalidateAll()): + * a "soft" delete that only marks the items as "invalid", meaning "not fresh" + * or "not fresh enough". Invalid items are not usually returned from the + * cache, so in most ways they behave as if they have been deleted. However, + * it is possible to retrieve the invalid entries, if they have not yet been + * permanently removed by the garbage collector, by passing TRUE as the second + * argument for get($cid, $allow_invalid). * * Cache items should be deleted if they are no longer considered useful. This * is relevant e.g. if the cache item contains references to data that has been @@ -161,7 +161,7 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array * * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() * @see \Drupal\Core\Cache\CacheBackendInterface::deleteMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::deleteTags() + * @see \Drupal\Core\Cache\CacheTagInterface::deleteTags() * @see \Drupal\Core\Cache\CacheBackendInterface::deleteAll() */ public function delete($cid); @@ -180,7 +180,7 @@ public function delete($cid); * * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() * @see \Drupal\Core\Cache\CacheBackendInterface::delete() - * @see \Drupal\Core\Cache\CacheBackendInterface::deleteTags() + * @see \Drupal\Core\Cache\CacheTagInterface::deleteTags() * @see \Drupal\Core\Cache\CacheBackendInterface::deleteAll() */ public function deleteMultiple(array $cids); @@ -191,7 +191,7 @@ public function deleteMultiple(array $cids); * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() * @see \Drupal\Core\Cache\CacheBackendInterface::delete() * @see \Drupal\Core\Cache\CacheBackendInterface::deleteMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::deleteTags() + * @see \Drupal\Core\Cache\CacheTagInterface::deleteTags() */ public function deleteAll(); @@ -206,7 +206,7 @@ public function deleteAll(); * * @see \Drupal\Core\Cache\CacheBackendInterface::delete() * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateTags() + * @see \Drupal\Core\Cache\CacheTagInterface::invalidateTags() * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() */ public function invalidate($cid); @@ -222,7 +222,7 @@ public function invalidate($cid); * * @see \Drupal\Core\Cache\CacheBackendInterface::deleteMultiple() * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateTags() + * @see \Drupal\Core\Cache\CacheTagInterface::invalidateTags() * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateAll() */ public function invalidateMultiple(array $cids); @@ -239,7 +239,7 @@ public function invalidateMultiple(array $cids); * @see \Drupal\Core\Cache\CacheBackendInterface::deleteAll() * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate() * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple() - * @see \Drupal\Core\Cache\CacheBackendInterface::invalidateTags() + * @see \Drupal\Core\Cache\CacheTagInterface::invalidateTags() */ public function invalidateAll(); diff --git a/core/lib/Drupal/Core/Cache/NullBackend.php b/core/lib/Drupal/Core/Cache/NullBackend.php index 0364663..287d947 100644 --- a/core/lib/Drupal/Core/Cache/NullBackend.php +++ b/core/lib/Drupal/Core/Cache/NullBackend.php @@ -63,11 +63,6 @@ public function deleteMultiple(array $cids) {} public function deleteAll() {} /** - * Implements Drupal\Core\Cache\CacheBackendInterface::deleteTags(). - */ - public function deleteTags(array $tags) {} - - /** * Implements Drupal\Core\Cache\CacheBackendInterface::invalidate(). */ public function invalidate($cid) {} @@ -78,11 +73,6 @@ public function invalidate($cid) {} public function invalidateMultiple(array $cids) {} /** - * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). - */ - public function invalidateTags(array $tags) {} - - /** * Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). */ public function invalidateAll() {} diff --git a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php index e558816..a5142db 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php @@ -353,66 +353,6 @@ public function testDeleteMultiple() { } /** - * Tests Drupal\Core\Cache\CacheBackendInterface::deleteTags(). - */ - 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)); - $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)); - $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))); - $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))); - $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))); - $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))); - $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)); - $bins = array('path', 'bootstrap', 'page'); - foreach ($bins as $bin) { - $this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags); - $this->assertTrue($this->getCacheBackend($bin)->get('test'), 'Cache item was set in bin.'); - } - - // Delete tag in mulitple bins. - foreach ($bins as $bin) { - $this->getCacheBackend($bin)->deleteTags(array('test_tag' => array(2))); - } - - // Test that cache entry has been deleted in multple bins. - foreach ($bins as $bin) { - $this->assertFalse($this->getCacheBackend($bin)->get('test', TRUE), 'Tag deletion affected item in bin.'); - } - // Test that the cache entry with a matching tag has been invalidated. - $this->assertFalse($this->getCacheBackend($bin)->get('test_cid_invalidate2', TRUE), 'Cache items matching tag were deleted.'); - // Test that the cache entry with without a matching tag still exists. - $this->assertTrue($this->getCacheBackend($bin)->get('test_cid_invalidate1'), 'Cache items not matching tag were not invalidated.'); - } - - /** * Test Drupal\Core\Cache\CacheBackendInterface::deleteAll(). */ public function testDeleteAll() { @@ -460,66 +400,6 @@ function testInvalidate() { } /** - * Tests Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). - */ - 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)); - $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)); - $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))); - $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))); - $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))); - $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))); - $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)); - $bins = array('path', 'bootstrap', 'page'); - foreach ($bins as $bin) { - $this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags); - $this->assertTrue($this->getCacheBackend($bin)->get('test'), 'Cache item was set in bin.'); - } - - // Invalidate tag in mulitple bins. - foreach ($bins as $bin) { - $this->getCacheBackend($bin)->invalidateTags(array('test_tag' => array(2))); - } - - // Test that cache entry has been invalidated in multple bins. - foreach ($bins as $bin) { - $this->assertFalse($this->getCacheBackend($bin)->get('test'), 'Tag invalidation affected item in bin.'); - } - // Test that the cache entry with a matching tag has been invalidated. - $this->assertFalse($this->getCacheBackend($bin)->get('test_cid_invalidate2'), 'Cache items matching tag were invalidated.'); - // Test that the cache entry with without a matching tag still exists. - $this->assertTrue($this->getCacheBackend($bin)->get('test_cid_invalidate1'), 'Cache items not matching tag were not invalidated.'); - } - - /** * Test Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). */ public function testInvalidateAll() { diff --git a/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php b/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php index 71a5642..8841720 100644 --- a/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php @@ -234,83 +234,6 @@ public function testDeleteAllPropagation() { } /** - * Test that the delete tags operation is propagated to all backends - * in the chain. - */ - public function testDeleteTagsPropagation() { - // Create two cache entries with the same tag and tag value. - $this->chain->set('test_cid_clear1', 'foo', Cache::PERMANENT, array('test_tag' => 2)); - $this->chain->set('test_cid_clear2', 'foo', Cache::PERMANENT, array('test_tag' => 2)); - $this->assertNotSame(FALSE, $this->firstBackend->get('test_cid_clear1') - && $this->firstBackend->get('test_cid_clear2') - && $this->secondBackend->get('test_cid_clear1') - && $this->secondBackend->get('test_cid_clear2') - && $this->thirdBackend->get('test_cid_clear1') - && $this->thirdBackend->get('test_cid_clear2'), - 'Two cache items were created in all backends.'); - - // Invalidate test_tag of value 1. This should invalidate both entries. - $this->chain->deleteTags(array('test_tag' => 2)); - $this->assertSame(FALSE, $this->firstBackend->get('test_cid_clear1') - && $this->firstBackend->get('test_cid_clear2') - && $this->secondBackend->get('test_cid_clear1') - && $this->secondBackend->get('test_cid_clear2') - && $this->thirdBackend->get('test_cid_clear1') - && $this->thirdBackend->get('test_cid_clear2'), - 'Two caches removed from all backends after clearing a cache tag.'); - - // Create two cache entries with the same tag and an array tag value. - $this->chain->set('test_cid_clear1', 'foo', Cache::PERMANENT, array('test_tag' => array(1))); - $this->chain->set('test_cid_clear2', 'foo', Cache::PERMANENT, array('test_tag' => array(1))); - $this->assertNotSame(FALSE, $this->firstBackend->get('test_cid_clear1') - && $this->firstBackend->get('test_cid_clear2') - && $this->secondBackend->get('test_cid_clear1') - && $this->secondBackend->get('test_cid_clear2') - && $this->thirdBackend->get('test_cid_clear1') - && $this->thirdBackend->get('test_cid_clear2'), - 'Two cache items were created in all backends.'); - - // Invalidate test_tag of value 1. This should invalidate both entries. - $this->chain->deleteTags(array('test_tag' => array(1))); - $this->assertSame(FALSE, $this->firstBackend->get('test_cid_clear1') - && $this->firstBackend->get('test_cid_clear2') - && $this->secondBackend->get('test_cid_clear1') - && $this->secondBackend->get('test_cid_clear2') - && $this->thirdBackend->get('test_cid_clear1') - && $this->thirdBackend->get('test_cid_clear2'), - 'Two caches removed from all backends after clearing a cache tag.'); - - // Create three cache entries with a mix of tags and tag values. - $this->chain->set('test_cid_clear1', 'foo', Cache::PERMANENT, array('test_tag' => array(1))); - $this->chain->set('test_cid_clear2', 'foo', Cache::PERMANENT, array('test_tag' => array(2))); - $this->chain->set('test_cid_clear3', 'foo', Cache::PERMANENT, array('test_tag_foo' => array(3))); - $this->assertNotSame(FALSE, $this->firstBackend->get('test_cid_clear1') - && $this->firstBackend->get('test_cid_clear2') - && $this->firstBackend->get('test_cid_clear3') - && $this->secondBackend->get('test_cid_clear1') - && $this->secondBackend->get('test_cid_clear2') - && $this->secondBackend->get('test_cid_clear3') - && $this->thirdBackend->get('test_cid_clear1') - && $this->thirdBackend->get('test_cid_clear2') - && $this->thirdBackend->get('test_cid_clear3'), - 'Three cached items were created in all backends.'); - - $this->chain->deleteTags(array('test_tag_foo' => array(3))); - $this->assertNotSame(FALSE, $this->firstBackend->get('test_cid_clear1') - && $this->firstBackend->get('test_cid_clear2') - && $this->secondBackend->get('test_cid_clear1') - && $this->secondBackend->get('test_cid_clear2') - && $this->thirdBackend->get('test_cid_clear1') - && $this->thirdBackend->get('test_cid_clear2'), - 'Cached items not matching the tag were not cleared from any of the backends.'); - - $this->assertSame(FALSE, $this->firstBackend->get('test_cid_clear3') - && $this->secondBackend->get('test_cid_clear3') - && $this->thirdBackend->get('test_cid_clear3'), - 'Cached item matching the tag was removed from all backends.'); - } - - /** * Test that removing bin propagates to all backends. */ public function testRemoveBin() { diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php index 05a987c..7740523 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php @@ -27,6 +27,13 @@ class CacheCollectorTest extends UnitTestCase { protected $cache; /** + * The cache tag backend to use. + * + * @var \Drupal\Core\Cache\CacheTagInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cacheTag; + + /** * The lock backend that should be used. * * @var \PHPUnit_Framework_MockObject_MockObject @@ -60,11 +67,12 @@ public static function getInfo() { */ protected function setUp() { $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTag = $this->getMock('Drupal\Core\Cache\CacheTagInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $this->cid = $this->randomName(); $this->collector = new CacheCollectorHelper($this->cid, $this->cache, $this->lock); - $this->getContainerWithCacheBins($this->cache); + $this->getContainerWithCacheTags($this->cacheTag); } @@ -387,7 +395,7 @@ public function testUpdateCacheClear() { $this->cache->expects($this->once()) ->method('delete') ->with($this->cid); - $this->cache->expects($this->never()) + $this->cacheTag->expects($this->never()) ->method('deleteTags'); $this->collector->clear(); $this->assertEquals($value, $this->collector->get($key)); @@ -414,7 +422,7 @@ public function testUpdateCacheClearTags() { // Clear the collected cache using the tags, should call it again. $this->cache->expects($this->never()) ->method('delete'); - $this->cache->expects($this->once()) + $this->cacheTag->expects($this->once()) ->method('deleteTags') ->with($tags); $this->collector->clear(); diff --git a/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php b/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php index 3ad73a1..81a6248 100644 --- a/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php @@ -138,7 +138,7 @@ public function testGetMultipleOnPartiallyPrimedCache() { */ public function testReadNonExistentFileCacheMiss() { $name = 'config.does_not_exist'; - $cache = new MemoryBackend(__FUNCTION__); + $cache = new MemoryBackend(new MemoryTag(), __FUNCTION__); $storage = $this->getMock('Drupal\Core\Config\StorageInterface'); $storage->expects($this->once()) ->method('read') @@ -158,7 +158,7 @@ public function testReadNonExistentFileCacheMiss() { */ public function testReadNonExistentFileCached() { $name = 'config.does_not_exist'; - $cache = new MemoryBackend(__FUNCTION__); + $cache = new MemoryBackend(new MemoryTag(), __FUNCTION__); $cache->set($name, FALSE); $storage = $this->getMock('Drupal\Core\Config\StorageInterface'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 4da13aa..b4b5937 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -66,6 +66,13 @@ class EntityManagerTest extends UnitTestCase { protected $cache; /** + * The cache tag backend to use. + * + * @var \Drupal\Core\Cache\CacheTagInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cacheTag; + + /** * The language manager. * * @var \Drupal\Core\Language\LanguageManager|\PHPUnit_Framework_MockObject_MockObject @@ -111,6 +118,8 @@ protected function setUp() { $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTag = $this->getMock('Drupal\Core\Cache\CacheTagInterface'); + $this->languageManager = $this->getMockBuilder('Drupal\Core\Language\LanguageManager') ->disableOriginalConstructor() ->getMock(); @@ -122,7 +131,7 @@ protected function setUp() { $this->formBuilder = $this->getMock('Drupal\Core\Form\FormBuilderInterface'); - $this->container = $this->getContainerWithCacheBins($this->cache); + $this->container = $this->getContainerWithCacheTags($this->cacheTag); $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface'); } @@ -609,7 +618,7 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f */ public function testClearCachedFieldDefinitions() { $this->setUpEntityManager(); - $this->cache->expects($this->once()) + $this->cacheTag->expects($this->once()) ->method('deleteTags') ->with(array('entity_field_info' => TRUE)); diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 6efddf7..97116d1 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -44,6 +44,13 @@ class ThemeHandlerTest extends UnitTestCase { protected $cacheBackend; /** + * The mocked cache tag service. + * + * @var \Drupal\Core\Cache\CacheTagInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cacheTag; + + /** * The mocked config factory. * * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject @@ -96,6 +103,7 @@ protected function setUp() { $this->configFactory = $this->getConfigFactoryStub(array('system.theme' => array(), 'system.theme.disabled' => array())); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTag = $this->getMock('Drupal\Core\Cache\CacheTagInterface'); $this->infoParser = $this->getMock('Drupal\Core\Extension\InfoParserInterface'); $this->configInstaller = $this->getMock('Drupal\Core\Config\ConfigInstallerInterface'); $this->routeBuilder = $this->getMockBuilder('Drupal\Core\Routing\RouteBuilder') @@ -106,7 +114,7 @@ protected function setUp() { ->getMock(); $this->themeHandler = new TestThemeHandler($this->configFactory, $this->moduleHandler, $this->cacheBackend, $this->infoParser, $this->configInstaller, $this->routeBuilder, $this->systemListingInfo); - $this->getContainerWithCacheBins($this->cacheBackend); + $this->getContainerWithCacheTags($this->cacheTag); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 894a6e1..cf4692e 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -161,18 +161,23 @@ public function testDefaultPluginManagerWithFilledCache() { */ public function testCacheClearWithTags() { $cid = $this->randomName(); - $cache_backend = $this->getMockBuilder('Drupal\Core\Cache\MemoryBackend') + $memory_tag = $this->getMockBuilder('Drupal\Core\Cache\MemoryTag') ->disableOriginalConstructor() ->getMock(); - $cache_backend + $memory_tag ->expects($this->once()) ->method('deleteTags') ->with(array('tag' => TRUE)); + + $cache_backend = $this->getMockBuilder('Drupal\Core\Cache\MemoryBackend') + ->setConstructorArgs(array($memory_tag)) + ->disableOriginalConstructor() + ->getMock(); $cache_backend ->expects($this->never()) ->method('deleteMultiple'); - $this->getContainerWithCacheBins($cache_backend); + $this->getContainerWithCacheTags($memory_tag); $language = new Language(array('id' => 'en')); $language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index a76611c..6c239d6 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\Random; use Drupal\Component\Utility\String; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\CacheTagInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; /** @@ -200,25 +201,24 @@ public function getStringTranslationStub() { /** * Sets up a container with cache bins. * - * @param \Drupal\Core\Cache\CacheBackendInterface $backend - * The cache backend to set up. + * @param \Drupal\Core\Cache\CacheTagInterface $backend + * The cache tag to set up. * * @return \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject * The container with the cache bins set up. */ - protected function getContainerWithCacheBins(CacheBackendInterface $backend) { + protected function getContainerWithCacheTags(CacheTagInterface $backend) { $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $container->expects($this->any()) ->method('getParameter') - ->with('cache_bins') - ->will($this->returnValue(array('cache.test' => 'test'))); + ->with('cache_tags') + ->will($this->returnValue(array('cache.tag.test' => 'test'))); $container->expects($this->any()) ->method('get') - ->with('cache.test') + ->with('cache.tag.test') ->will($this->returnValue($backend)); \Drupal::setContainer($container); return $container; } - }