diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 6415285..3a65176 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -45,6 +45,16 @@ public static function createInstance(ContainerInterface $container, EntityTypeI /** * {@inheritdoc} */ + public function hasData() { + return (bool) $this->getQuery() + ->accessCheck(FALSE) + ->range(0, 1) + ->execute(); + } + + /** + * {@inheritdoc} + */ protected function doCreate(array $values) { // We have to determine the bundle first. $bundle = FALSE; diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index e1d403f..b8db248 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -1765,17 +1765,6 @@ public function countFieldData($storage_definition, $as_bool = FALSE) { } /** - * {@inheritdoc} - */ - public function hasData() { - return (bool) $this->database->select($this->getBaseTable(), 'base') - ->fields('base') - ->range(0, 1) - ->execute() - ->fetchField(); - } - - /** * Returns whether the passed field has been already deleted. * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 39302df..3af7076 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -1184,48 +1184,33 @@ public function testLoadMultiplePersistentCacheMiss() { * @covers ::hasData */ public function testHasData() { - $select_fetch_field = $this->getMockBuilder('\Drupal\Core\Database\StatementInterface') - ->disableOriginalConstructor() - ->getMock(); - - $select_fetch_field->expects($this->once()) - ->method('fetchField') - ->will($this->returnValue(TRUE)); - - $select_execute = $this->getMockBuilder('\Drupal\Core\Database\Query\Select') - ->disableOriginalConstructor() - ->getMock(); - - $select_execute->expects($this->once()) - ->method('execute') - ->will($this->returnValue($select_fetch_field)); - - $select_range_query = $this->getMockBuilder('\Drupal\Core\Database\Query\Select') - ->disableOriginalConstructor() - ->getMock(); - - $select_range_query->expects($this->once()) + $query = $this->getMock('Drupal\Core\Entity\Query\QueryInterface'); + $query->expects(($this->once())) + ->method('accessCheck') + ->with(FALSE) + ->willReturn($query); + $query->expects(($this->once())) ->method('range') - ->will($this->returnValue($select_execute)); + ->with(0, 1) + ->willReturn($query); + $query->expects(($this->once())) + ->method('execute') + ->willReturn(array(5)); - $database_select = $this->getMockBuilder('\Drupal\Core\Database\Query\Select') + $factory = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory') ->disableOriginalConstructor() ->getMock(); + $factory->expects($this->once()) + ->method('get') + ->with('entity_test', 'AND') + ->willReturn($query); - $database_select->expects($this->once()) - ->method('fields') - ->will($this->returnValue($select_range_query)); + $this->container->set('entity.query', $factory); $database = $this->getMockBuilder('Drupal\Core\Database\Connection') ->disableOriginalConstructor() ->getMock(); - $database->expects($this->once()) - ->method('select') - ->will($this->returnValue($database_select)); - - $this->container->set('database', $database); - $this->entityManager->expects($this->any()) ->method('getDefinition') ->will($this->returnValue($this->entityType));