Mercurial > hg > isophonics-drupal-site
comparison core/modules/config/src/Tests/AssertConfigEntityImportTrait.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\config\Tests; | |
4 | |
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); | |
6 | |
7 use Drupal\Core\Config\Entity\ConfigEntityInterface; | |
8 | |
9 /** | |
10 * Provides test assertions for testing config entity synchronization. | |
11 * | |
12 * Can be used by test classes that extend \Drupal\simpletest\WebTestBase or | |
13 * \Drupal\KernelTests\KernelTestBase. | |
14 * | |
15 * @deprecated in Drupal 8.4.1 and will be removed before Drupal 9.0.0. | |
16 * Use \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait. | |
17 * | |
18 * @see https://www.drupal.org/node/2916197 | |
19 */ | |
20 trait AssertConfigEntityImportTrait { | |
21 | |
22 /** | |
23 * Asserts that a config entity can be imported without changing it. | |
24 * | |
25 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity | |
26 * The config entity to test importing. | |
27 */ | |
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. | |
38 $entity->delete(); | |
39 $this->configImporter()->reset()->import(); | |
40 $imported_entity = \Drupal::entityManager()->loadEntityByUuid($entity_type_id, $entity_uuid); | |
41 $this->assertIdentical($original_data, $imported_entity->toArray()); | |
42 } | |
43 | |
44 } |