3 namespace Drupal\config\Tests;
5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
8 * Provides test assertions for testing config entity synchronization.
10 * Can be used by test classes that extend \Drupal\simpletest\WebTestBase or
11 * \Drupal\KernelTests\KernelTestBase.
13 trait AssertConfigEntityImportTrait {
16 * Asserts that a config entity can be imported without changing it.
18 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
19 * The config entity to test importing.
21 public function assertConfigEntityImport(ConfigEntityInterface $entity) {
22 // Save original config information.
23 $entity_uuid = $entity->uuid();
24 $entity_type_id = $entity->getEntityTypeId();
25 $original_data = $entity->toArray();
26 // Copy everything to sync.
27 $this->copyConfig(\Drupal::service('config.storage'), \Drupal::service('config.storage.sync'));
28 // Delete the configuration from active. Don't worry about side effects of
29 // deleting config like fields cleaning up field storages. The coming import
30 // should recreate everything as necessary.
32 $this->configImporter()->reset()->import();
33 $imported_entity = \Drupal::entityManager()->loadEntityByUuid($entity_type_id, $entity_uuid);
34 $this->assertIdentical($original_data, $imported_entity->toArray());