diff --git a/core/modules/config/src/Tests/ConfigSingleImportExportTest.php b/core/modules/config/src/Tests/ConfigSingleImportExportTest.php index 088129a..2d26a66 100644 --- a/core/modules/config/src/Tests/ConfigSingleImportExportTest.php +++ b/core/modules/config/src/Tests/ConfigSingleImportExportTest.php @@ -8,6 +8,8 @@ namespace Drupal\config\Tests; use Drupal\Component\Serialization\Yaml; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; /** @@ -215,4 +217,61 @@ public function testExport() { $this->assertFieldByXPath('//textarea[@name="export"]', $data, 'The fallback date format config entity export code is displayed.'); } + /** + * Tests single export exports configuration entities in an importable format. + * + * @see \Drupal\Core\Config\Entity\ConfigEntityStorageInterface::mapToStorageRecord() + * @see \Drupal\Core\Config\Entity\ConfigEntityStorageInterface::createFromStorageRecord() + */ + public function testConfigEntityWithStorageRecordMapping() { + \Drupal::service('module_installer')->install(['node', 'options']); + + // Create a field which when cast to an array would have dots in the keys. + $content_type = $this->createContentType(['type' => 'test_type']); + $field_storage = FieldStorageConfig::create(array( + 'field_name' => 'test_options_field', + 'entity_type' => 'node', + 'type' => 'list_float', + // Prevent field storage being deleted when field is deleted. + 'persist_with_no_fields' => TRUE, + )); + $field_storage + ->setSetting('allowed_values', ['0' => 'Zero', '0.5' => 'Point five']) + ->save(); + $field = FieldConfig::create([ + 'field_name' => 'test_options_field', + 'entity_type' => 'node', + 'bundle' => $content_type->id(), + ]); + $field->save(); + + // Export the field and the field storage. + $this->drupalLogin($this->drupalCreateUser(['import configuration', 'export configuration'])); + $this->drupalGet('admin/config/development/configuration/single/export/field_storage_config/node.test_options_field'); + $exported_field_storage = (string) $this->cssSelect('textarea#edit-export')[0]; + $this->drupalGet('admin/config/development/configuration/single/export/field_config/node.test_type.test_options_field'); + $exported_field = (string) $this->cssSelect('textarea#edit-export')[0]; + + $field->delete(); + $field_storage->delete(); + + // Import the field storage and the field. + $edit = [ + 'config_type' => 'field_storage_config', + 'import' => $exported_field_storage, + ]; + $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); + $this->drupalPostForm(NULL, [], t('Confirm')); + $this->assertRaw(t('The configuration was imported successfully.')); + $edit = [ + 'config_type' => 'field_config', + 'import' => $exported_field, + ]; + $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); + $this->drupalPostForm(NULL, [], t('Confirm')); + $this->assertRaw(t('The configuration was imported successfully.')); + $this->assertNotNull(FieldConfig::loadByName('node', 'test_type', 'test_options_field'), 'The field has been recreated by single config import.'); + $this->assertNotNull(FieldStorageConfig::loadByName('node', 'test_options_field'), 'The field storage has been recreated by single config import.'); + } + }