function SqlContentEntityStorageTest::testHasData

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testHasData()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testHasData()
  3. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testHasData()

@covers ::hasData

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 1333

Class

SqlContentEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testHasData() : void {
    $query = $this->createMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
    $query->expects($this->once())
        ->method('accessCheck')
        ->with(FALSE)
        ->willReturn($query);
    $query->expects($this->once())
        ->method('range')
        ->with(0, 1)
        ->willReturn($query);
    $query->expects($this->once())
        ->method('execute')
        ->willReturn([
        5,
    ]);
    $factory = $this->createMock(QueryFactoryInterface::class);
    $factory->expects($this->once())
        ->method('get')
        ->with($this->entityType, 'AND')
        ->willReturn($query);
    $this->container
        ->set('entity.query.sql', $factory);
    $database = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
        ->disableOriginalConstructor()
        ->getMock();
    $this->entityTypeManager
        ->getDefinition($this->entityType
        ->id())
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->getActiveDefinition($this->entityType
        ->id())
        ->willReturn($this->entityType);
    $this->entityFieldManager
        ->getFieldStorageDefinitions($this->entityType
        ->id())
        ->willReturn($this->fieldDefinitions);
    $this->entityFieldManager
        ->getActiveFieldStorageDefinitions($this->entityType
        ->id())
        ->willReturn($this->fieldDefinitions);
    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityFieldManager
        ->reveal(), $this->cache, $this->languageManager, new MemoryCache(new Time()), $this->entityTypeBundleInfo, $this->entityTypeManager
        ->reveal());
    $result = $this->entityStorage
        ->hasData();
    $this->assertTrue($result, 'hasData returned TRUE');
}

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