ConfigEntityStorageTest.php in Drupal 9
File
core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Config;
use Drupal\Core\Config\ConfigDuplicateUUIDException;
use Drupal\KernelTests\KernelTestBase;
class ConfigEntityStorageTest extends KernelTestBase {
protected static $modules = [
'config_test',
];
public function testUUIDConflict() {
$entity_type = 'config_test';
$id = 'test_1';
$storage = $this->container
->get('entity_type.manager')
->getStorage($entity_type);
$storage
->create([
'id' => $id,
])
->save();
$entity = $storage
->load($id);
$original_properties = $entity
->toArray();
$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) {
}
$entity = $storage
->loadUnchanged($entity
->id());
$this
->assertSame($original_properties, $entity
->toArray());
}
public function testHasData() {
$storage = \Drupal::entityTypeManager()
->getStorage('config_test');
$this
->assertFalse($storage
->hasData());
$storage
->create([
'id' => $this
->randomMachineName(),
])
->save();
$this
->assertTrue($storage
->hasData());
}
}