core/lib/Drupal/Core/Config/ConfigFactory.php | 2 + .../Drupal/Tests/Core/Config/ConfigFactoryTest.php | 87 ++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index b1a8932..ce092d3 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Cache\Cache; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -218,6 +219,7 @@ public function reset($name = NULL) { * {@inheritdoc} */ public function rename($old_name, $new_name) { + Cache::invalidateTags($this->get($old_name)->getCacheTags()); $this->storage->rename($old_name, $new_name); // Clear out the static cache of any references to the old name. diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigFactoryTest.php new file mode 100644 index 0000000..4e4f613 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/ConfigFactoryTest.php @@ -0,0 +1,87 @@ +storage = $this->getMock('Drupal\Core\Config\StorageInterface'); + $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->typedConfig = $this->getMock('\Drupal\Core\Config\TypedConfigManagerInterface'); + $this->configFactory = new ConfigFactory($this->storage, $this->eventDispatcher, $this->typedConfig); + + $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); + + $container = new ContainerBuilder(); + $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator); + \Drupal::setContainer($container); + } + + /** + * @covers ::rename + */ + public function testRename() { + $old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig); + $new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig); + + $this->storage->expects($this->exactly(2)) + ->method('readMultiple') + ->willReturnMap([ + [[$old->getName()], $old->getRawData()], + [[$new->getName()], $new->getRawData()], + ]); + + $this->cacheTagsInvalidator->expects($this->once()) + ->method('invalidateTags') + ->with($old->getCacheTags()); + + $this->configFactory->rename($old->getName(), $new->getName()); + } + +}