You are here

public function SqlContentEntityStorageTest::testHasData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 1198
Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest.

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testHasData() {
  $query = $this
    ->getMock('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(array(
    5,
  ));
  $factory = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $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->entityManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->will($this
    ->returnValue($this->entityType));
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getFieldStorageDefinitions')
    ->will($this
    ->returnValue($this->fieldDefinitions));
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getBaseFieldDefinitions')
    ->will($this
    ->returnValue($this->fieldDefinitions));
  $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager);
  $result = $this->entityStorage
    ->hasData();
  $this
    ->assertTrue($result, 'hasData returned TRUE');
}