3 namespace Drupal\KernelTests\Core\Config;
5 use Drupal\Core\Config\ConfigDuplicateUUIDException;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests sync and importing config entities with IDs and UUIDs that match
14 class ConfigEntityStorageTest extends KernelTestBase {
21 public static $modules = ['config_test'];
24 * Tests creating configuration entities with changed UUIDs.
26 public function testUUIDConflict() {
27 $entity_type = 'config_test';
29 // Load the original configuration entity.
30 $storage = $this->container->get('entity_type.manager')
31 ->getStorage($entity_type);
32 $storage->create(['id' => $id])->save();
33 $entity = $storage->load($id);
35 $original_properties = $entity->toArray();
37 // Override with a new UUID and try to save.
38 $new_uuid = $this->container->get('uuid')->generate();
39 $entity->set('uuid', $new_uuid);
43 $this->fail('Exception thrown when attempting to save a configuration entity with a UUID that does not match the existing UUID.');
45 catch (ConfigDuplicateUUIDException $e) {
46 $this->pass(format_string('Exception thrown when attempting to save a configuration entity with a UUID that does not match existing data: %e.', ['%e' => $e]));
49 // Ensure that the config entity was not corrupted.
50 $entity = entity_load('config_test', $entity->id(), TRUE);
51 $this->assertIdentical($entity->toArray(), $original_properties);
55 * Tests the hasData() method for config entity storage.
57 * @covers \Drupal\Core\Config\Entity\ConfigEntityStorage::hasData
59 public function testHasData() {
60 $storage = \Drupal::entityTypeManager()->getStorage('config_test');
61 $this->assertFalse($storage->hasData());
63 // Add a test config entity and check again.
64 $storage->create(['id' => $this->randomMachineName()])->save();
65 $this->assertTrue($storage->hasData());