function KeyValueEntityStorageTest::testSaveUpdate
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveUpdate()
- 8.9.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveUpdate()
- 11.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveUpdate()
@covers ::save @covers ::doSave
@depends testSaveInsert
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
Return value
\Drupal\Core\Entity\EntityInterface
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ KeyValueStore/ KeyValueEntityStorageTest.php, line 287
Class
- KeyValueEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\KeyValueStoreCode
public function testSaveUpdate(EntityInterface $entity) {
$this->entityType
->expects($this->once())
->method('getClass')
->willReturn(get_class($entity));
$this->setUpKeyValueEntityStorage();
$expected = [
'id' => 'foo',
];
$this->keyValueStore
->expects($this->exactly(2))
->method('has')
->with('foo')
->willReturn(TRUE);
$this->keyValueStore
->expects($this->once())
->method('getMultiple')
->with([
'foo',
])
->willReturn([
[
'id' => 'foo',
],
]);
$this->keyValueStore
->expects($this->never())
->method('delete');
$hooks = [
'test_entity_type_presave',
'entity_presave',
'test_entity_type_update',
'entity_update',
];
$this->moduleHandler
->expects($this->exactly(count($hooks)))
->method('invokeAll')
->with($this->callback(function (string $hook) use (&$hooks) : bool {
return array_shift($hooks) === $hook;
}));
$this->keyValueStore
->expects($this->once())
->method('set')
->with('foo', $expected);
$return = $this->entityStorage
->save($entity);
$this->assertSame(SAVED_UPDATED, $return);
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.