function ModuleTestBase::assertModuleConfig

Same name in this branch
  1. 8.9.x core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\Module\ModuleTestBase::assertModuleConfig()
Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleConfig()
  2. 10 core/modules/system/tests/src/Functional/Module/ModuleTestBase.php \Drupal\Tests\system\Functional\Module\ModuleTestBase::assertModuleConfig()
  3. 11.x 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.

2 calls 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.
InstallUninstallTest::assertModuleSuccessfullyInstalled in core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
Asserts that a module was successfully installed.

File

core/modules/system/tests/src/Functional/Module/ModuleTestBase.php, line 102

Class

ModuleTestBase
Helper class for module test cases.

Namespace

Drupal\Tests\system\Functional\Module

Code

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->assertNotEmpty($all_names);
    $module_config_dependencies = \Drupal::service('config.manager')->findConfigEntityDependents('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(strpos($name, $module . '.') === 0 || 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).
    return $this->assertEmpty($names, new FormattableMarkup('All default configuration of @module module found.', [
        '@module' => $module,
    ]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.