diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index 6fa40a3..4258f80 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -7,13 +7,11 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Database\Database; -use Drupal\Core\Config\ConfigImporter; -use Drupal\Core\Config\StorageComparer; -use Drupal\Core\Config\StorageInterface; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\Test\TestDatabase; use Drupal\Core\Utility\Error; +use Drupal\Tests\ConfigTestTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\Tests\SessionTestTrait; @@ -27,6 +25,11 @@ use SessionTestTrait; use RandomGeneratorTrait; use AssertHelperTrait; + // For backwards compatibility switch the visbility of the methods to public. + use ConfigTestTrait { + configImporter as public; + copyConfig as public; + } /** * The test run ID. @@ -1538,51 +1541,6 @@ public static function filePreDeleteCallback($path) { } /** - * Returns a ConfigImporter object to import test importing of configuration. - * - * @return \Drupal\Core\Config\ConfigImporter - * The ConfigImporter object. - */ - public 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. - */ - public 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)); - } - } - - /** * Configuration accessor for tests. Returns non-overridden configuration. * * @param $name diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index ed3875d..8807cb5 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -7,9 +7,6 @@ use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; -use Drupal\Core\Config\ConfigImporter; -use Drupal\Core\Config\StorageComparer; -use Drupal\Core\Config\StorageInterface; use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; @@ -20,6 +17,7 @@ use Drupal\Core\Site\Settings; use Drupal\simpletest\AssertContentTrait; use Drupal\simpletest\AssertHelperTrait; +use Drupal\Tests\ConfigTestTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\simpletest\TestServiceProvider; use Symfony\Component\DependencyInjection\Reference; @@ -55,6 +53,7 @@ use AssertContentTrait; use AssertHelperTrait; use RandomGeneratorTrait; + use ConfigTestTrait; /** * {@inheritdoc} @@ -1016,54 +1015,6 @@ protected function setSetting($name, $value) { } /** - * Returns a ConfigImporter object to import test configuration. - * - * @return \Drupal\Core\Config\ConfigImporter - * - * @todo Move into Config-specific test base class. - */ - 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 a source storage to a target storage. - * - * @param \Drupal\Core\Config\StorageInterface $source_storage - * The source config storage. - * @param \Drupal\Core\Config\StorageInterface $target_storage - * The target config storage. - * - * @todo Move into Config-specific test base class. - */ - 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)); - } - } - - /** * Stops test execution. */ protected function stop() { diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 3beb32f..a8560f0 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -56,6 +56,7 @@ use ContentTypeCreationTrait { createContentType as drupalCreateContentType; } + use ConfigTestTrait; /** * Class loader. diff --git a/core/tests/Drupal/Tests/ConfigTestTrait.php b/core/tests/Drupal/Tests/ConfigTestTrait.php new file mode 100644 index 0000000..330ff47 --- /dev/null +++ b/core/tests/Drupal/Tests/ConfigTestTrait.php @@ -0,0 +1,59 @@ +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)); + } + } + +}