3 namespace Drupal\KernelTests\Core\Theme;
5 use Drupal\Core\Config\InstallStorage;
6 use Drupal\Core\Extension\ExtensionDiscovery;
7 use Drupal\KernelTests\KernelTestBase;
10 * Tests theme settings functionality.
14 class ThemeSettingsTest extends KernelTestBase {
21 public static $modules = ['system'];
24 * List of discovered themes.
28 protected $availableThemes;
30 protected function setUp() {
32 // Theme settings rely on System module's system.theme.global configuration.
33 $this->installConfig(['system']);
35 if (!isset($this->availableThemes)) {
36 $discovery = new ExtensionDiscovery($this->root);
37 $this->availableThemes = $discovery->scan('theme');
42 * Tests that $theme.settings are imported and used as default theme settings.
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');
53 * Tests that the $theme.settings default config file is optional.
55 public function testNoDefaultConfig() {
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));
64 * Tests that the default logo config can be overridden.
66 public function testLogoConfig() {
67 /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */
68 $theme_handler = $this->container->get('theme_handler');
69 $theme_handler->install(['stark']);
70 $theme = $theme_handler->getTheme('stark');
72 // Tests default behaviour.
73 $expected = '/' . $theme->getPath() . '/logo.svg';
74 $this->assertEquals($expected, theme_get_setting('logo.url', 'stark'));
76 $config = $this->config('stark.settings');
77 drupal_static_reset('theme_get_setting');
80 'default_logo' => FALSE,
81 'logo_path' => 'public://logo_with_scheme.png',
83 theme_settings_convert_to_config($values, $config)->save();
85 // Tests logo path with scheme.
86 $expected = file_url_transform_relative(file_create_url('public://logo_with_scheme.png'));
87 $this->assertEquals($expected, theme_get_setting('logo.url', 'stark'));
90 'default_logo' => FALSE,
91 'logo_path' => $theme->getPath() . '/logo_relative_path.gif',
93 theme_settings_convert_to_config($values, $config)->save();
95 drupal_static_reset('theme_get_setting');
97 // Tests relative path.
98 $expected = '/' . $theme->getPath() . '/logo_relative_path.gif';
99 $this->assertEquals($expected, theme_get_setting('logo.url', 'stark'));
101 $theme_handler->install(['test_theme']);
102 $theme_handler->setDefault('test_theme');
103 $theme = $theme_handler->getTheme('test_theme');
105 drupal_static_reset('theme_get_setting');
107 // Tests logo set in test_theme.info.yml.
108 $expected = '/' . $theme->getPath() . '/images/logo2.svg';
109 $this->assertEquals($expected, theme_get_setting('logo.url', 'test_theme'));