You are here

function ModuleTestBase::assertModuleConfig in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Module/ModuleTestBase.php \Drupal\system\Tests\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 TRUE if configuration has been installed, FALSE otherwise.

2 calls to ModuleTestBase::assertModuleConfig()
ConfigImportAllTest::testInstallUninstall in core/modules/config/src/Tests/ConfigImportAllTest.php
Tests that a fixed set of modules can be installed and uninstalled.
InstallUninstallTest::assertModuleSuccessfullyInstalled in core/modules/system/src/Tests/Module/InstallUninstallTest.php
Asserts that a module was successfully installed.

File

core/modules/system/src/Tests/Module/ModuleTestBase.php, line 98
Contains \Drupal\system\Tests\Module\ModuleTestBase.

Class

ModuleTestBase
Helper class for module test cases.

Namespace

Drupal\system\Tests\Module

Code

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, format_string('All default configuration of @module module found.', array(
    '@module' => $module,
  )));
}