Completed
Pull Request — master (#47)
by Maximilian
63:15
created

StylesSetManagerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 48.39 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 30
loc 62
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Ivory\CKEditorBundle\Tests\Model;
13
14
use Ivory\CKEditorBundle\Model\StylesSetManager;
15
use Ivory\CKEditorBundle\Tests\AbstractTestCase;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class StylesSetManagerTest extends AbstractTestCase
21
{
22
    /**
23
     * @var StylesSetManager
24
     */
25
    private $stylesSetManager;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function setUp()
31
    {
32
        $this->stylesSetManager = new StylesSetManager();
33
    }
34
35
    public function testDefaultState()
36
    {
37
        $this->assertFalse($this->stylesSetManager->hasStylesSets());
38
        $this->assertSame([], $this->stylesSetManager->getStylesSets());
39
    }
40
41
    public function testInitialState()
42
    {
43
        $stylesSets = [
44
            'default' => [
45
                ['name' => 'Blue Title', 'element' => 'h2', 'styles' => ['color' => 'Blue']],
46
                ['name' => 'CSS Style', 'element' => 'span', 'attributes' => ['class' => 'my_style']],
47
            ],
48
        ];
49
50
        $this->stylesSetManager = new StylesSetManager($stylesSets);
51
52
        $this->assertTrue($this->stylesSetManager->hasStylesSets());
53
        $this->assertTrue($this->stylesSetManager->hasStylesSet('default'));
54
        $this->assertSame($stylesSets['default'], $this->stylesSetManager->getStylesSet('default'));
55
    }
56
57
    public function testTemplates()
58
    {
59
        $stylesSets = [
60
            'default' => [
61
                ['name' => 'Blue Title', 'element' => 'h2', 'styles' => ['color' => 'Blue']],
62
                ['name' => 'CSS Style', 'element' => 'span', 'attributes' => ['class' => 'my_style']],
63
            ],
64
        ];
65
66
        $this->stylesSetManager->setStylesSets($stylesSets);
67
68
        $this->assertTrue($this->stylesSetManager->hasStylesSets());
69
        $this->assertTrue($this->stylesSetManager->hasStylesSet('default'));
70
        $this->assertSame($stylesSets, $this->stylesSetManager->getStylesSets());
71
    }
72
73
    /**
74
     * @expectedException \Ivory\CKEditorBundle\Exception\StylesSetManagerException
75
     * @expectedExceptionMessage The CKEditor styles set "foo" does not exist.
76
     */
77
    public function testGetStylesSetWithInvalidValue()
78
    {
79
        $this->stylesSetManager->getStylesSet('foo');
80
    }
81
}
82