Mercurial > hg > cmmr2012-drupal-site
diff core/tests/Drupal/Tests/ConfigTestTrait.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | 12f9dff5fda9 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/tests/Drupal/Tests/ConfigTestTrait.php Thu Jul 05 14:24:15 2018 +0000 @@ -0,0 +1,59 @@ +<?php + +namespace Drupal\Tests; + +use Drupal\Core\Config\ConfigImporter; +use Drupal\Core\Config\StorageComparer; +use Drupal\Core\Config\StorageInterface; + +/** + * Provides helper methods to deal with config system objects in tests. + */ +trait ConfigTestTrait { + + /** + * Returns a ConfigImporter object to import test configuration. + * + * @return \Drupal\Core\Config\ConfigImporter + * The config importer object. + */ + protected function configImporter() { + if (!$this->configImporter) { + // Set up the ConfigImporter object for testing. + $storage_comparer = new StorageComparer( + $this->container->get('config.storage.sync'), + $this->container->get('config.storage'), + $this->container->get('config.manager') + ); + $this->configImporter = new ConfigImporter( + $storage_comparer, + $this->container->get('event_dispatcher'), + $this->container->get('config.manager'), + $this->container->get('lock'), + $this->container->get('config.typed'), + $this->container->get('module_handler'), + $this->container->get('module_installer'), + $this->container->get('theme_handler'), + $this->container->get('string_translation') + ); + } + // Always recalculate the changelist when called. + return $this->configImporter->reset(); + } + + /** + * Copies configuration objects from source storage to target storage. + * + * @param \Drupal\Core\Config\StorageInterface $source_storage + * The source config storage service. + * @param \Drupal\Core\Config\StorageInterface $target_storage + * The target config storage service. + */ + protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) { + $target_storage->deleteAll(); + foreach ($source_storage->listAll() as $name) { + $target_storage->write($name, $source_storage->read($name)); + } + } + +}