.../Core/Config/Entity/ConfigEntityStorageTest.php | 78 +++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index d6f5c9c..fb1ab1c 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -28,6 +28,13 @@ class ConfigEntityStorageTest extends UnitTestCase { protected $entityType; /** + * The type ID of the entity under test. + * + * @var string + */ + protected $entityTypeId; + + /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject @@ -84,6 +91,13 @@ class ConfigEntityStorageTest extends UnitTestCase { protected $entityManager; /** + * The mocked cache backend. + * + * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cacheBackend; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -101,6 +115,7 @@ protected function setUp() { parent::setUp(); $this->entityType = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); + $this->entityTypeId = 'test_entity_type'; $this->entityType->expects($this->any()) ->method('getKey') ->will($this->returnValueMap(array( @@ -109,7 +124,7 @@ protected function setUp() { ))); $this->entityType->expects($this->any()) ->method('id') - ->will($this->returnValue('test_entity_type')); + ->will($this->returnValue($this->entityTypeId)); $this->entityType->expects($this->any()) ->method('getConfigPrefix') ->will($this->returnValue('the_config_prefix')); @@ -144,8 +159,12 @@ protected function setUp() { ->with('test_entity_type') ->will($this->returnValue($this->entityType)); + $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); + $container->set('cache.test', $this->cacheBackend); + $container->setParameter('cache_bins', array('cache.test' => 'test')); \Drupal::setContainer($container); } @@ -158,6 +177,9 @@ public function testCreateWithPredefinedUuid() { ->method('getClass') ->will($this->returnValue(get_class($this->getMockEntity()))); + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->moduleHandler->expects($this->at(0)) ->method('invokeAll') ->with('test_entity_type_create'); @@ -183,6 +205,9 @@ public function testCreate() { ->method('getClass') ->will($this->returnValue(get_class($this->getMockEntity()))); + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->moduleHandler->expects($this->at(0)) ->method('invokeAll') ->with('test_entity_type_create'); @@ -221,6 +246,12 @@ public function testSaveInsert(EntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); + $this->cacheBackend->expects($this->once()) + ->method('invalidateTags') + ->with(array( + $this->entityTypeId . 's' => TRUE, // List cache tag. + )); + $this->configFactory->expects($this->once()) ->method('get') ->with('the_config_prefix.foo') @@ -273,6 +304,13 @@ public function testSaveUpdate(EntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); + $this->cacheBackend->expects($this->once()) + ->method('invalidateTags') + ->with(array( + $this->entityTypeId . 's' => TRUE, // List cache tag. + $this->entityTypeId => array('foo'), // Own cache tag. + )); + $this->configFactory->expects($this->exactly(2)) ->method('loadMultiple') ->with(array('the_config_prefix.foo')) @@ -325,6 +363,13 @@ public function testSaveRename(ConfigEntityInterface $entity) { $config_object->expects($this->once()) ->method('save'); + $this->cacheBackend->expects($this->once()) + ->method('invalidateTags') + ->with(array( + $this->entityTypeId . 's' => TRUE, // List cache tag. + $this->entityTypeId => array('bar'), // Own cache tag. + )); + $this->configFactory->expects($this->once()) ->method('rename') ->will($this->returnValue($config_object)); @@ -362,6 +407,9 @@ public function testSaveRename(ConfigEntityInterface $entity) { * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $entity = $this->getMockEntity(); $this->entityStorage->save($entity); } @@ -383,6 +431,9 @@ public function testSaveDuplicate() { $config_object->expects($this->never()) ->method('save'); + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->configFactory->expects($this->once()) ->method('get') ->with('the_config_prefix.foo') @@ -410,6 +461,9 @@ public function testSaveMismatch() { $config_object->expects($this->never()) ->method('save'); + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->configFactory->expects($this->once()) ->method('get') ->with('the_config_prefix.foo') @@ -439,6 +493,12 @@ public function testSaveNoMismatch() { $config_object->expects($this->once()) ->method('save'); + $this->cacheBackend->expects($this->once()) + ->method('invalidateTags') + ->with(array( + $this->entityTypeId . 's' => TRUE, // List cache tag. + )); + $this->configFactory->expects($this->once()) ->method('get') ->with('the_config_prefix.baz') @@ -482,6 +542,9 @@ public function testSaveChangedUuid() { array('id', 'foo'), ))); + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->configFactory->expects($this->at(1)) ->method('loadMultiple') ->with(array('the_config_prefix.foo')) @@ -643,6 +706,9 @@ public function testLoadRevision() { * @covers ::deleteRevision() */ public function testDeleteRevision() { + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->assertSame(NULL, $this->entityStorage->deleteRevision(1)); } @@ -669,6 +735,13 @@ public function testDelete() { $config_map[] = array("the_config_prefix.$id", $config_object); } + $this->cacheBackend->expects($this->once()) + ->method('invalidateTags') + ->with(array( + $this->entityTypeId . 's' => TRUE, // List cache tag. + $this->entityTypeId => array('foo', 'bar'), // Own cache tag. + )); + $this->configFactory->expects($this->exactly(2)) ->method('get') ->will($this->returnValueMap($config_map)); @@ -710,6 +783,9 @@ public function testDeleteNothing() { $this->configFactory->expects($this->never()) ->method('get'); + $this->cacheBackend->expects($this->never()) + ->method('invalidateTags'); + $this->entityStorage->delete(array()); }