Completed
Push — master ( 991aa3...ce6ba6 )
by
unknown
22s
created

CWPSiteConfigExtensionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testConfigurableSearchLabelsExistAndAreInCorrectTab() 0 5 1
A testGetThemeOptionsExcluding() 0 40 1
1
<?php
2
3
namespace CWP\AgencyExtensions\Tests\Extensions;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\TextField;
8
use SilverStripe\SiteConfig\SiteConfig;
9
10
class CWPSiteConfigExtensionTest extends SapphireTest
11
{
12
    protected $usesDatabase = true;
13
14
    /**
15
     * Ensure that the two "search caption" fields exist and are in the right tab
16
     */
17
    public function testConfigurableSearchLabelsExistAndAreInCorrectTab()
18
    {
19
        $fields = SiteConfig::create()->getCMSFields();
20
        $this->assertInstanceOf(TextField::class, $fields->fieldByName('Root.SearchOptions.EmptySearch'));
21
        $this->assertInstanceOf(TextField::class, $fields->fieldByName('Root.SearchOptions.NoSearchResults'));
22
    }
23
24
    /**
25
     * Ensure theme options are returned in the expected format without any excluded values
26
     */
27
    public function testGetThemeOptionsExcluding()
28
    {
29
        Config::modify()->set(SiteConfig::class, 'theme_colors', [
30
            'color1' => [
31
                'Title' => 'Color 1',
32
                'CSSClass' => 'color-1',
33
                'Color' => '#111111',
34
            ],
35
            'color2' => [
36
                'Title' => 'Color 2',
37
                'CSSClass' => 'color-2',
38
                'Color' => '#222222',
39
            ],
40
        ]);
41
        $siteConfig = SiteConfig::create();
42
43
        // Returns all colors by default
44
        $themeColors = $siteConfig->getThemeOptionsExcluding();
45
        $this->assertEquals([
46
            [
47
                'Title' => 'Color 1',
48
                'CSSClass' => 'color-1',
49
                'Color' => '#111111',
50
            ],
51
            [
52
                'Title' => 'Color 2',
53
                'CSSClass' => 'color-2',
54
                'Color' => '#222222',
55
            ],
56
        ], $themeColors);
57
58
        // Returns colors without excludedColors
59
        $themeColors = $siteConfig->getThemeOptionsExcluding(['color-1']);
60
        $this->assertEquals([
61
            [
62
                'Title' => 'Color 2',
63
                'CSSClass' => 'color-2',
64
                'Color' => '#222222',
65
            ],
66
        ], $themeColors);
67
    }
68
}
69