BaseThemeMissingTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Theme/BaseThemeMissingTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Theme;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Extension\InfoParserException;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\KernelTests\KernelTestBase;
use org\bovigo\vfs\vfsStream;
class BaseThemeMissingTest extends KernelTestBase {
protected static $modules = [
'system',
];
protected $themeInstaller;
protected function setUp() : void {
parent::setUp();
$this->themeInstaller = $this->container
->get('theme_installer');
}
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_missing_base_theme' => [
'test_missing_base_theme.info.yml' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_missing_base_theme/test_missing_base_theme.info.yml'),
'test_missing_base_theme.theme' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_missing_base_theme/test_missing_base_theme.theme'),
],
],
], $vfs_root);
}
public function testMissingBaseThemeException() {
$this->container
->get('extension.list.theme')
->setExtensionDiscovery(new ExtensionDiscovery('vfs://core'));
$this
->expectException(InfoParserException::class);
$this
->expectExceptionMessage('Missing required key ("base theme") in themes/test_missing_base_theme/test_missing_base_theme.info.yml, see https://www.drupal.org/node/3066038');
$this->themeInstaller
->install([
'test_missing_base_theme',
]);
}
}
class VfsThemeExtensionList extends ThemeExtensionList {
protected $extensionDiscovery;
public function setExtensionDiscovery(ExtensionDiscovery $discovery) {
$this->extensionDiscovery = $discovery;
return $this;
}
public function getExtensionDiscovery() {
return $this->extensionDiscovery;
}
}