ConfigImportThemeInstallTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Theme/ConfigImportThemeInstallTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Theme;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\KernelTests\KernelTestBase;
class ConfigImportThemeInstallTest extends KernelTestBase {
protected static $modules = [
'system',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
]);
}
public function testConfigImportWithThemeWithModuleDependencies() {
$this->container
->get('module_installer')
->install([
'test_module_required_by_theme',
'test_another_module_required_by_theme',
]);
$this->container
->get('theme_installer')
->install([
'test_theme_depending_on_modules',
]);
$this
->assertTrue($this->container
->get('theme_handler')
->themeExists('test_theme_depending_on_modules'), 'test_theme_depending_on_modules theme installed');
$sync = $this->container
->get('config.storage.sync');
$this
->copyConfig($this->container
->get('config.storage'), $sync);
$extensions = $sync
->read('core.extension');
unset($extensions['module']['test_module_required_by_theme']);
$sync
->write('core.extension', $extensions);
try {
$this
->configImporter()
->validate();
$this
->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
} catch (ConfigImporterException $e) {
$error_message = 'Unable to uninstall the <em class="placeholder">Test Module Required by Theme</em> module because: Required by the theme: Test Theme Depending on Modules.';
$this
->assertStringContainsString($error_message, $e
->getMessage(), 'There were errors validating the config synchronization.');
$error_log = $this->configImporter
->getErrors();
$this
->assertEquals([
$error_message,
], $error_log);
}
unset($extensions['module']['test_another_module_required_by_theme']);
unset($extensions['theme']['test_theme_depending_on_modules']);
$sync
->write('core.extension', $extensions);
$this
->configImporter()
->import();
$this
->assertFalse($this->container
->get('theme_handler')
->themeExists('test_theme_depending_on_modules'), 'test_theme_depending_on_modules theme uninstalled by configuration import');
$extensions['theme']['test_theme_depending_on_modules'] = 0;
$extensions['module']['test_another_module_required_by_theme'] = 0;
$sync
->write('core.extension', $extensions);
try {
$this
->configImporter()
->validate();
$this
->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
} catch (ConfigImporterException $e) {
$error_message = 'Unable to install the <em class="placeholder">Test Theme Depending on Modules</em> theme since it requires the <em class="placeholder">Test Module Required by Theme</em> module.';
$this
->assertStringContainsString($error_message, $e
->getMessage(), 'There were errors validating the config synchronization.');
$error_log = $this->configImporter
->getErrors();
$this
->assertEquals([
$error_message,
], $error_log);
}
$extensions['module']['test_module_required_by_theme'] = 0;
$sync
->write('core.extension', $extensions);
$this
->configImporter()
->import();
$this
->assertTrue($this->container
->get('theme_handler')
->themeExists('test_theme_depending_on_modules'), 'test_theme_depending_on_modules theme installed');
}
}