Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\config\Tests;
|
Chris@0
|
4
|
Chris@0
|
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);
|
Chris@0
|
6
|
Chris@0
|
7 use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Provides test assertions for testing config entity synchronization.
|
Chris@0
|
11 *
|
Chris@0
|
12 * Can be used by test classes that extend \Drupal\simpletest\WebTestBase or
|
Chris@0
|
13 * \Drupal\KernelTests\KernelTestBase.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @deprecated in Drupal 8.4.1 and will be removed before Drupal 9.0.0.
|
Chris@0
|
16 * Use \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @see https://www.drupal.org/node/2916197
|
Chris@0
|
19 */
|
Chris@0
|
20 trait AssertConfigEntityImportTrait {
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Asserts that a config entity can be imported without changing it.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
|
Chris@0
|
26 * The config entity to test importing.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function assertConfigEntityImport(ConfigEntityInterface $entity) {
|
Chris@0
|
29 // Save original config information.
|
Chris@0
|
30 $entity_uuid = $entity->uuid();
|
Chris@0
|
31 $entity_type_id = $entity->getEntityTypeId();
|
Chris@0
|
32 $original_data = $entity->toArray();
|
Chris@0
|
33 // Copy everything to sync.
|
Chris@0
|
34 $this->copyConfig(\Drupal::service('config.storage'), \Drupal::service('config.storage.sync'));
|
Chris@0
|
35 // Delete the configuration from active. Don't worry about side effects of
|
Chris@0
|
36 // deleting config like fields cleaning up field storages. The coming import
|
Chris@0
|
37 // should recreate everything as necessary.
|
Chris@0
|
38 $entity->delete();
|
Chris@0
|
39 $this->configImporter()->reset()->import();
|
Chris@18
|
40 $imported_entity = \Drupal::service('entity.repository')->loadEntityByUuid($entity_type_id, $entity_uuid);
|
Chris@0
|
41 $this->assertIdentical($original_data, $imported_entity->toArray());
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 }
|