3 namespace Drupal\Tests;
5 use Drupal\Core\Config\ConfigImporter;
6 use Drupal\Core\Config\StorageComparer;
7 use Drupal\Core\Config\StorageInterface;
10 * Provides helper methods to deal with config system objects in tests.
12 trait ConfigTestTrait {
15 * Returns a ConfigImporter object to import test configuration.
17 * @return \Drupal\Core\Config\ConfigImporter
18 * The config importer object.
20 protected function configImporter() {
21 if (!$this->configImporter) {
22 // Set up the ConfigImporter object for testing.
23 $storage_comparer = new StorageComparer(
24 $this->container->get('config.storage.sync'),
25 $this->container->get('config.storage'),
26 $this->container->get('config.manager')
28 $this->configImporter = new ConfigImporter(
30 $this->container->get('event_dispatcher'),
31 $this->container->get('config.manager'),
32 $this->container->get('lock'),
33 $this->container->get('config.typed'),
34 $this->container->get('module_handler'),
35 $this->container->get('module_installer'),
36 $this->container->get('theme_handler'),
37 $this->container->get('string_translation')
40 // Always recalculate the changelist when called.
41 return $this->configImporter->reset();
45 * Copies configuration objects from source storage to target storage.
47 * @param \Drupal\Core\Config\StorageInterface $source_storage
48 * The source config storage service.
49 * @param \Drupal\Core\Config\StorageInterface $target_storage
50 * The target config storage service.
52 protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) {
53 $target_storage->deleteAll();
54 foreach ($source_storage->listAll() as $name) {
55 $target_storage->write($name, $source_storage->read($name));