You are here

protected function DefaultConfigTest::doTestsOnConfigStorage in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::doTestsOnConfigStorage()
  2. 10 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::doTestsOnConfigStorage()

Tests that default config matches the installed config.

Parameters

\Drupal\Core\Config\StorageInterface $default_config_storage: The default config storage to test.

1 call to DefaultConfigTest::doTestsOnConfigStorage()
DefaultConfigTest::testModuleConfig in core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
Tests if installed config is equal to the exported config.

File

core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php, line 100

Class

DefaultConfigTest
Tests that the installed config matches the default config.

Namespace

Drupal\KernelTests\Config

Code

protected function doTestsOnConfigStorage(StorageInterface $default_config_storage, $module) {

  /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  $config_manager = $this->container
    ->get('config.manager');

  // Just connect directly to the config table so we don't need to worry about
  // the cache layer.
  $active_config_storage = $this->container
    ->get('config.storage');
  foreach ($default_config_storage
    ->listAll() as $config_name) {
    if ($active_config_storage
      ->exists($config_name)) {

      // If it is a config entity re-save it. This ensures that any
      // recalculation of dependencies does not cause config change.
      if ($entity_type = $config_manager
        ->getEntityTypeIdByName($config_name)) {
        $entity_storage = $config_manager
          ->getEntityTypeManager()
          ->getStorage($entity_type);
        $id = $entity_storage
          ->getIDFromConfigName($config_name, $entity_storage
          ->getEntityType()
          ->getConfigPrefix());
        $entity_storage
          ->load($id)
          ->calculateDependencies()
          ->save();
      }
      $result = $config_manager
        ->diff($default_config_storage, $active_config_storage, $config_name);

      // ::assertConfigDiff will throw an exception if the configuration is
      // different.
      $this
        ->assertNull($this
        ->assertConfigDiff($result, $config_name, static::$skippedConfig));
    }
    else {
      $info = $this->container
        ->get('extension.list.module')
        ->getExtensionInfo($module);
      if (!isset($info['package']) || $info['package'] !== 'Core (Experimental)') {
        $this
          ->fail("{$config_name} provided by {$module} does not exist after installing all dependencies");
      }
    }
  }
}