3 namespace Drupal\Tests\system\Functional\Theme;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests processing of theme .info.yml properties.
12 class ThemeInfoTest extends BrowserTestBase {
19 public static $modules = ['theme_test'];
22 * The theme handler used in this test for enabling themes.
24 * @var \Drupal\Core\Extension\ThemeHandler
26 protected $themeHandler;
29 * The theme manager used in this test.
31 * @var \Drupal\Core\Theme\ThemeManagerInterface
33 protected $themeManager;
36 * The state service used in this test.
38 * @var \Drupal\Core\State\StateInterface
45 protected function setUp() {
48 $this->themeHandler = $this->container->get('theme_handler');
49 $this->themeManager = $this->container->get('theme.manager');
50 $this->state = $this->container->get('state');
54 * Tests stylesheets-remove.
56 public function testStylesheets() {
57 $this->themeHandler->install(['test_basetheme', 'test_subtheme']);
58 $this->config('system.theme')
59 ->set('default', 'test_subtheme')
62 $base = drupal_get_path('theme', 'test_basetheme');
63 $sub = drupal_get_path('theme', 'test_subtheme') . '/css';
65 // All removals are expected to be based on a file's path and name and
66 // should work nevertheless.
67 $this->drupalGet('theme-test/info/stylesheets');
69 $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href' => "$base/base-add.css"])), "$base/base-add.css found");
70 $this->assertIdentical(0, count($this->xpath('//link[contains(@href, :href)]', [':href' => "base-remove.css"])), "base-remove.css not found");
72 $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href' => "$sub/sub-add.css"])), "$sub/sub-add.css found");
73 $this->assertIdentical(0, count($this->xpath('//link[contains(@href, :href)]', [':href' => "sub-remove.css"])), "sub-remove.css not found");
74 $this->assertIdentical(0, count($this->xpath('//link[contains(@href, :href)]', [':href' => "base-add.sub-remove.css"])), "base-add.sub-remove.css not found");
76 // Verify that CSS files with the same name are loaded from both the base theme and subtheme.
77 $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href' => "$base/samename.css"])), "$base/samename.css found");
78 $this->assertIdentical(1, count($this->xpath('//link[contains(@href, :href)]', [':href' => "$sub/samename.css"])), "$sub/samename.css found");
83 * Tests that changes to the info file are picked up.
85 public function testChanges() {
86 $this->themeHandler->install(['test_theme']);
87 $this->config('system.theme')->set('default', 'test_theme')->save();
88 $this->themeManager->resetActiveTheme();
90 $active_theme = $this->themeManager->getActiveTheme();
91 // Make sure we are not testing the wrong theme.
92 $this->assertEqual('test_theme', $active_theme->getName());
93 $this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
95 // @see theme_test_system_info_alter()
96 $this->state->set('theme_test.modify_info_files', TRUE);
97 drupal_flush_all_caches();
98 $active_theme = $this->themeManager->getActiveTheme();
99 $this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());