ExcludedModulesEventSubscriberTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Config/ExcludedModulesEventSubscriberTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Config;
use Drupal\KernelTests\KernelTestBase;
class ExcludedModulesEventSubscriberTest extends KernelTestBase {
protected static $modules = [
'system',
'config_test',
'config_exclude_test',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
'config_test',
'config_exclude_test',
]);
$this
->setSetting('config_exclude_modules', [
'config_test',
]);
}
public function testExcludedModules() {
$active = $this->container
->get('config.storage');
$this
->assertNotEmpty($active
->listAll('config_test.'));
$this
->assertNotEmpty($active
->listAll('system.'));
$this
->assertArrayHasKey('config_test', $active
->read('core.extension')['module']);
$collection = $this
->randomMachineName();
foreach ($active
->listAll() as $config) {
$active
->createCollection($collection)
->write($config, $active
->read($config));
}
$export = $this->container
->get('config.storage.export');
$this
->assertEmpty($export
->listAll('config_test.'));
$this
->assertNotEmpty($export
->listAll('system.'));
$this
->assertEmpty($export
->createCollection($collection)
->listAll('config_test.'));
$this
->assertNotEmpty($export
->createCollection($collection)
->listAll('system.'));
$this
->assertArrayNotHasKey('config_test', $export
->read('core.extension')['module']);
$this
->assertArrayHasKey('config_exclude_test', $export
->read('core.extension')['module']);
$this
->assertFalse($export
->exists('system.menu.exclude_test'));
$this
->assertFalse($export
->exists('system.menu.indirect_exclude_test'));
$import = $this->container
->get('config.import_transformer')
->transform($export);
$this
->assertNotEmpty($import
->listAll('config_test.'));
$this
->assertNotEmpty($import
->listAll('system.'));
$this
->assertNotEmpty($import
->createCollection($collection)
->listAll('config_test.'));
$this
->assertNotEmpty($import
->createCollection($collection)
->listAll('system.'));
$this
->assertArrayHasKey('config_test', $import
->read('core.extension')['module']);
$this
->assertArrayHasKey('config_exclude_test', $import
->read('core.extension')['module']);
$this
->assertTrue($import
->exists('system.menu.exclude_test'));
$this
->assertTrue($import
->exists('system.menu.indirect_exclude_test'));
$this
->assertEquals($active
->read('core.extension'), $import
->read('core.extension'));
$this
->assertEquals($active
->listAll(), $import
->listAll());
foreach ($active
->listAll() as $config) {
$this
->assertEquals($active
->read($config), $import
->read($config));
}
$this
->setSetting('config_exclude_modules', []);
$this->container
->get('kernel')
->rebuildContainer();
$export = $this->container
->get('config.storage.export');
$this
->assertArrayHasKey('config_test', $export
->read('core.extension')['module']);
}
}