Completed
Pull Request — master (#47)
by Maximilian
392:42 queued 327:39
created

TemplateManagerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 55.56 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 40
loc 72
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\TemplateManager;
15
use Ivory\CKEditorBundle\Tests\AbstractTestCase;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class TemplateManagerTest extends AbstractTestCase
21
{
22
    /**
23
     * @var TemplateManager
24
     */
25
    private $templateManager;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function setUp()
31
    {
32
        $this->templateManager = new TemplateManager();
33
    }
34
35
    public function testDefaultState()
36
    {
37
        $this->assertFalse($this->templateManager->hasTemplates());
38
        $this->assertSame([], $this->templateManager->getTemplates());
39
    }
40
41
    public function testInitialState()
42
    {
43
        $templates = [
44
            'default' => [
45
                'imagesPath' => '/my/path',
46
                'templates' => [
47
                    [
48
                        'title' => 'My Template',
49
                        'html' => '<h1>Template</h1><p>Type your text here.</p>',
50
                    ],
51
                ],
52
            ],
53
        ];
54
55
        $this->templateManager = new TemplateManager($templates);
56
57
        $this->assertTrue($this->templateManager->hasTemplates());
58
        $this->assertTrue($this->templateManager->hasTemplate('default'));
59
        $this->assertSame($templates['default'], $this->templateManager->getTemplate('default'));
60
    }
61
62
    public function testTemplates()
63
    {
64
        $templates = [
65
            'default' => [
66
                'imagesPath' => '/my/path',
67
                'templates' => [
68
                    [
69
                        'title' => 'My Template',
70
                        'html' => '<h1>Template</h1><p>Type your text here.</p>',
71
                    ],
72
                ],
73
            ],
74
        ];
75
76
        $this->templateManager->setTemplates($templates);
77
78
        $this->assertTrue($this->templateManager->hasTemplates());
79
        $this->assertTrue($this->templateManager->hasTemplate('default'));
80
        $this->assertSame($templates, $this->templateManager->getTemplates());
81
    }
82
83
    /**
84
     * @expectedException \Ivory\CKEditorBundle\Exception\TemplateManagerException
85
     * @expectedExceptionMessage The CKEditor template "foo" does not exist.
86
     */
87
    public function testGetTemplateWithInvalidValue()
88
    {
89
        $this->templateManager->getTemplate('foo');
90
    }
91
}
92