function SqlContentEntityStorageTest::testCreate
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCreate()
- 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCreate()
- 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCreate()
@covers ::create
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ Sql/ SqlContentEntityStorageTest.php, line 1067
Class
- SqlContentEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\SqlCode
public function testCreate() : void {
$language_manager = $this->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$language = new Language([
'id' => 'en',
]);
$language_manager->expects($this->any())
->method('getCurrentLanguage')
->willReturn($language);
$entity = $this->getMockBuilder(ContentEntityBaseMockableClass::class)
->disableOriginalConstructor()
->onlyMethods([
'id',
])
->getMock();
$this->entityType
->expects($this->atLeastOnce())
->method('id')
->willReturn($this->entityTypeId);
$this->entityType
->expects($this->atLeastOnce())
->method('getClass')
->willReturn(get_class($entity));
$this->entityType
->expects($this->atLeastOnce())
->method('getKeys')
->willReturn([
'id' => 'id',
]);
// ContentEntityStorageBase iterates over the entity which calls this method
// internally in ContentEntityBase::getProperties().
$this->entityFieldManager
->getFieldDefinitions(Argument::type('string'), Argument::type('string'))
->willReturn([])
->shouldBeCalledOnce();
$this->entityType
->expects($this->atLeastOnce())
->method('isRevisionable')
->willReturn(FALSE);
$this->entityTypeManager
->getDefinition($this->entityType
->id())
->willReturn($this->entityType)
->shouldBeCalled();
$this->setUpEntityStorage();
$entity = $this->entityStorage
->create();
$entity->expects($this->atLeastOnce())
->method('id')
->willReturn('foo');
$this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity);
$this->assertSame('foo', $entity->id());
$this->assertTrue($entity->isNew());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.