function KeyValueEntityStorageTest::testSaveContentEntity

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveContentEntity()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveContentEntity()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveContentEntity()

@covers ::save @covers ::doSave

File

core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php, line 400

Class

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

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

public function testSaveContentEntity() : void {
    $this->entityType
        ->expects($this->any())
        ->method('getKeys')
        ->willReturn([
        'id' => 'id',
    ]);
    $this->setUpKeyValueEntityStorage();
    $expected = [
        'id' => 'foo',
    ];
    $this->keyValueStore
        ->expects($this->exactly(2))
        ->method('has')
        ->with('foo')
        ->willReturn(FALSE);
    $this->keyValueStore
        ->expects($this->once())
        ->method('set')
        ->with('foo', $expected);
    $this->keyValueStore
        ->expects($this->never())
        ->method('delete');
    $entity = $this->getMockEntity('Drupal\\Core\\Entity\\ContentEntityBase', [], [
        'toArray',
        'id',
    ]);
    $entity->expects($this->atLeastOnce())
        ->method('id')
        ->willReturn('foo');
    $entity->expects($this->once())
        ->method('toArray')
        ->willReturn($expected);
    $this->entityStorage
        ->save($entity);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.