View source
<?php
namespace Drupal\system\Tests\Entity;
use Drupal\contact\Entity\ContactForm;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\StorageComparer;
use Drupal\simpletest\KernelTestBase;
class ContentEntityNullStorageTest extends KernelTestBase {
public static $modules = array(
'system',
'contact',
'user',
);
public function testEntityQuery() {
$this
->assertIdentical(0, \Drupal::entityQuery('contact_message')
->count()
->execute(), 'Counting a null storage returns 0.');
$this
->assertIdentical([], \Drupal::entityQuery('contact_message')
->execute(), 'Querying a null storage returns an empty array.');
$this
->assertIdentical([], \Drupal::entityQuery('contact_message')
->condition('contact_form', 'test')
->execute(), 'Querying a null storage returns an empty array and conditions are ignored.');
$this
->assertIdentical([], \Drupal::entityQueryAggregate('contact_message')
->aggregate('name', 'AVG')
->execute(), 'Aggregate querying a null storage returns an empty array');
}
public function testDeleteThroughImport() {
$contact_form = ContactForm::create([
'id' => 'test',
]);
$contact_form
->save();
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
$storage_comparer = new StorageComparer($this->container
->get('config.storage.sync'), $this->container
->get('config.storage'), $this->container
->get('config.manager'));
$config_importer = new ConfigImporter($storage_comparer
->createChangelist(), $this->container
->get('event_dispatcher'), $this->container
->get('config.manager'), $this->container
->get('lock'), $this->container
->get('config.typed'), $this->container
->get('module_handler'), $this->container
->get('module_installer'), $this->container
->get('theme_handler'), $this->container
->get('string_translation'));
$sync = $this->container
->get('config.storage.sync');
$sync
->delete($contact_form
->getConfigDependencyName());
$config_importer
->reset()
->import();
$this
->assertNull(ContactForm::load($contact_form
->id()), 'The contact form has been deleted.');
}
}