6da9bb3baad0fe7d1c9134b1acc19c7fd2d2c800
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Entity / ContentEntityNullStorageTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Entity;
4
5 use Drupal\contact\Entity\ContactForm;
6 use Drupal\Core\Config\ConfigImporter;
7 use Drupal\Core\Config\StorageComparer;
8 use Drupal\KernelTests\KernelTestBase;
9
10 /**
11  * Tests ContentEntityNullStorage entity query support.
12  *
13  * @see \Drupal\Core\Entity\ContentEntityNullStorage
14  * @see \Drupal\Core\Entity\Query\Null\Query
15  *
16  * @group Entity
17  */
18 class ContentEntityNullStorageTest extends KernelTestBase {
19
20   /**
21    * Modules to enable.
22    *
23    * @var array
24    */
25   public static $modules = ['system', 'contact', 'user'];
26
27   /**
28    * Tests using entity query with ContentEntityNullStorage.
29    *
30    * @see \Drupal\Core\Entity\Query\Null\Query
31    */
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');
37
38   }
39
40   /**
41    * Tests deleting a contact form entity via a configuration import.
42    *
43    * @see \Drupal\Core\Entity\Event\BundleConfigImportValidate
44    */
45   public function testDeleteThroughImport() {
46     $contact_form = ContactForm::create(['id' => 'test']);
47     $contact_form->save();
48
49     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
50
51     // Set up the ConfigImporter object for testing.
52     $storage_comparer = new StorageComparer(
53       $this->container->get('config.storage.sync'),
54       $this->container->get('config.storage'),
55       $this->container->get('config.manager')
56     );
57     $config_importer = new ConfigImporter(
58       $storage_comparer->createChangelist(),
59       $this->container->get('event_dispatcher'),
60       $this->container->get('config.manager'),
61       $this->container->get('lock'),
62       $this->container->get('config.typed'),
63       $this->container->get('module_handler'),
64       $this->container->get('module_installer'),
65       $this->container->get('theme_handler'),
66       $this->container->get('string_translation')
67     );
68
69     // Delete the contact message in sync.
70     $sync = $this->container->get('config.storage.sync');
71     $sync->delete($contact_form->getConfigDependencyName());
72
73     // Import.
74     $config_importer->reset()->import();
75     $this->assertNull(ContactForm::load($contact_form->id()), 'The contact form has been deleted.');
76   }
77
78 }