Issue #2391829 by amateescu, cilefen, Berdir, yched, fago: ContentUninstallValidator relies on the not required ContentEntityStorage::hasData() method
parent
32e402231e
commit
7e427d5c5e
|
@ -316,6 +316,13 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
|
|||
return !$config->isNew();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData() {
|
||||
return (bool) $this->configFactory->listAll($this->getPrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets entities from the static cache.
|
||||
*
|
||||
|
|
|
@ -62,16 +62,6 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData() {
|
||||
return (bool) $this->getQuery()
|
||||
->accessCheck(FALSE)
|
||||
->range(0, 1)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -18,14 +18,6 @@ use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
|
|||
*/
|
||||
interface DynamicallyFieldableEntityStorageInterface extends FieldableEntityStorageInterface, FieldStorageDefinitionListenerInterface, FieldDefinitionListenerInterface {
|
||||
|
||||
/**
|
||||
* Determines if the storage contains any data.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the storage contains data, FALSE if not.
|
||||
*/
|
||||
public function hasData();
|
||||
|
||||
/**
|
||||
* Purges a batch of field data.
|
||||
*
|
||||
|
|
|
@ -505,6 +505,16 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
|
|||
return $result ? $this->loadMultiple($result) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData() {
|
||||
return (bool) $this->getQuery()
|
||||
->accessCheck(FALSE)
|
||||
->range(0, 1)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -142,6 +142,14 @@ interface EntityStorageInterface {
|
|||
*/
|
||||
public function save(EntityInterface $entity);
|
||||
|
||||
/**
|
||||
* Determines if the storage contains any data.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the storage contains data, FALSE if not.
|
||||
*/
|
||||
public function hasData();
|
||||
|
||||
/**
|
||||
* Gets an entity query instance.
|
||||
*
|
||||
|
|
|
@ -187,6 +187,13 @@ class KeyValueEntityStorage extends EntityStorageBase {
|
|||
return $this->keyValueStore->has($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData() {
|
||||
return (bool) $this->keyValueStore->getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -14,5 +14,6 @@ function keyvalue_test_entity_type_alter(array &$entity_types) {
|
|||
$entity_types['entity_test_label']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueContentEntityStorage');
|
||||
$entity_keys = $entity_types['entity_test_label']->getKeys();
|
||||
$entity_types['entity_test_label']->set('entity_keys', $entity_keys + ['uuid' => 'uuid']);
|
||||
$entity_types['entity_test_label']->set('provider', 'keyvalue_test');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,18 @@ class ConfigEntityStorageTest extends KernelTestBase {
|
|||
$this->assertIdentical($entity->toArray(), $original_properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the hasData() method for config entity storage.
|
||||
*
|
||||
* @covers \Drupal\Core\Config\Entity\ConfigEntityStorage::hasData
|
||||
*/
|
||||
public function testHasData() {
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('config_test');
|
||||
$this->assertFalse($storage->hasData());
|
||||
|
||||
// Add a test config entity and check again.
|
||||
$storage->create(['id' => $this->randomMachineName()])->save();
|
||||
$this->assertTrue($storage->hasData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,9 +31,15 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
|
|||
|
||||
/**
|
||||
* Tests CRUD operations.
|
||||
*
|
||||
* @covers \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::hasData
|
||||
*/
|
||||
public function testCRUD() {
|
||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('entity_test_label');
|
||||
$this->assertFalse($storage->hasData());
|
||||
|
||||
// Verify default properties on a newly created empty entity.
|
||||
$empty = EntityTestLabel::create();
|
||||
$this->assertIdentical($empty->id->value, NULL);
|
||||
|
@ -108,6 +114,9 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
|
|||
$this->fail('EntityMalformedException was not thrown.');
|
||||
}
|
||||
|
||||
// Verify that hasData() returns the expected result.
|
||||
$this->assertTrue($storage->hasData());
|
||||
|
||||
// Verify that the correct status is returned and properties did not change.
|
||||
$this->assertIdentical($status, SAVED_NEW);
|
||||
$this->assertIdentical($entity_test->id(), $expected['id']);
|
||||
|
@ -157,4 +166,12 @@ class KeyValueContentEntityStorageTest extends KernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uninstallation of a module that does not use the SQL entity storage.
|
||||
*/
|
||||
public function testUninstall() {
|
||||
$uninstall_validator_reasons = \Drupal::service('content_uninstall_validator')->validate('keyvalue_test');
|
||||
$this->assertEmpty($uninstall_validator_reasons);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue