function DefaultConfigTest::testModuleConfig
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::testModuleConfig()
- 10 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::testModuleConfig()
- 11.x core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::testModuleConfig()
Tests if installed config is equal to the exported config.
@dataProvider coreModuleListDataProvider
File
-
core/
tests/ Drupal/ KernelTests/ Config/ DefaultConfigTest.php, line 53
Class
- DefaultConfigTest
- Tests that the installed config matches the default config.
Namespace
Drupal\KernelTests\ConfigCode
public function testModuleConfig($module) {
// System and user are required in order to be able to install some of the
// other modules. Therefore they are put into static::$modules, which though
// doesn't install config files, so import those config files explicitly. Do
// this for all tests in case optional configuration depends on it.
$this->installConfig([
'system',
'user',
]);
$module_path = drupal_get_path('module', $module) . '/';
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = $this->container
->get('module_installer');
$module_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION);
$optional_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION);
if (empty($optional_config_storage->listAll()) && empty($module_config_storage->listAll())) {
$this->markTestSkipped("{$module} has no configuration to test");
}
// Work out any additional modules and themes that need installing to create
// an optional config.
$modules_to_install = [
$module,
];
$themes_to_install = [];
foreach ($optional_config_storage->listAll() as $config_name) {
$data = $optional_config_storage->read($config_name);
$dependency = new ConfigEntityDependency($config_name, $data);
$modules_to_install = array_merge($modules_to_install, $dependency->getDependencies('module'));
$themes_to_install = array_merge($themes_to_install, $dependency->getDependencies('theme'));
}
// Remove core because that cannot be installed.
$modules_to_install = array_diff(array_unique($modules_to_install), [
'core',
]);
$module_installer->install($modules_to_install);
$this->container
->get('theme_installer')
->install(array_unique($themes_to_install));
// Test configuration in the module's config/install directory.
$this->doTestsOnConfigStorage($module_config_storage, $module);
// Test configuration in the module's config/optional directory.
$this->doTestsOnConfigStorage($optional_config_storage, $module);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.