3 namespace Drupal\Tests\content_translation\Kernel;
5 use Drupal\Core\Config\ConfigImporter;
6 use Drupal\Core\Config\StorageComparer;
7 use Drupal\KernelTests\KernelTestBase;
10 * Tests content translation updates performed during config import.
12 * @group content_translation
14 class ContentTranslationConfigImportTest extends KernelTestBase {
17 * Config Importer object used for testing.
19 * @var \Drupal\Core\Config\ConfigImporter
21 protected $configImporter;
28 public static $modules = ['system', 'user', 'entity_test', 'language', 'content_translation'];
33 protected function setUp() {
36 $this->installConfig(['system']);
37 $this->installEntitySchema('entity_test_mul');
38 $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
40 // Set up the ConfigImporter object for testing.
41 $storage_comparer = new StorageComparer(
42 $this->container->get('config.storage.sync'),
43 $this->container->get('config.storage'),
44 $this->container->get('config.manager')
46 $this->configImporter = new ConfigImporter(
47 $storage_comparer->createChangelist(),
48 $this->container->get('event_dispatcher'),
49 $this->container->get('config.manager'),
50 $this->container->get('lock'),
51 $this->container->get('config.typed'),
52 $this->container->get('module_handler'),
53 $this->container->get('module_installer'),
54 $this->container->get('theme_handler'),
55 $this->container->get('string_translation')
60 * Tests config import updates.
62 public function testConfigImportUpdates() {
63 $entity_type_id = 'entity_test_mul';
64 $config_id = $entity_type_id . '.' . $entity_type_id;
65 $config_name = 'language.content_settings.' . $config_id;
66 $storage = $this->container->get('config.storage');
67 $sync = $this->container->get('config.storage.sync');
69 // Verify the configuration to create does not exist yet.
70 $this->assertIdentical($storage->exists($config_name), FALSE, $config_name . ' not found.');
72 // Create new config entity.
74 'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
78 'module' => ['content_translation'],
81 'target_entity_type_id' => 'entity_test_mul',
82 'target_bundle' => 'entity_test_mul',
83 'default_langcode' => 'site_default',
84 'language_alterable' => FALSE,
85 'third_party_settings' => [
86 'content_translation' => ['enabled' => TRUE],
89 $sync->write($config_name, $data);
90 $this->assertIdentical($sync->exists($config_name), TRUE, $config_name . ' found.');
93 $this->configImporter->reset()->import();
95 // Verify the values appeared.
96 $config = $this->config($config_name);
97 $this->assertIdentical($config->get('id'), $config_id);
99 // Verify that updates were performed.
100 $entity_type = $this->container->get('entity.manager')->getDefinition($entity_type_id);
101 $table = $entity_type->getDataTable();
102 $db_schema = $this->container->get('database')->schema();
103 $result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
104 $this->assertTrue($result, 'Content translation updates were successfully performed during config import.');