Issue #3020964 by alexpott: Empty collection config CRUD operations are inconsistent across the backend

8.7.x
Nathaniel Catchpole 2018-12-18 17:04:01 +00:00
parent 29d53e518c
commit 991fd05d95
2 changed files with 24 additions and 22 deletions

View File

@ -169,10 +169,6 @@ class FileStorage implements StorageInterface {
*/
public function delete($name) {
if (!$this->exists($name)) {
$dir = $this->getCollectionDirectory();
if (!file_exists($dir)) {
throw new StorageException($dir . '/ not found.');
}
return FALSE;
}
$this->fileCache->delete($this->getFilePath($name));
@ -185,7 +181,7 @@ class FileStorage implements StorageInterface {
public function rename($name, $new_name) {
$status = @rename($this->getFilePath($name), $this->getFilePath($new_name));
if ($status === FALSE) {
throw new StorageException('Failed to rename configuration file from: ' . $this->getFilePath($name) . ' to: ' . $this->getFilePath($new_name));
return FALSE;
}
$this->fileCache->delete($this->getFilePath($name));
$this->fileCache->delete($this->getFilePath($new_name));
@ -242,8 +238,8 @@ class FileStorage implements StorageInterface {
* {@inheritdoc}
*/
public function deleteAll($prefix = '') {
$success = TRUE;
$files = $this->listAll($prefix);
$success = !empty($files);
foreach ($files as $name) {
if (!$this->delete($name) && $success) {
$success = FALSE;

View File

@ -95,28 +95,22 @@ abstract class ConfigStorageTestBase extends KernelTestBase {
$this->storage->write($name, $data);
}
// Test that deleting a prefix that returns no configuration returns FALSE
// because nothing is deleted.
$this->assertFalse($this->storage->deleteAll('some_thing_that_cannot_exist'));
$result = $this->storage->deleteAll('config_test.');
$names = $this->storage->listAll('config_test.');
$this->assertIdentical($result, TRUE);
$this->assertIdentical($names, []);
// Test renaming an object that does not exist throws an exception.
try {
$this->storage->rename('config_test.storage_does_not_exist', 'config_test.storage_does_not_exist_rename');
}
catch (\Exception $e) {
$class = get_class($e);
$this->pass($class . ' thrown upon renaming a nonexistent storage bin.');
}
// Test renaming an object that does not exist returns FALSE.
$this->assertFalse($this->storage->rename('config_test.storage_does_not_exist', 'config_test.storage_does_not_exist_rename'));
// Test renaming to an object that already exists throws an exception.
try {
$this->storage->rename('system.cron', 'system.performance');
}
catch (\Exception $e) {
$class = get_class($e);
$this->pass($class . ' thrown upon renaming a nonexistent storage bin.');
}
// Test renaming to an object that already returns FALSE.
$data = ['foo' => 'bar'];
$this->assertTrue($this->storage->write($name, $data));
$this->assertFalse($this->storage->rename('config_test.storage_does_not_exist', $name));
}
/**
@ -200,6 +194,10 @@ abstract class ConfigStorageTestBase extends KernelTestBase {
$new_storage = $this->storage->createCollection('collection.sub.new');
$this->assertFalse($new_storage->exists($name));
$this->assertEqual([], $new_storage->listAll());
$this->assertFalse($new_storage->delete($name));
$this->assertFalse($new_storage->deleteAll('config_test.'));
$this->assertFalse($new_storage->deleteAll());
$this->assertFalse($new_storage->rename($name, 'config_test.another_name'));
$new_storage->write($name, $data);
$this->assertIdentical($result, TRUE);
$this->assertSame($data, $new_storage->read($name));
@ -252,6 +250,14 @@ abstract class ConfigStorageTestBase extends KernelTestBase {
$parent_storage->deleteAll();
$this->assertSame(['collection.sub.another', 'collection.sub.new'], $this->storage->getAllCollectionNames());
// Test operations on a collection emptied through deletion.
$this->assertFalse($parent_storage->exists($name));
$this->assertEqual([], $parent_storage->listAll());
$this->assertFalse($parent_storage->delete($name));
$this->assertFalse($parent_storage->deleteAll('config_test.'));
$this->assertFalse($parent_storage->deleteAll());
$this->assertFalse($parent_storage->rename($name, 'config_test.another_name'));
// Check that the having an empty collection-less storage does not break
// anything. Before deleting check that the previous delete did not affect
// data in another collection.