function ModuleTestBase::assertModuleConfig
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleConfig()
- 8.9.x core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertModuleConfig()
- 8.9.x core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleConfig()
- 10 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleConfig()
Asserts that the default configuration of a module has been installed.
Parameters
string $module: The name of the module.
1 call to ModuleTestBase::assertModuleConfig()
- ConfigImportAllTest::testInstallUninstall in core/
modules/ config/ tests/ src/ Functional/ ConfigImportAllTest.php - Tests that a fixed set of modules can be installed and uninstalled.
File
-
core/
modules/ system/ tests/ src/ Functional/ Module/ ModuleTestBase.php, line 81
Class
- ModuleTestBase
- Helper class for module test cases.
Namespace
Drupal\Tests\system\Functional\ModuleCode
public function assertModuleConfig($module) {
$module_config_dir = $this->getModulePath($module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
if (!is_dir($module_config_dir)) {
return;
}
$module_file_storage = new FileStorage($module_config_dir);
// Verify that the module's default config directory is not empty and
// contains default configuration files (instead of something else).
$all_names = $module_file_storage->listAll();
if (empty($all_names)) {
// Module has an empty config directory. For example it might contain a
// schema directory.
return;
}
$this->assertNotEmpty($all_names);
$module_config_dependencies = \Drupal::service('config.manager')->findConfigEntityDependencies('module', [
$module,
]);
// Look up each default configuration object name in the active
// configuration, and if it exists, remove it from the stack.
$names = $module_file_storage->listAll();
foreach ($names as $key => $name) {
if ($this->config($name)
->get()) {
unset($names[$key]);
}
// All configuration in a module's config/install directory should depend
// on the module as it must be removed on uninstall or the module will not
// be re-installable.
$this->assertTrue(str_starts_with($name, $module . '.') || isset($module_config_dependencies[$name]), "Configuration {$name} provided by {$module} in its config/install directory does not depend on it.");
}
// Verify that all configuration has been installed (which means that $names
// is empty).
$this->assertEmpty($names, "All default configuration of {$module} module found.");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.