You are here

public function DefaultConfigTest::testModuleConfig in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::testModuleConfig()

Tests if installed config is equal to the exported config.

@dataProvider providerTestModuleConfig

File

core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php, line 58
Contains \Drupal\KernelTests\Config\DefaultConfigTest.

Class

DefaultConfigTest
Tests that the installed config matches the default config.

Namespace

Drupal\KernelTests\Config

Code

public function testModuleConfig($module) {

  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = $this->container
    ->get('module_installer');

  /** @var \Drupal\Core\Config\StorageInterface $active_config_storage */
  $active_config_storage = $this->container
    ->get('config.storage');

  /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  $config_manager = $this->container
    ->get('config.manager');
  $module_installer
    ->install([
    $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.
  switch ($module) {
    case 'system':
    case 'user':
      $this
        ->installConfig([
        $module,
      ]);
      break;
  }
  $default_install_path = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
  $module_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);

  // The following config entries are changed on module install, so compare
  // them doesn't make sense.
  $skipped_config = [];
  $skipped_config['locale.settings'][] = 'path: ';
  $skipped_config['syslog.settings'][] = 'facility: ';

  // @todo Figure out why simpletest.settings is not installed.
  $skipped_config['simpletest.settings'] = TRUE;

  // Compare the installed config with the one in the module directory.
  foreach ($module_config_storage
    ->listAll() as $config_name) {
    $result = $config_manager
      ->diff($module_config_storage, $active_config_storage, $config_name);
    $this
      ->assertConfigDiff($result, $config_name, $skipped_config);
  }
}