Passed
Push — master ( 25ca2a...86c16b )
by Robbie
02:46
created

CwpThemeHelperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 34.78 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 16
loc 46
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testDetectDefaultThemeViaSiteConfig() 0 14 1
A testDetectDefaultThemeViaConfig() 8 8 1
A testRenamedDefaultThemeCanBeDetected() 7 7 1

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
class CwpThemeHelperTest extends SapphireTest
4
{
5
    protected $usesDatabase = true;
6
7
    /**
8
     * Ensure that the "default" theme can be detected correctly via configuration settings
9
     */
10 View Code Duplication
    public function testDetectDefaultThemeViaConfig()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    {
12
        Config::inst()->update('SSViewer', 'theme_enabled', true);
13
        Config::inst()->update('SSViewer', 'theme', 'default');
14
        $this->assertTrue(CwpThemeHelper::singleton()->getIsDefaultTheme());
15
16
        Config::inst()->update('SSViewer', 'theme', 'starter');
17
        $this->assertFalse(CwpThemeHelper::singleton()->getIsDefaultTheme());
18
    }
19
20
    /**
21
     * Ensure that the "default" theme can be detected correctly via SiteConfig
22
     */
23
    public function testDetectDefaultThemeViaSiteConfig()
24
    {
25
        $siteConfig = SiteConfig::current_site_config();
26
        $siteConfig->Theme = 'default';
27
        $siteConfig->write();
28
        $siteConfig->flushCache();
29
30
        $this->assertTrue(CwpThemeHelper::singleton()->getIsDefaultTheme());
31
32
        $siteConfig->Theme = 'starter';
33
        $siteConfig->write();
34
        $siteConfig->flushCache();
35
36
        $this->assertFalse(CwpThemeHelper::singleton()->getIsDefaultTheme());
37
    }
38
39
    /**
40
     * Ensure that a customised default theme name can be detected
41
     */
42 View Code Duplication
    public function testRenamedDefaultThemeCanBeDetected()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        Config::inst()->update('SSViewer', 'theme_enabled', true);
45
        Config::inst()->update('SSViewer', 'theme', 'default-but-updated');
46
        Config::inst()->update('CwpThemeHelper', 'default_themes', array('default-but-updated'));
47
48
        $this->assertTrue(CwpThemeHelper::singleton()->getIsDefaultTheme());
49
    }
50
}
51