annotate core/tests/Drupal/Tests/ConfigTestTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
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@18 7 use Drupal\Core\Config\StorageCopyTrait;
Chris@0 8 use Drupal\Core\Config\StorageInterface;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Provides helper methods to deal with config system objects in tests.
Chris@0 12 */
Chris@0 13 trait ConfigTestTrait {
Chris@0 14
Chris@18 15 use StorageCopyTrait;
Chris@18 16
Chris@0 17 /**
Chris@0 18 * Returns a ConfigImporter object to import test configuration.
Chris@0 19 *
Chris@0 20 * @return \Drupal\Core\Config\ConfigImporter
Chris@0 21 * The config importer object.
Chris@0 22 */
Chris@0 23 protected function configImporter() {
Chris@0 24 if (!$this->configImporter) {
Chris@0 25 // Set up the ConfigImporter object for testing.
Chris@0 26 $storage_comparer = new StorageComparer(
Chris@0 27 $this->container->get('config.storage.sync'),
Chris@18 28 $this->container->get('config.storage')
Chris@0 29 );
Chris@0 30 $this->configImporter = new ConfigImporter(
Chris@0 31 $storage_comparer,
Chris@0 32 $this->container->get('event_dispatcher'),
Chris@0 33 $this->container->get('config.manager'),
Chris@0 34 $this->container->get('lock'),
Chris@0 35 $this->container->get('config.typed'),
Chris@0 36 $this->container->get('module_handler'),
Chris@0 37 $this->container->get('module_installer'),
Chris@0 38 $this->container->get('theme_handler'),
Chris@0 39 $this->container->get('string_translation')
Chris@0 40 );
Chris@0 41 }
Chris@0 42 // Always recalculate the changelist when called.
Chris@0 43 return $this->configImporter->reset();
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Copies configuration objects from source storage to target storage.
Chris@0 48 *
Chris@0 49 * @param \Drupal\Core\Config\StorageInterface $source_storage
Chris@0 50 * The source config storage service.
Chris@0 51 * @param \Drupal\Core\Config\StorageInterface $target_storage
Chris@0 52 * The target config storage service.
Chris@0 53 */
Chris@0 54 protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) {
Chris@18 55 static::replaceStorageContents($source_storage, $target_storage);
Chris@0 56 }
Chris@0 57
Chris@0 58 }