BaseThemeDefaultDeprecationTest.php in Drupal 8
File
core/tests/Drupal/KernelTests/Core/Theme/BaseThemeDefaultDeprecationTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Theme;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Extension\InfoParser;
use Drupal\Core\Extension\InfoParserInterface;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\KernelTests\KernelTestBase;
use org\bovigo\vfs\vfsStream;
class BaseThemeDefaultDeprecationTest extends KernelTestBase {
public static $modules = [
'system',
];
protected $themeInstaller;
protected $themeManager;
protected function setUp() {
parent::setUp();
$this->themeInstaller = $this->container
->get('theme_installer');
$this->themeManager = $this->container
->get('theme.manager');
}
public function register(ContainerBuilder $container) {
parent::register($container);
$container
->getDefinition('extension.list.theme')
->setClass(VfsThemeExtensionList::class);
}
protected function setUpFilesystem() {
parent::setUpFilesystem();
$vfs_root = vfsStream::setup('core');
vfsStream::create([
'themes' => [
'test_stable' => [
'test_stable.info.yml' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_stable/test_stable.info.yml'),
'test_stable.theme' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_stable/test_stable.theme'),
],
'stable' => [
'stable.info.yml' => file_get_contents(DRUPAL_ROOT . '/core/themes/stable/stable.info.yml'),
'stable.theme' => file_get_contents(DRUPAL_ROOT . '/core/themes/stable/stable.theme'),
],
],
], $vfs_root);
}
public function testStableIsDefault() {
$this->container
->get('extension.list.theme')
->setExtensionDiscovery(new ExtensionDiscovery('vfs://core'))
->setInfoParser(new VfsInfoParser('vfs:/'));
$this->themeInstaller
->install([
'test_stable',
]);
$this
->config('system.theme')
->set('default', 'test_stable')
->save();
$theme = $this->themeManager
->getActiveTheme();
$base_themes = $theme
->getBaseThemeExtensions();
$base_theme = reset($base_themes);
$this
->assertTrue($base_theme
->getName() == 'stable', "Stable theme is the base theme if a theme hasn't decided to opt out.");
}
}
class VfsThemeExtensionList extends ThemeExtensionList {
protected $extensionDiscovery;
public function setExtensionDiscovery(ExtensionDiscovery $discovery) {
$this->extensionDiscovery = $discovery;
return $this;
}
public function setInfoParser(InfoParserInterface $info_parser) {
$this->infoParser = $info_parser;
return $this;
}
public function getExtensionDiscovery() {
return $this->extensionDiscovery;
}
}
class VfsInfoParser extends InfoParser {
public function parse($filename) {
return parent::parse("vfs://core/{$filename}");
}
}