3 namespace Drupal\KernelTests\Core\Entity;
5 use Drupal\contact\Entity\ContactForm;
6 use Drupal\Core\Config\ConfigImporter;
7 use Drupal\Core\Config\StorageComparer;
8 use Drupal\KernelTests\KernelTestBase;
11 * Tests ContentEntityNullStorage entity query support.
13 * @see \Drupal\Core\Entity\ContentEntityNullStorage
14 * @see \Drupal\Core\Entity\Query\Null\Query
18 class ContentEntityNullStorageTest extends KernelTestBase {
25 public static $modules = ['system', 'contact', 'user'];
28 * Tests using entity query with ContentEntityNullStorage.
30 * @see \Drupal\Core\Entity\Query\Null\Query
32 public function testEntityQuery() {
33 $this->assertSame(0, \Drupal::entityQuery('contact_message')->count()->execute(), 'Counting a null storage returns 0.');
34 $this->assertSame([], \Drupal::entityQuery('contact_message')->execute(), 'Querying a null storage returns an empty array.');
35 $this->assertSame([], \Drupal::entityQuery('contact_message')->condition('contact_form', 'test')->execute(), 'Querying a null storage returns an empty array and conditions are ignored.');
36 $this->assertSame([], \Drupal::entityQueryAggregate('contact_message')->aggregate('name', 'AVG')->execute(), 'Aggregate querying a null storage returns an empty array');
41 * Tests deleting a contact form entity via a configuration import.
43 * @see \Drupal\Core\Entity\Event\BundleConfigImportValidate
45 public function testDeleteThroughImport() {
46 $this->installConfig(['system']);
47 $contact_form = ContactForm::create(['id' => 'test']);
48 $contact_form->save();
50 $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
52 // Set up the ConfigImporter object for testing.
53 $storage_comparer = new StorageComparer(
54 $this->container->get('config.storage.sync'),
55 $this->container->get('config.storage'),
56 $this->container->get('config.manager')
58 $config_importer = new ConfigImporter(
59 $storage_comparer->createChangelist(),
60 $this->container->get('event_dispatcher'),
61 $this->container->get('config.manager'),
62 $this->container->get('lock'),
63 $this->container->get('config.typed'),
64 $this->container->get('module_handler'),
65 $this->container->get('module_installer'),
66 $this->container->get('theme_handler'),
67 $this->container->get('string_translation')
70 // Delete the contact message in sync.
71 $sync = $this->container->get('config.storage.sync');
72 $sync->delete($contact_form->getConfigDependencyName());
75 $config_importer->reset()->import();
76 $this->assertNull(ContactForm::load($contact_form->id()), 'The contact form has been deleted.');