function KeyValueEntityStorageTest::testSaveRenameConfigEntity

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

@covers ::save @covers ::doSave

@depends testSaveConfigEntity

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

public function testSaveRenameConfigEntity(ConfigEntityInterface $entity) : void {
    $this->entityType
        ->expects($this->once())
        ->method('getClass')
        ->willReturn(get_class($entity));
    $this->setUpKeyValueEntityStorage();
    $expected = [
        'id' => 'foo',
    ];
    $entity->expects($this->once())
        ->method('toArray')
        ->willReturn($expected);
    $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->once())
        ->method('delete')
        ->with('foo');
    $this->keyValueStore
        ->expects($this->once())
        ->method('set')
        ->with('bar', $expected);
    // Performing a rename does not change the original ID until saving.
    $this->assertSame('foo', $entity->getOriginalId());
    $entity->set('id', 'bar');
    $this->assertSame('foo', $entity->getOriginalId());
    $return = $this->entityStorage
        ->save($entity);
    $this->assertSame(SAVED_UPDATED, $return);
    $this->assertSame('bar', $entity->getOriginalId());
}

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