View source
<?php
namespace Drupal\Tests\system\Functional\Theme;
use Drupal\Tests\BrowserTestBase;
class ThemeInfoTest extends BrowserTestBase {
protected static $modules = [
'theme_test',
];
protected $defaultTheme = 'stark';
protected $themeInstaller;
protected $themeManager;
protected $state;
protected function setUp() : void {
parent::setUp();
$this->themeInstaller = $this->container
->get('theme_installer');
$this->themeManager = $this->container
->get('theme.manager');
$this->state = $this->container
->get('state');
}
public function testStylesheets() {
$this->themeInstaller
->install([
'test_basetheme',
'test_subtheme',
]);
$this
->config('system.theme')
->set('default', 'test_subtheme')
->save();
$base = $this
->getThemePath('test_basetheme');
$sub = $this
->getThemePath('test_subtheme') . '/css';
$this
->drupalGet('theme-test/info/stylesheets');
$this
->assertCount(1, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "{$base}/base-add.css",
]), "{$base}/base-add.css found");
$this
->assertCount(0, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "base-remove.css",
]), "base-remove.css not found");
$this
->assertCount(1, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "{$sub}/sub-add.css",
]), "{$sub}/sub-add.css found");
$this
->assertCount(0, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "sub-remove.css",
]), "sub-remove.css not found");
$this
->assertCount(0, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "base-add.sub-remove.css",
]), "base-add.sub-remove.css not found");
$this
->assertCount(1, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "{$base}/samename.css",
]), "{$base}/samename.css found");
$this
->assertCount(1, $this
->xpath('//link[contains(@href, :href)]', [
':href' => "{$sub}/samename.css",
]), "{$sub}/samename.css found");
}
public function testChanges() {
$this->themeInstaller
->install([
'test_theme',
]);
$this
->config('system.theme')
->set('default', 'test_theme')
->save();
$this->themeManager
->resetActiveTheme();
$active_theme = $this->themeManager
->getActiveTheme();
$this
->assertEquals('test_theme', $active_theme
->getName());
$this
->assertEquals([
'classy/base',
'classy/messages',
'core/normalize',
'test_theme/global-styling',
], $active_theme
->getLibraries());
$this->state
->set('theme_test.modify_info_files', TRUE);
$this
->resetAll();
$active_theme = $this->themeManager
->getActiveTheme();
$this
->assertEquals([
'classy/base',
'classy/messages',
'core/normalize',
'test_theme/global-styling',
'core/backbone',
], $active_theme
->getLibraries());
}
}