Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / content_translation / tests / src / Kernel / ContentTranslationConfigImportTest.php
1 <?php
2
3 namespace Drupal\Tests\content_translation\Kernel;
4
5 use Drupal\Core\Config\ConfigImporter;
6 use Drupal\Core\Config\StorageComparer;
7 use Drupal\KernelTests\KernelTestBase;
8
9 /**
10  * Tests content translation updates performed during config import.
11  *
12  * @group content_translation
13  */
14 class ContentTranslationConfigImportTest extends KernelTestBase {
15
16   /**
17    * Config Importer object used for testing.
18    *
19    * @var \Drupal\Core\Config\ConfigImporter
20    */
21   protected $configImporter;
22
23   /**
24    * Modules to enable.
25    *
26    * @var array
27    */
28   public static $modules = ['system', 'user', 'entity_test', 'language', 'content_translation'];
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp() {
34     parent::setUp();
35
36     $this->installConfig(['system']);
37     $this->installEntitySchema('entity_test_mul');
38     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
39
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')
45     );
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')
56     );
57   }
58
59   /**
60    * Tests config import updates.
61    */
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');
68
69     // Verify the configuration to create does not exist yet.
70     $this->assertIdentical($storage->exists($config_name), FALSE, $config_name . ' not found.');
71
72     // Create new config entity.
73     $data = [
74       'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
75       'langcode' => 'en',
76       'status' => TRUE,
77       'dependencies' => [
78         'module' => ['content_translation'],
79       ],
80       'id' => $config_id,
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],
87       ],
88     ];
89     $sync->write($config_name, $data);
90     $this->assertIdentical($sync->exists($config_name), TRUE, $config_name . ' found.');
91
92     // Import.
93     $this->configImporter->reset()->import();
94
95     // Verify the values appeared.
96     $config = $this->config($config_name);
97     $this->assertIdentical($config->get('id'), $config_id);
98
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.');
105   }
106
107 }