805cef97a7f614b1b4338abbdcb18630e082a1a6
[yaffs-website] / web / core / modules / language / tests / src / Unit / Config / LanguageConfigOverrideTest.php
1 <?php
2
3 namespace Drupal\Tests\language\Unit\Config;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\language\Config\LanguageConfigOverride;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\language\Config\LanguageConfigOverride
11  * @group Config
12  * @group language
13  */
14 class LanguageConfigOverrideTest extends UnitTestCase {
15
16   /**
17    * Language configuration override.
18    *
19    * @var \Drupal\language\Config\LanguageConfigOverride
20    */
21   protected $configTranslation;
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->configTranslation = new LanguageConfigOverride('config.test', $this->storage, $this->typedConfig, $this->eventDispatcher);
59     $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
60
61     $container = new ContainerBuilder();
62     $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
63     \Drupal::setContainer($container);
64   }
65
66   /**
67    * @covers ::save
68    */
69   public function testSaveNew() {
70     $this->cacheTagsInvalidator->expects($this->once())
71       ->method('invalidateTags')
72       ->with(['config:config.test']);
73     $this->assertTrue($this->configTranslation->isNew());
74     $this->configTranslation->save();
75   }
76
77   /**
78    * @covers ::save
79    */
80   public function testSaveExisting() {
81     $this->cacheTagsInvalidator->expects($this->once())
82       ->method('invalidateTags')
83       ->with(['config:config.test']);
84     $this->configTranslation->initWithData([]);
85     $this->configTranslation->save();
86   }
87
88   /**
89    * @covers ::delete
90    */
91   public function testDelete() {
92     $this->cacheTagsInvalidator->expects($this->once())
93       ->method('invalidateTags')
94       ->with(['config:config.test']);
95     $this->configTranslation->initWithData([]);
96     $this->configTranslation->delete();
97   }
98
99 }