1 | <?php |
||
20 | class ConfigManagerTest extends AbstractTestCase |
||
21 | { |
||
22 | /** |
||
23 | * @var ConfigManager |
||
24 | */ |
||
25 | private $configManager; |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | protected function setUp() |
||
31 | { |
||
32 | $this->configManager = new ConfigManager(); |
||
33 | } |
||
34 | |||
35 | public function testDefaultState() |
||
36 | { |
||
37 | $this->assertNull($this->configManager->getDefaultConfig()); |
||
38 | $this->assertFalse($this->configManager->hasConfigs()); |
||
39 | $this->assertSame([], $this->configManager->getConfigs()); |
||
40 | } |
||
41 | |||
42 | public function testInitialState() |
||
43 | { |
||
44 | $configs = [ |
||
45 | 'foo' => ['foo'], |
||
46 | 'bar' => ['bar'], |
||
47 | ]; |
||
48 | |||
49 | $this->configManager = new ConfigManager($configs, 'foo'); |
||
50 | |||
51 | $this->assertSame('foo', $this->configManager->getDefaultConfig()); |
||
52 | $this->assertTrue($this->configManager->hasConfigs()); |
||
53 | $this->assertSame($configs, $this->configManager->getConfigs()); |
||
54 | } |
||
55 | |||
56 | public function testSetConfig() |
||
57 | { |
||
58 | $this->configManager->setConfig('foo', ['foo' => 'bar']); |
||
59 | $this->configManager->setConfig('foo', $config = ['foo' => 'baz']); |
||
60 | |||
61 | $this->assertSame($config, $this->configManager->getConfig('foo')); |
||
62 | } |
||
63 | |||
64 | public function testMergeConfig() |
||
65 | { |
||
66 | $this->configManager->setConfig('foo', $config1 = ['foo' => 'bar', 'bar' => 'foo']); |
||
67 | $this->configManager->mergeConfig('foo', $config2 = ['foo' => 'baz']); |
||
68 | |||
69 | $this->assertSame(array_merge($config1, $config2), $this->configManager->getConfig('foo')); |
||
70 | } |
||
71 | |||
72 | public function testDefaultConfig() |
||
73 | { |
||
74 | $this->configManager->setConfig('foo', ['foo' => 'bar']); |
||
75 | $this->configManager->setDefaultConfig($default = 'foo'); |
||
76 | |||
77 | $this->assertSame($default, $this->configManager->getDefaultConfig()); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @expectedException \FOS\CKEditorBundle\Exception\ConfigManagerException |
||
82 | * @expectedExceptionMessage The CKEditor config "foo" does not exist. |
||
83 | */ |
||
84 | public function testDefaultConfigWithInvalidValue() |
||
85 | { |
||
86 | $this->configManager->setDefaultConfig('foo'); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @expectedException \FOS\CKEditorBundle\Exception\ConfigManagerException |
||
91 | * @expectedExceptionMessage The CKEditor config "foo" does not exist. |
||
92 | */ |
||
93 | public function testGetConfigWithInvalidName() |
||
94 | { |
||
95 | $this->configManager->getConfig('foo'); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @expectedException \FOS\CKEditorBundle\Exception\ConfigManagerException |
||
100 | * @expectedExceptionMessage The CKEditor config "foo" does not exist. |
||
101 | */ |
||
102 | public function testMergeConfigWithInvalidName() |
||
103 | { |
||
104 | $this->configManager->mergeConfig('foo', ['foo' => 'bar']); |
||
105 | } |
||
106 | } |
||
107 |