public function KeyValueEntityStorageTest::testSaveConfigEntity in Drupal 8
@covers ::save @covers ::doSave
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ KeyValueStore/ KeyValueEntityStorageTest.php, line 339
Class
- KeyValueEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\KeyValueStoreCode
public function testSaveConfigEntity() {
$this
->setUpKeyValueEntityStorage();
$entity = $this
->getMockEntity('Drupal\\Core\\Config\\Entity\\ConfigEntityBase', [
[
'id' => 'foo',
],
], [
'toArray',
'preSave',
]);
$entity
->enforceIsNew();
// When creating a new entity, the ID is tracked as the original ID.
$this
->assertSame('foo', $entity
->getOriginalId());
$expected = [
'id' => 'foo',
];
$entity
->expects($this
->atLeastOnce())
->method('toArray')
->will($this
->returnValue($expected));
$this->keyValueStore
->expects($this
->exactly(2))
->method('has')
->with('foo')
->will($this
->returnValue(FALSE));
$this->keyValueStore
->expects($this
->once())
->method('set')
->with('foo', $expected);
$this->keyValueStore
->expects($this
->never())
->method('delete');
$return = $this->entityStorage
->save($entity);
$this
->assertSame(SAVED_NEW, $return);
return $entity;
}