Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStorageTest::testUUIDConflict()
  2. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStorageTest::testUUIDConflict()

Tests creating configuration entities with changed UUIDs.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php, line 25

Class

ConfigEntityStorageTest
Tests configuration entity storage.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testUUIDConflict() {
  $entity_type = 'config_test';
  $id = 'test_1';

  // Load the original configuration entity.
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($entity_type);
  $storage
    ->create([
    'id' => $id,
  ])
    ->save();
  $entity = $storage
    ->load($id);
  $original_properties = $entity
    ->toArray();

  // Override with a new UUID and try to save.
  $new_uuid = $this->container
    ->get('uuid')
    ->generate();
  $entity
    ->set('uuid', $new_uuid);
  try {
    $entity
      ->save();
    $this
      ->fail('Exception thrown when attempting to save a configuration entity with a UUID that does not match the existing UUID.');
  } catch (ConfigDuplicateUUIDException $e) {

    // Expected exception; just continue testing.
  }

  // Ensure that the config entity was not corrupted.
  $entity = $storage
    ->loadUnchanged($entity
    ->id());
  $this
    ->assertSame($original_properties, $entity
    ->toArray());
}