|
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() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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
|
|
|
|
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.