Issue #3031130 by tim.plunkett: \Drupal\Core\KeyValueStore\MemoryStorage::rename() erases data if keys match
parent
c274b2b8f3
commit
d70a475234
|
@ -71,8 +71,10 @@ class MemoryStorage extends StorageBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($key, $new_key) {
|
||||
$this->data[$new_key] = $this->data[$key];
|
||||
unset($this->data[$key]);
|
||||
if ($key !== $new_key) {
|
||||
$this->data[$new_key] = $this->data[$key];
|
||||
unset($this->data[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -189,6 +189,19 @@ abstract class StorageTestBase extends KernelTestBase {
|
|||
$this->assertNull($store->get('old'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the rename operation.
|
||||
*/
|
||||
public function testRenameNoChange() {
|
||||
$stores = $this->createStorage();
|
||||
$store = $stores[0];
|
||||
|
||||
$store->set('old', 'thing');
|
||||
$this->assertSame($store->get('old'), 'thing');
|
||||
$store->rename('old', 'old');
|
||||
$this->assertSame($store->get('old'), 'thing');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates storage objects for each collection defined for this class.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue