function KeyValueEntityStorageTest::testSaveInsert
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveInsert()
- 10 core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveInsert()
- 11.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveInsert()
@covers ::save @covers ::doSave
@depends testCreate
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 231
Class
- KeyValueEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\KeyValueStoreCode
public function testSaveInsert(EntityInterface $entity) {
$this->setUpKeyValueEntityStorage();
$expected = [
'id' => 'foo',
];
$this->keyValueStore
->expects($this->exactly(2))
->method('has')
->with('foo')
->willReturn(FALSE);
$this->keyValueStore
->expects($this->never())
->method('getMultiple');
$this->keyValueStore
->expects($this->never())
->method('delete');
$entity->expects($this->atLeastOnce())
->method('toArray')
->willReturn($expected);
$this->moduleHandler
->expects($this->exactly(4))
->method('invokeAll')
->withConsecutive([
'test_entity_type_presave',
], [
'entity_presave',
], [
'test_entity_type_insert',
], [
'entity_insert',
]);
$this->keyValueStore
->expects($this->once())
->method('set')
->with('foo', $expected);
$return = $this->entityStorage
->save($entity);
$this->assertSame(SAVED_NEW, $return);
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.