3 namespace Drupal\Tests\Core\Config;
5 use Drupal\Core\Config\Config;
6 use Drupal\Core\Config\ConfigFactory;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\DependencyInjection\ContainerBuilder;
12 * @coversDefaultClass \Drupal\Core\Config\ConfigFactory
14 class ConfigFactoryTest extends UnitTestCase {
17 * Config factory under test.
19 * @var \Drupal\Core\Config\ConfigFactory
21 protected $configFactory;
26 * @var \Drupal\Core\Config\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
33 * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
35 protected $eventDispatcher;
40 * @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
42 protected $typedConfig;
45 * The mocked cache tags invalidator.
47 * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
49 protected $cacheTagsInvalidator;
54 protected function setUp() {
55 $this->storage = $this->getMock('Drupal\Core\Config\StorageInterface');
56 $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
57 $this->typedConfig = $this->getMock('\Drupal\Core\Config\TypedConfigManagerInterface');
58 $this->configFactory = new ConfigFactory($this->storage, $this->eventDispatcher, $this->typedConfig);
60 $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
62 $container = new ContainerBuilder();
63 $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
64 \Drupal::setContainer($container);
70 public function testRename() {
71 $old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
72 $new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
74 $this->storage->expects($this->exactly(2))
75 ->method('readMultiple')
77 [[$old->getName()], $old->getRawData()],
78 [[$new->getName()], $new->getRawData()],
81 $this->cacheTagsInvalidator->expects($this->once())
82 ->method('invalidateTags')
83 ->with($old->getCacheTags());
85 $this->storage->expects($this->once())
87 ->with($old->getName(), $new->getName());
89 $this->configFactory->rename($old->getName(), $new->getName());