044144483a1c6d4b2a87bb739a81ea5526816f00
[yaffs-website] / web / core / modules / config / src / Tests / AssertConfigEntityImportTrait.php
1 <?php
2
3 namespace Drupal\config\Tests;
4
5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
6
7 /**
8  * Provides test assertions for testing config entity synchronization.
9  *
10  * Can be used by test classes that extend \Drupal\simpletest\WebTestBase or
11  * \Drupal\KernelTests\KernelTestBase.
12  */
13 trait AssertConfigEntityImportTrait {
14
15   /**
16    * Asserts that a config entity can be imported without changing it.
17    *
18    * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
19    *   The config entity to test importing.
20    */
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.
31     $entity->delete();
32     $this->configImporter()->reset()->import();
33     $imported_entity = \Drupal::entityManager()->loadEntityByUuid($entity_type_id, $entity_uuid);
34     $this->assertIdentical($original_data, $imported_entity->toArray());
35   }
36
37 }