View source
<?php
namespace Drupal\config\Tests;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\StorageComparer;
use Drupal\simpletest\KernelTestBase;
class ConfigImporterMissingContentTest extends KernelTestBase {
protected $configImporter;
public static $modules = array(
'system',
'user',
'entity_test',
'config_test',
'config_import_test',
);
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'sequences');
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
$this
->installConfig(array(
'config_test',
));
unset($GLOBALS['hook_config_test']);
$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'));
$this->configImporter = 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'));
}
function testMissingContent() {
\Drupal::state()
->set('config_import_test.config_import_missing_content', TRUE);
$storage = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$entity_one = entity_create('entity_test', array(
'name' => 'one',
));
$entity_two = entity_create('entity_test', array(
'name' => 'two',
));
$entity_three = entity_create('entity_test', array(
'name' => 'three',
));
$dynamic_name = 'config_test.dynamic.dotted.default';
$original_dynamic_data = $storage
->read($dynamic_name);
$original_dynamic_data['dependencies']['content'][] = $entity_one
->getConfigDependencyName();
$original_dynamic_data['dependencies']['content'][] = $entity_two
->getConfigDependencyName();
$original_dynamic_data['dependencies']['content'][] = $entity_three
->getConfigDependencyName();
$sync
->write($dynamic_name, $original_dynamic_data);
$this->configImporter
->reset()
->import();
$this
->assertEqual([], $this->configImporter
->getErrors(), 'There were no errors during the import.');
$this
->assertEqual($entity_one
->uuid(), \Drupal::state()
->get('config_import_test.config_import_missing_content_one'), 'The missing content event is fired during configuration import.');
$this
->assertEqual($entity_two
->uuid(), \Drupal::state()
->get('config_import_test.config_import_missing_content_two'), 'The missing content event is fired during configuration import.');
$original_dynamic_data = $storage
->read($dynamic_name);
$this
->assertEqual([
$entity_one
->getConfigDependencyName(),
$entity_two
->getConfigDependencyName(),
$entity_three
->getConfigDependencyName(),
], $original_dynamic_data['dependencies']['content'], 'The imported configuration entity has the missing content entity dependency.');
}
}