001d9ba3dee81b0b9f31650f6db133e3fb4f065c
[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     $this->installConfig(['system']);
47     $contact_form = ContactForm::create(['id' => 'test']);
48     $contact_form->save();
49
50     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
51
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')
57     );
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')
68     );
69
70     // Delete the contact message in sync.
71     $sync = $this->container->get('config.storage.sync');
72     $sync->delete($contact_form->getConfigDependencyName());
73
74     // Import.
75     $config_importer->reset()->import();
76     $this->assertNull(ContactForm::load($contact_form->id()), 'The contact form has been deleted.');
77   }
78
79 }