function KeyValueEntityStorageTest::testSaveConfigEntity

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

@covers ::save @covers ::doSave

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

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')
        ->willReturn($expected);
    $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');
    $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.