public function SqlContentEntityStorageTest::testCreate in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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 940 - Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest.
Class
- SqlContentEntityStorageTest
- @coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity
Namespace
Drupal\Tests\Core\Entity\SqlCode
public function testCreate() {
$language_manager = $this
->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$language = new Language(array(
'id' => 'en',
));
$language_manager
->expects($this
->any())
->method('getCurrentLanguage')
->will($this
->returnValue($language));
$this->container
->set('language_manager', $language_manager);
$this->container
->set('entity.manager', $this->entityManager);
$this->container
->set('module_handler', $this->moduleHandler);
$entity = $this
->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')
->disableOriginalConstructor()
->setMethods(array(
'id',
))
->getMockForAbstractClass();
$this->entityType
->expects($this
->atLeastOnce())
->method('id')
->will($this
->returnValue($this->entityTypeId));
$this->entityType
->expects($this
->atLeastOnce())
->method('getClass')
->will($this
->returnValue(get_class($entity)));
$this->entityType
->expects($this
->atLeastOnce())
->method('getKeys')
->will($this
->returnValue(array(
'id' => 'id',
)));
// ContentEntityStorageBase iterates over the entity which calls this method
// internally in ContentEntityBase::getProperties().
$this->entityManager
->expects($this
->once())
->method('getFieldDefinitions')
->will($this
->returnValue(array()));
$this->entityType
->expects($this
->atLeastOnce())
->method('isRevisionable')
->will($this
->returnValue(FALSE));
$this->entityManager
->expects($this
->atLeastOnce())
->method('getDefinition')
->with($this->entityType
->id())
->will($this
->returnValue($this->entityType));
$this
->setUpEntityStorage();
$entity = $this->entityStorage
->create();
$entity
->expects($this
->atLeastOnce())
->method('id')
->will($this
->returnValue('foo'));
$this
->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity);
$this
->assertSame('foo', $entity
->id());
$this
->assertTrue($entity
->isNew());
}