function SqlContentEntityStorageTest::testCreate

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCreate()
  2. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCreate()
  3. 11.x 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 1068

Class

SqlContentEntityStorageTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Sql%21SqlContentEntityStorage.php/class/SqlContentEntityStorage/8.9.x" title="A content entity database storage implementation." class="local">\Drupal\Core\Entity\Sql\SqlContentEntityStorage</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testCreate() {
    $language_manager = $this->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');
    $language = new Language([
        'id' => 'en',
    ]);
    $language_manager->expects($this->any())
        ->method('getCurrentLanguage')
        ->will($this->returnValue($language));
    $entity = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')
        ->disableOriginalConstructor()
        ->setMethods([
        '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([
        'id' => 'id',
    ]));
    // ContentEntityStorageBase iterates over the entity which calls this method
    // internally in ContentEntityBase::getProperties().
    $this->entityFieldManager
        ->expects($this->once())
        ->method('getFieldDefinitions')
        ->will($this->returnValue([]));
    $this->entityType
        ->expects($this->atLeastOnce())
        ->method('isRevisionable')
        ->will($this->returnValue(FALSE));
    $this->entityTypeManager
        ->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());
}

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