3 namespace Drupal\config\Tests;
5 @trigger_error('The ' . __NAMESPACE__ . '\AssertConfigEntityImportTrait is deprecated in Drupal 8.4.1 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait. See https://www.drupal.org/node/2916197.', E_USER_DEPRECATED);
7 use Drupal\Core\Config\Entity\ConfigEntityInterface;
10 * Provides test assertions for testing config entity synchronization.
12 * Can be used by test classes that extend \Drupal\simpletest\WebTestBase or
13 * \Drupal\KernelTests\KernelTestBase.
15 * @deprecated in Drupal 8.4.1 and will be removed before Drupal 9.0.0.
16 * Use \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait.
18 * @see https://www.drupal.org/node/2916197
20 trait AssertConfigEntityImportTrait {
23 * Asserts that a config entity can be imported without changing it.
25 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
26 * The config entity to test importing.
28 public function assertConfigEntityImport(ConfigEntityInterface $entity) {
29 // Save original config information.
30 $entity_uuid = $entity->uuid();
31 $entity_type_id = $entity->getEntityTypeId();
32 $original_data = $entity->toArray();
33 // Copy everything to sync.
34 $this->copyConfig(\Drupal::service('config.storage'), \Drupal::service('config.storage.sync'));
35 // Delete the configuration from active. Don't worry about side effects of
36 // deleting config like fields cleaning up field storages. The coming import
37 // should recreate everything as necessary.
39 $this->configImporter()->reset()->import();
40 $imported_entity = \Drupal::entityManager()->loadEntityByUuid($entity_type_id, $entity_uuid);
41 $this->assertIdentical($original_data, $imported_entity->toArray());