Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / ConfigTestTrait.php
1 <?php
2
3 namespace Drupal\Tests;
4
5 use Drupal\Core\Config\ConfigImporter;
6 use Drupal\Core\Config\StorageComparer;
7 use Drupal\Core\Config\StorageInterface;
8
9 /**
10  * Provides helper methods to deal with config system objects in tests.
11  */
12 trait ConfigTestTrait {
13
14   /**
15    * Returns a ConfigImporter object to import test configuration.
16    *
17    * @return \Drupal\Core\Config\ConfigImporter
18    *   The config importer object.
19    */
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')
27       );
28       $this->configImporter = new ConfigImporter(
29         $storage_comparer,
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')
38       );
39     }
40     // Always recalculate the changelist when called.
41     return $this->configImporter->reset();
42   }
43
44   /**
45    * Copies configuration objects from source storage to target storage.
46    *
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.
51    */
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));
56     }
57   }
58
59 }