Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Config / ConfigFactoryTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Config;
4
5 use Drupal\Core\Config\Config;
6 use Drupal\Core\Config\ConfigFactory;
7 use Drupal\Tests\UnitTestCase;
8 use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10 /**
11  * @group Config
12  * @coversDefaultClass \Drupal\Core\Config\ConfigFactory
13  */
14 class ConfigFactoryTest extends UnitTestCase {
15
16   /**
17    * Config factory under test.
18    *
19    * @var \Drupal\Core\Config\ConfigFactory
20    */
21   protected $configFactory;
22
23   /**
24    * Storage.
25    *
26    * @var \Drupal\Core\Config\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
27    */
28   protected $storage;
29
30   /**
31    * Event Dispatcher.
32    *
33    * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
34    */
35   protected $eventDispatcher;
36
37   /**
38    * Typed Config.
39    *
40    * @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
41    */
42   protected $typedConfig;
43
44   /**
45    * The mocked cache tags invalidator.
46    *
47    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
48    */
49   protected $cacheTagsInvalidator;
50
51   /**
52    * {@inheritdoc}
53    */
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);
59
60     $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
61
62     $container = new ContainerBuilder();
63     $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
64     \Drupal::setContainer($container);
65   }
66
67   /**
68    * @covers ::rename
69    */
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);
73
74     $this->storage->expects($this->exactly(2))
75       ->method('readMultiple')
76       ->willReturnMap([
77         [[$old->getName()], $old->getRawData()],
78         [[$new->getName()], $new->getRawData()],
79       ]);
80
81     $this->cacheTagsInvalidator->expects($this->once())
82       ->method('invalidateTags')
83       ->with($old->getCacheTags());
84
85     $this->storage->expects($this->once())
86       ->method('rename')
87       ->with($old->getName(), $new->getName());
88
89     $this->configFactory->rename($old->getName(), $new->getName());
90   }
91
92 }