public function KeyValueEntityStorageTest::testSaveRenameConfigEntity in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveRenameConfigEntity()
@covers ::save @covers ::doSave
@depends testSaveConfigEntity
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ KeyValueStore/ KeyValueEntityStorageTest.php, line 366 - Contains \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest.
Class
- KeyValueEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\KeyValueStoreCode
public function testSaveRenameConfigEntity(ConfigEntityInterface $entity) {
$this->entityType
->expects($this
->once())
->method('getClass')
->will($this
->returnValue(get_class($entity)));
$this
->setUpKeyValueEntityStorage();
$this->moduleHandler
->expects($this
->at(0))
->method('getImplementations')
->with('entity_load')
->will($this
->returnValue(array()));
$this->moduleHandler
->expects($this
->at(1))
->method('getImplementations')
->with('test_entity_type_load')
->will($this
->returnValue(array()));
$expected = array(
'id' => 'foo',
);
$entity
->expects($this
->once())
->method('toArray')
->will($this
->returnValue($expected));
$this->keyValueStore
->expects($this
->exactly(2))
->method('has')
->with('foo')
->will($this
->returnValue(TRUE));
$this->keyValueStore
->expects($this
->once())
->method('getMultiple')
->with(array(
'foo',
))
->will($this
->returnValue(array(
array(
'id' => 'foo',
),
)));
$this->keyValueStore
->expects($this
->once())
->method('delete')
->with('foo');
$this->keyValueStore
->expects($this
->once())
->method('set')
->with('bar', $expected);
// Performing a rename does not change the original ID until saving.
$this
->assertSame('foo', $entity
->getOriginalId());
$entity
->set('id', 'bar');
$this
->assertSame('foo', $entity
->getOriginalId());
$return = $this->entityStorage
->save($entity);
$this
->assertSame(SAVED_UPDATED, $return);
$this
->assertSame('bar', $entity
->getOriginalId());
}