Completed
Pull Request — master (#47)
by Maximilian
62:08 queued 57s
created

ConfigManagerTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 87
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\CKEditorBundle\Tests\Model;
13
14
use FOS\CKEditorBundle\Model\ConfigManager;
15
use FOS\CKEditorBundle\Tests\AbstractTestCase;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
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