function DefaultConfigTest::doTestsOnConfigStorage

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::doTestsOnConfigStorage()
  2. 8.9.x core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php \Drupal\KernelTests\Config\DefaultConfigTest::doTestsOnConfigStorage()
  3. 11.x 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.

string $extension: The extension that is being tested.

string $type: The extension type to test.

1 call to DefaultConfigTest::doTestsOnConfigStorage()
DefaultConfigTest::assertExtensionConfig in core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php
Tests that the config provided by the extension is correct.

File

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

Class

DefaultConfigTest
Tests that the installed config matches the default config.

Namespace

Drupal\KernelTests\Config

Code

protected function doTestsOnConfigStorage(StorageInterface $default_config_storage, $extension, string $type = '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');
  /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
  $config_factory = $this->container
    ->get('config.factory');
  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();
      }
      else {
        // Ensure simple configuration is re-saved so any schema sorting is
        // applied.
        $config_factory->getEditable($config_name)
          ->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 {
      $data = $default_config_storage->read($config_name);
      $dependency = new ConfigEntityDependency($config_name, $data);
      if ($dependency->hasDependency('module', 'standard')) {
        // Skip configuration with a dependency on the standard profile. Such
        // configuration has probably been removed from the standard profile
        // and needs its own test.
        continue;
      }
      $info = $this->container
        ->get("extension.list.{$type}")
        ->getExtensionInfo($extension);
      if (!isset($info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]) || $info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] !== ExtensionLifecycle::EXPERIMENTAL) {
        $this->fail("{$config_name} provided by {$extension} does not exist after installing all dependencies");
      }
    }
  }
}

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