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

https://gitlab.com/reasonat/test8 · PHP · 106 lines · 64 code · 15 blank · 27 comment · 1 complexity · b728c5cf45688bcfe39fe7542ed25784 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. public static $modules = array('system', 'user', 'entity_test', 'language', 'content_translation');
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function setUp() {
  28. parent::setUp();
  29. $this->installEntitySchema('entity_test_mul');
  30. $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
  31. // Set up the ConfigImporter object for testing.
  32. $storage_comparer = new StorageComparer(
  33. $this->container->get('config.storage.sync'),
  34. $this->container->get('config.storage'),
  35. $this->container->get('config.manager')
  36. );
  37. $this->configImporter = new ConfigImporter(
  38. $storage_comparer->createChangelist(),
  39. $this->container->get('event_dispatcher'),
  40. $this->container->get('config.manager'),
  41. $this->container->get('lock'),
  42. $this->container->get('config.typed'),
  43. $this->container->get('module_handler'),
  44. $this->container->get('module_installer'),
  45. $this->container->get('theme_handler'),
  46. $this->container->get('string_translation')
  47. );
  48. }
  49. /**
  50. * Tests config import updates.
  51. */
  52. function testConfigImportUpdates() {
  53. $entity_type_id = 'entity_test_mul';
  54. $config_id = $entity_type_id . '.' . $entity_type_id;
  55. $config_name = 'language.content_settings.' . $config_id;
  56. $storage = $this->container->get('config.storage');
  57. $sync = $this->container->get('config.storage.sync');
  58. // Verify the configuration to create does not exist yet.
  59. $this->assertIdentical($storage->exists($config_name), FALSE, $config_name . ' not found.');
  60. // Create new config entity.
  61. $data = array(
  62. 'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
  63. 'langcode' => 'en',
  64. 'status' => TRUE,
  65. 'dependencies' => array(
  66. 'module' => array('content_translation')
  67. ),
  68. 'id' => $config_id,
  69. 'target_entity_type_id' => 'entity_test_mul',
  70. 'target_bundle' => 'entity_test_mul',
  71. 'default_langcode' => 'site_default',
  72. 'language_alterable' => FALSE,
  73. 'third_party_settings' => array(
  74. 'content_translation' => array('enabled' => TRUE),
  75. ),
  76. );
  77. $sync->write($config_name, $data);
  78. $this->assertIdentical($sync->exists($config_name), TRUE, $config_name . ' found.');
  79. // Import.
  80. $this->configImporter->reset()->import();
  81. // Verify the values appeared.
  82. $config = $this->config($config_name);
  83. $this->assertIdentical($config->get('id'), $config_id);
  84. // Verify that updates were performed.
  85. $entity_type = $this->container->get('entity.manager')->getDefinition($entity_type_id);
  86. $table = $entity_type->getDataTable();
  87. $db_schema = $this->container->get('database')->schema();
  88. $result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
  89. $this->assertTrue($result, 'Content translation updates were successfully performed during config import.');
  90. }
  91. }