public function ModuleTestBase::assertModuleConfig in Drupal 8
Same name in this branch
- 8 core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertModuleConfig()
- 8 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.
Return value
bool|null TRUE if configuration has been installed, FALSE otherwise. Returns NULL if the module configuration directory does not exist or does not contain any configuration files.
File
- core/
modules/ system/ src/ Tests/ Module/ ModuleTestBase.php, line 106
Class
- ModuleTestBase
- Helper class for module test cases.
Namespace
Drupal\system\Tests\ModuleCode
public function assertModuleConfig($module) {
$module_config_dir = drupal_get_path('module', $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
->assertTrue($all_names);
// Look up each default configuration object name in the active
// configuration, and if it exists, remove it from the stack.
// Only default config that belongs to $module is guaranteed to exist; any
// other default config depends on whether other modules are enabled. Thus,
// list all default config once more, but filtered by $module.
$names = $module_file_storage
->listAll($module . '.');
foreach ($names as $key => $name) {
if ($this
->config($name)
->get()) {
unset($names[$key]);
}
}
// Verify that all configuration has been installed (which means that $names
// is empty).
return $this
->assertFalse($names, new FormattableMarkup('All default configuration of @module module found.', [
'@module' => $module,
]));
}