Upgraded drupal core with security updates
[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->installEntitySchema('entity_test_mul');
37     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
38
39     // Set up the ConfigImporter object for testing.
40     $storage_comparer = new StorageComparer(
41       $this->container->get('config.storage.sync'),
42       $this->container->get('config.storage'),
43       $this->container->get('config.manager')
44     );
45     $this->configImporter = new ConfigImporter(
46       $storage_comparer->createChangelist(),
47       $this->container->get('event_dispatcher'),
48       $this->container->get('config.manager'),
49       $this->container->get('lock'),
50       $this->container->get('config.typed'),
51       $this->container->get('module_handler'),
52       $this->container->get('module_installer'),
53       $this->container->get('theme_handler'),
54       $this->container->get('string_translation')
55     );
56   }
57
58   /**
59    * Tests config import updates.
60    */
61   public function testConfigImportUpdates() {
62     $entity_type_id = 'entity_test_mul';
63     $config_id = $entity_type_id . '.' . $entity_type_id;
64     $config_name = 'language.content_settings.' . $config_id;
65     $storage = $this->container->get('config.storage');
66     $sync = $this->container->get('config.storage.sync');
67
68     // Verify the configuration to create does not exist yet.
69     $this->assertIdentical($storage->exists($config_name), FALSE, $config_name . ' not found.');
70
71     // Create new config entity.
72     $data = [
73       'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
74       'langcode' => 'en',
75       'status' => TRUE,
76       'dependencies' => [
77         'module' => ['content_translation']
78       ],
79       'id' => $config_id,
80       'target_entity_type_id' => 'entity_test_mul',
81       'target_bundle' => 'entity_test_mul',
82       'default_langcode' => 'site_default',
83       'language_alterable' => FALSE,
84       'third_party_settings' => [
85         'content_translation' => ['enabled' => TRUE],
86       ],
87     ];
88     $sync->write($config_name, $data);
89     $this->assertIdentical($sync->exists($config_name), TRUE, $config_name . ' found.');
90
91     // Import.
92     $this->configImporter->reset()->import();
93
94     // Verify the values appeared.
95     $config = $this->config($config_name);
96     $this->assertIdentical($config->get('id'), $config_id);
97
98     // Verify that updates were performed.
99     $entity_type = $this->container->get('entity.manager')->getDefinition($entity_type_id);
100     $table = $entity_type->getDataTable();
101     $db_schema = $this->container->get('database')->schema();
102     $result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
103     $this->assertTrue($result, 'Content translation updates were successfully performed during config import.');
104   }
105
106 }