a077c25a853c305808c230bf39c0d9fc8d2f6408
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Theme / ThemeSettingsTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Theme;
4
5 use Drupal\Core\Config\InstallStorage;
6 use Drupal\Core\Extension\ExtensionDiscovery;
7 use Drupal\KernelTests\KernelTestBase;
8
9 /**
10  * Tests theme settings functionality.
11  *
12  * @group Theme
13  */
14 class ThemeSettingsTest extends KernelTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['system'];
22
23   /**
24    * List of discovered themes.
25    *
26    * @var array
27    */
28   protected $availableThemes;
29
30   protected function setUp() {
31     parent::setUp();
32     // Theme settings rely on System module's system.theme.global configuration.
33     $this->installConfig(['system']);
34
35     if (!isset($this->availableThemes)) {
36       $discovery = new ExtensionDiscovery(\Drupal::root());
37       $this->availableThemes = $discovery->scan('theme');
38     }
39   }
40
41   /**
42    * Tests that $theme.settings are imported and used as default theme settings.
43    */
44   public function testDefaultConfig() {
45     $name = 'test_basetheme';
46     $path = $this->availableThemes[$name]->getPath();
47     $this->assertTrue(file_exists("$path/" . InstallStorage::CONFIG_INSTALL_DIRECTORY . "/$name.settings.yml"));
48     $this->container->get('theme_handler')->install([$name]);
49     $this->assertIdentical(theme_get_setting('base', $name), 'only');
50   }
51
52   /**
53    * Tests that the $theme.settings default config file is optional.
54    */
55   public function testNoDefaultConfig() {
56     $name = 'stark';
57     $path = $this->availableThemes[$name]->getPath();
58     $this->assertFalse(file_exists("$path/" . InstallStorage::CONFIG_INSTALL_DIRECTORY . "/$name.settings.yml"));
59     $this->container->get('theme_handler')->install([$name]);
60     $this->assertNotNull(theme_get_setting('features.favicon', $name));
61   }
62
63 }