Source of file CWPSiteConfigExtensionTest.php
Size: 2,816 Bytes - Last Modified: 2021-12-24T06:43:12+00:00
/var/www/docs.ssmods.com/process/src/tests/Extensions/CWPSiteConfigExtensionTest.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 | <?php namespace CWP\AgencyExtensions\Tests\Extensions; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\TextField; use SilverStripe\SiteConfig\SiteConfig; class CWPSiteConfigExtensionTest extends SapphireTest { protected $usesDatabase = true; /** * Ensure that the two "search caption" fields exist and are in the right tab */ public function testConfigurableSearchLabelsExistAndAreInCorrectTab() { $fields = SiteConfig::create()->getCMSFields(); $this->assertInstanceOf(TextField::class, $fields->fieldByName('Root.SearchOptions.EmptySearch')); $this->assertInstanceOf(TextField::class, $fields->fieldByName('Root.SearchOptions.NoSearchResults')); } /** * Ensure theme options are returned in the expected format without any excluded values */ public function testGetThemeOptionsExcluding() { Config::modify()->set(SiteConfig::class, 'theme_colors', [ 'color1' => [ 'Title' => 'Color 1', 'CSSClass' => 'color-1', 'Color' => '#111111', ], 'color2' => [ 'Title' => 'Color 2', 'CSSClass' => 'color-2', 'Color' => '#222222', ], ]); $siteConfig = SiteConfig::create(); // Returns all colors by default $themeColors = $siteConfig->getThemeOptionsExcluding(); $this->assertEquals([ [ 'Title' => 'Color 1', 'CSSClass' => 'color-1', 'Color' => '#111111', ], [ 'Title' => 'Color 2', 'CSSClass' => 'color-2', 'Color' => '#222222', ], ], $themeColors); // Returns colors without excludedColors $themeColors = $siteConfig->getThemeOptionsExcluding(['color-1']); $this->assertEquals([ [ 'Title' => 'Color 2', 'CSSClass' => 'color-2', 'Color' => '#222222', ], ], $themeColors); } public function testDefaultValuesAreNotWrittenWhenDisabled() { SiteConfig::config()->set('enable_theme_color_picker', false); $siteConfig = SiteConfig::create(); $siteConfig->write(); $this->assertEmpty($siteConfig->HeaderBackground, 'Colour fields should not be written when disabled'); } public function testDefaultValuesAreWrittenWhenEnabled() { SiteConfig::config()->set('enable_theme_color_picker', true); $siteConfig = SiteConfig::create(); $siteConfig->write(); $this->assertNotEmpty($siteConfig->HeaderBackground, 'Colour fields should be written when enabled'); } } |