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

DefaultThemeExtensionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 53.85 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 28
loc 52
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 2
A testAddCustomStylesAndScripts() 14 14 1
A testDefaultAssetsAreNotAddedWhenDisabledWithConfig() 13 13 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 DefaultThemeExtensionTest extends SapphireTest
4
{
5
    protected $requiredExtensions = array(
6
        'BasePage_Controller' => array('DefaultThemeExtension', 'DefaultThemeExtensionStub')
7
    );
8
9
    /**
10
     * @var BasePage_Controller
11
     */
12
    protected $controller;
13
14
    public function setUp()
15
    {
16
        parent::setUp();
17
18
        if (!is_dir(BASE_PATH . '/themes/default')) {
19
            $this->markTestSkipped('These tests require the default theme to be installed');
20
        }
21
22
        $this->controller = BasePage_Controller::create();
23
        $this->controller->init();
24
    }
25
26 View Code Duplication
    public function testAddCustomStylesAndScripts()
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...
27
    {
28
        Config::inst()->update('DefaultThemeExtension', 'disable_default_styles', false);
29
        Config::inst()->update('DefaultThemeExtension', 'disable_default_scripts', false);
30
31
        $this->controller->extend('onAfterInit');
32
33
        $javascript = Requirements::backend()->get_javascript();
34
        $this->assertContains('agency-extensions/tests/Extensions/Stub/agencytest.js', $javascript);
35
        $this->assertContains('themes/default/js/general.js', $javascript);
36
37
        $css = Requirements::backend()->get_css();
38
        $this->assertArrayHasKey('agency-extensions/tests/Extensions/Stub/agencytest.css', $css);
39
        $this->assertArrayHasKey('themes/default/css/layout.css', $css);
40
    }
41
42 View Code Duplication
    public function testDefaultAssetsAreNotAddedWhenDisabledWithConfig()
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('DefaultThemeExtension', 'disable_default_scripts', true);
45
        $this->controller->extend('onAfterInit');
46
        $javascript = Requirements::backend()->get_javascript();
47
        $this->assertContains('agency-extensions/tests/Extensions/Stub/agencytest.js', $javascript);
48
        $this->assertNotContains('themes/default/js/general.js', $javascript);
49
50
        Config::inst()->update('DefaultThemeExtension', 'disable_default_styles', true);
51
        $this->controller->extend('onAfterInit');
52
        $css = Requirements::backend()->get_css();
53
        $this->assertArrayHasKey('agency-extensions/tests/Extensions/Stub/agencytest.css', $css);
54
        $this->assertArrayNotHasKey('themes/default/css/layout.css', $css);
55
    }
56
}
57