Completed
Pull Request — master (#13)
by Scott
03:29
created

testConfigurableSearchLabelsExistAndAreInCorrectTab()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
        // Case where ColorPaletteField exists
44
        $siteConfig->setUseColorPaletteField(true);
45
        // Returns all colors by default
46
        $themeColors = $siteConfig->getThemeOptionsExcluding();
47
        $this->assertEquals([
48
            'color-1' => '#111111',
49
            'color-2' => '#222222',
50
        ], $themeColors);
51
52
        // Returns colors without excludedColors
53
        $themeColors = $siteConfig->getThemeOptionsExcluding(['color-1']);
54
        $this->assertEquals([
55
            'color-2' => '#222222',
56
        ], $themeColors);
57
58
        // Case where ColorPaletteField doesn't exists
59
        $siteConfig->setUseColorPaletteField(false);
60
        // Returns all colors by default
61
        $themeColors = $siteConfig->getThemeOptionsExcluding();
62
        $this->assertEquals([
63
            'color-1' => 'Color 1',
64
            'color-2' => 'Color 2',
65
        ], $themeColors);
66
67
        // Returns colors without excludedColors
68
        $themeColors = $siteConfig->getThemeOptionsExcluding(['color-1']);
69
        $this->assertEquals([
70
            'color-2' => 'Color 2',
71
        ], $themeColors);
72
    }
73
}
74