diff --git a/core/lib/Drupal/Core/Cache/Cache.php b/core/lib/Drupal/Core/Cache/Cache.php index c88171e..b8e6cdc 100644 --- a/core/lib/Drupal/Core/Cache/Cache.php +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -100,6 +100,8 @@ public static function buildTags($prefix, array $suffixes) { * The list of tags to delete cache items for. */ public static function deleteTags(array $tags) { + // @todo Move to service. + static::validateTags($tags); \Drupal::service('cache_tags')->deleteTags($tags); } @@ -110,6 +112,8 @@ public static function deleteTags(array $tags) { * The list of tags to invalidate cache items for. */ public static function invalidateTags(array $tags) { + // @todo Move to service. + static::validateTags($tags); \Drupal::service('cache_tags')->invalidateTags($tags); } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php index cf5b3f1..d8744d8 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php @@ -48,7 +48,7 @@ class CacheCollectorTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp() { - $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cache = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $this->cid = $this->randomMachineName(); $this->collector = new CacheCollectorHelper($this->cid, $this->cache, $this->lock); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 2da84fe..02ce8b5 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -79,9 +79,9 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheBackend; + protected $cacheTagHandler; /** * The mocked typed config manager. @@ -121,7 +121,7 @@ protected function setUp() { ->with('en') ->will($this->returnValue(new Language(array('id' => 'en')))); - $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); $this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); @@ -129,9 +129,8 @@ protected function setUp() { $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); $container->set('language_manager', $this->languageManager); - $container->set('cache.test', $this->cacheBackend); + $container->set('cache_tags', $this->cacheTagHandler); $container->set('config.typed', $this->typedConfigManager); - $container->setParameter('cache_bins', array('cache.test' => 'test')); \Drupal::setContainer($container); $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', array($values, $this->entityTypeId)); @@ -361,7 +360,7 @@ public function testEnable() { * @depends testSetStatus */ public function testDisable() { - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array($this->entityTypeId . ':' . $this->id)); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index fb14691..e95d7e4 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -85,9 +85,9 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheBackend; + protected $cacheTagHandler; /** * The mocked typed config manager. @@ -153,7 +153,7 @@ protected function setUp() { ->with('test_entity_type') ->will($this->returnValue($this->entityType)); - $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); $this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'); $this->typedConfigManager->expects($this->any()) @@ -162,8 +162,7 @@ protected function setUp() { $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('config.typed', $this->typedConfigManager); - $container->set('cache.test', $this->cacheBackend); - $container->setParameter('cache_bins', array('cache.test' => 'test')); + $container->set('cache_tags', $this->cacheTagHandler); \Drupal::setContainer($container); } @@ -173,7 +172,7 @@ protected function setUp() { * @covers ::doCreate */ public function testCreateWithPredefinedUuid() { - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->moduleHandler->expects($this->at(0)) @@ -198,7 +197,7 @@ public function testCreateWithPredefinedUuid() { * @return \Drupal\Core\Entity\EntityInterface */ public function testCreate() { - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->moduleHandler->expects($this->at(0)) @@ -240,7 +239,7 @@ public function testSaveInsert(EntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . '_list', // List cache tag. @@ -299,7 +298,7 @@ public function testSaveUpdate(EntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':foo', // Own cache tag. @@ -359,7 +358,7 @@ public function testSaveRename(ConfigEntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId .':bar', // Own cache tag. @@ -403,7 +402,7 @@ public function testSaveRename(ConfigEntityInterface $entity) { * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $entity = $this->getMockEntity(); @@ -428,7 +427,7 @@ public function testSaveDuplicate() { $config_object->expects($this->never()) ->method('save'); - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->configFactory->expects($this->once()) @@ -459,7 +458,7 @@ public function testSaveMismatch() { $config_object->expects($this->never()) ->method('save'); - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->configFactory->expects($this->once()) @@ -492,7 +491,7 @@ public function testSaveNoMismatch() { $config_object->expects($this->once()) ->method('save'); - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . '_list', // List cache tag. @@ -542,7 +541,7 @@ public function testSaveChangedUuid() { array('id', 'foo'), ))); - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->configFactory->expects($this->at(1)) @@ -699,7 +698,7 @@ public function testLoadRevision() { * @covers ::deleteRevision */ public function testDeleteRevision() { - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->assertSame(NULL, $this->entityStorage->deleteRevision(1)); @@ -725,7 +724,7 @@ public function testDelete() { $config_map[] = array("the_config_prefix.$id", $config_object); } - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':bar', // Own cache tag. @@ -775,7 +774,7 @@ public function testDeleteNothing() { $this->configFactory->expects($this->never()) ->method('get'); - $this->cacheBackend->expects($this->never()) + $this->cacheTagHandler->expects($this->never()) ->method('invalidateTags'); $this->entityStorage->delete(array()); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 933b7ed..beaa312 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -120,6 +120,7 @@ protected function setUp() { ->will($this->returnValue(array())); $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $cache_tag_handler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); $language = $this->getMock('Drupal\Core\Language\LanguageInterface'); $language->expects($this->any()) @@ -139,7 +140,7 @@ protected function setUp() { $this->formBuilder = $this->getMock('Drupal\Core\Form\FormBuilderInterface'); $this->controllerResolver = $this->getClassResolverStub(); - $this->container = $this->getContainerWithCacheBins($this->cache); + $this->container = $this->getContainerWithCacheBins($cache_tag_handler); $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index 6535732..c512fb1 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -75,9 +75,9 @@ class EntityUnitTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheBackend; + protected $cacheTagHandler; /** * The entity values. @@ -116,14 +116,13 @@ protected function setUp() { ->with('en') ->will($this->returnValue(new Language(array('id' => 'en')))); - $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandler'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); $container->set('language_manager', $this->languageManager); - $container->set('cache.test', $this->cacheBackend); - $container->setParameter('cache_bins', array('cache.test' => 'test')); + $container->set('cache_tags', $this->cacheTagHandler); \Drupal::setContainer($container); $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\Entity', array($this->values, $this->entityTypeId)); @@ -393,12 +392,12 @@ public function testPreSave() { * @covers ::postSave */ public function testPostSave() { - $this->cacheBackend->expects($this->at(0)) + $this->cacheTagHandler->expects($this->at(0)) ->method('invalidateTags') ->with(array( $this->entityTypeId . '_list', // List cache tag. )); - $this->cacheBackend->expects($this->at(1)) + $this->cacheTagHandler->expects($this->at(1)) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':' . $this->values['id'], // Own cache tag. @@ -450,7 +449,7 @@ public function testPreDelete() { * @covers ::postDelete */ public function testPostDelete() { - $this->cacheBackend->expects($this->once()) + $this->cacheTagHandler->expects($this->once()) ->method('invalidateTags') ->with(array( $this->entityTypeId . ':' . $this->values['id'], diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index ee10e54..a79b9c3 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -70,9 +70,9 @@ class KeyValueEntityStorageTest extends UnitTestCase { /** * The mocked cache backend. * - * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\cacheTagHandlerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheBackend; + protected $cacheTagHandler; /** * {@inheritdoc} @@ -110,7 +110,7 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') { ->with('test_entity_type') ->will($this->returnValue($this->entityType)); - $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->cacheTagHandler = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); $this->keyValueStore = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); @@ -130,8 +130,7 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') { $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('language_manager', $this->languageManager); - $container->set('cache.test', $this->cacheBackend); - $container->setParameter('cache_bins', array('cache.test' => 'test')); + $container->set('cache_tags', $this->cacheTagHandler); \Drupal::setContainer($container); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 0a58e81..89ed10c 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -121,7 +121,7 @@ protected function setUp() { $logger = $this->getMock('Psr\Log\LoggerInterface'); $this->themeHandler = new TestThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilderIndicator, $this->extensionDiscovery); - $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $cache_backend = $this->getMock('Drupal\Core\Cache\CacheTagHandlerInterface'); $this->getContainerWithCacheBins($cache_backend); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index c2ef841..e9bd4ce 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -190,7 +190,7 @@ public function testDefaultPluginManagerWithFilledCache() { */ public function testCacheClearWithTags() { $cid = $this->randomMachineName(); - $cache_backend = $this->getMockBuilder('Drupal\Core\Cache\MemoryBackend') + $cache_backend = $this->getMockBuilder('Drupal\Core\Cache\CacheTagHandlerInterface') ->disableOriginalConstructor() ->getMock(); $cache_backend diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 43748e8..268dadd 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -8,8 +8,7 @@ namespace Drupal\Tests; use Drupal\Component\Utility\Random; -use Drupal\Component\Utility\String; -use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\CacheTagHandlerInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; /** @@ -199,22 +198,18 @@ public function getStringTranslationStub() { /** * Sets up a container with cache bins. * - * @param \Drupal\Core\Cache\CacheBackendInterface $backend + * @param \Drupal\Core\Cache\CacheTagHandlerInterface $cache_tags_handler * The cache backend 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 getContainerWithCacheBins(CacheTagHandlerInterface $cache_tags_handler) { $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $container->expects($this->any()) - ->method('getParameter') - ->with('cache_bins') - ->will($this->returnValue(array('cache.test' => 'test'))); - $container->expects($this->any()) ->method('get') - ->with('cache.test') - ->will($this->returnValue($backend)); + ->with('cache_tags') + ->will($this->returnValue($cache_tags_handler)); \Drupal::setContainer($container); return $container;