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