|
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
|
|
|
public function testDefaultValuesAreNotWrittenWhenDisabled() |
|
70
|
|
|
{ |
|
71
|
|
|
SiteConfig::config()->set('enable_theme_color_picker', false); |
|
72
|
|
|
|
|
73
|
|
|
$siteConfig = SiteConfig::create(); |
|
74
|
|
|
$siteConfig->write(); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEmpty($siteConfig->HeaderBackground, 'Colour fields should not be written when disabled'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testDefaultValuesAreWrittenWhenEnabled() |
|
80
|
|
|
{ |
|
81
|
|
|
SiteConfig::config()->set('enable_theme_color_picker', true); |
|
82
|
|
|
|
|
83
|
|
|
$siteConfig = SiteConfig::create(); |
|
84
|
|
|
$siteConfig->write(); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertNotEmpty($siteConfig->HeaderBackground, 'Colour fields should be written when enabled'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|