function KeyValueEntityStorageTest::testSaveUpdate

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveUpdate()
  2. 10 core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveUpdate()
  3. 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 275

Class

KeyValueEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

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');
    $this->moduleHandler
        ->expects($this->exactly(4))
        ->method('invokeAll')
        ->withConsecutive([
        'test_entity_type_presave',
    ], [
        'entity_presave',
    ], [
        'test_entity_type_update',
    ], [
        'entity_update',
    ]);
    $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.