/web/core/modules/content_translation/tests/src/Kernel/ContentTranslationConfigImportTest.php

https://gitlab.com/andecode/theme-spark · PHP · 113 lines · 71 code · 15 blank · 27 comment · 1 complexity · 1646c02a8e4161a64fa19c4c7384d615 MD5 · raw file

  1. <?php
  2. namespace Drupal\Tests\content_translation\Kernel;
  3. use Drupal\Core\Config\ConfigImporter;
  4. use Drupal\Core\Config\StorageComparer;
  5. use Drupal\KernelTests\KernelTestBase;
  6. /**
  7. * Tests content translation updates performed during config import.
  8. *
  9. * @group content_translation
  10. */
  11. class ContentTranslationConfigImportTest extends KernelTestBase {
  12. /**
  13. * Config Importer object used for testing.
  14. *
  15. * @var \Drupal\Core\Config\ConfigImporter
  16. */
  17. protected $configImporter;
  18. /**
  19. * Modules to enable.
  20. *
  21. * @var array
  22. */
  23. protected static $modules = [
  24. 'system',
  25. 'user',
  26. 'entity_test',
  27. 'language',
  28. 'content_translation',
  29. ];
  30. /**
  31. * {@inheritdoc}
  32. */
  33. protected function setUp(): void {
  34. parent::setUp();
  35. $this->installConfig(['system']);
  36. $this->installEntitySchema('entity_test_mul');
  37. $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
  38. // Set up the ConfigImporter object for testing.
  39. $storage_comparer = new StorageComparer(
  40. $this->container->get('config.storage.sync'),
  41. $this->container->get('config.storage')
  42. );
  43. $this->configImporter = new ConfigImporter(
  44. $storage_comparer->createChangelist(),
  45. $this->container->get('event_dispatcher'),
  46. $this->container->get('config.manager'),
  47. $this->container->get('lock'),
  48. $this->container->get('config.typed'),
  49. $this->container->get('module_handler'),
  50. $this->container->get('module_installer'),
  51. $this->container->get('theme_handler'),
  52. $this->container->get('string_translation'),
  53. $this->container->get('extension.list.module')
  54. );
  55. }
  56. /**
  57. * Tests config import updates.
  58. */
  59. public function testConfigImportUpdates() {
  60. $entity_type_id = 'entity_test_mul';
  61. $config_id = $entity_type_id . '.' . $entity_type_id;
  62. $config_name = 'language.content_settings.' . $config_id;
  63. $storage = $this->container->get('config.storage');
  64. $sync = $this->container->get('config.storage.sync');
  65. // Verify the configuration to create does not exist yet.
  66. $this->assertFalse($storage->exists($config_name), $config_name . ' not found.');
  67. // Create new config entity.
  68. $data = [
  69. 'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
  70. 'langcode' => 'en',
  71. 'status' => TRUE,
  72. 'dependencies' => [
  73. 'module' => ['content_translation'],
  74. ],
  75. 'id' => $config_id,
  76. 'target_entity_type_id' => 'entity_test_mul',
  77. 'target_bundle' => 'entity_test_mul',
  78. 'default_langcode' => 'site_default',
  79. 'language_alterable' => FALSE,
  80. 'third_party_settings' => [
  81. 'content_translation' => ['enabled' => TRUE],
  82. ],
  83. ];
  84. $sync->write($config_name, $data);
  85. $this->assertTrue($sync->exists($config_name), $config_name . ' found.');
  86. // Import.
  87. $this->configImporter->reset()->import();
  88. // Verify the values appeared.
  89. $config = $this->config($config_name);
  90. $this->assertSame($config_id, $config->get('id'));
  91. // Verify that updates were performed.
  92. $entity_type = $this->container->get('entity_type.manager')->getDefinition($entity_type_id);
  93. $table = $entity_type->getDataTable();
  94. $db_schema = $this->container->get('database')->schema();
  95. $result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
  96. $this->assertTrue($result, 'Content translation updates were successfully performed during config import.');
  97. }
  98. }