public function KeyValueEntityStorageTest::testSaveConfigEntity in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 329 - Contains \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest.
Class
- KeyValueEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\KeyValueStoreCode
public function testSaveConfigEntity() {
$this
->setUpKeyValueEntityStorage();
$entity = $this
->getMockEntity('Drupal\\Core\\Config\\Entity\\ConfigEntityBase', array(
array(
'id' => 'foo',
),
), array(
'toArray',
'preSave',
));
$entity
->enforceIsNew();
// When creating a new entity, the ID is tracked as the original ID.
$this
->assertSame('foo', $entity
->getOriginalId());
$expected = array(
'id' => 'foo',
);
$entity
->expects($this
->once())
->method('toArray')
->will($this
->returnValue($expected));
$this->keyValueStore
->expects($this
->exactly(2))
->method('has')
->with('foo')
->will($this
->returnValue(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;
}