diff --git a/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php b/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php new file mode 100644 index 0000000..11ce278 --- /dev/null +++ b/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php @@ -0,0 +1,89 @@ +drupalCreateUser(array('synchronize configuration', 'access content', 'administer taxonomy', 'access administration pages', 'administer site configuration', 'administer content types', 'administer nodes', 'bypass node access', 'administer node fields', 'administer node display')); + $this->drupalLogin($admin_user); + + // Create content type, with underscores. + $type_name = 'test_' . strtolower($this->randomMachineName()); + $this->type_name = $type_name; + $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name)); + $this->type = $type->type; + } + + /** + * Tests that importing list_float fields works. + */ + public function testImport() { + $this->field_name = 'field_options_float'; + + entity_create('field_storage_config', array( + 'name' => $this->field_name, + 'entity_type' => 'node', + 'type' => 'list_float', + ))->save(); + entity_create('field_instance_config', array( + 'field_name' => $this->field_name, + 'entity_type' => 'node', + 'bundle' => $this->type, + ))->save(); + + $admin_path = 'admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $this->field_name . '/storage'; + + $edit = array('field[settings][allowed_values]' => "0|Zero\n.5|Point five"); + $this->drupalPostForm($admin_path, $edit, t('Save field settings')); + + // Export active config to staging + $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.staging')); + + $edit = array('field[settings][allowed_values]' => "0|Zero\n1|One"); + $this->drupalPostForm($admin_path, $edit, t('Save field settings')); + + $field_storage = FieldStorageConfig::loadByName('node', $this->field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '1' => 'One')); + + $this->drupalGet('admin/config/development/configuration'); + $this->drupalPostForm(NULL, array(), t('Import all')); + + $field_storage = FieldStorageConfig::loadByName('node', $this->field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five')); + + // Delete field to test creation. Deleting the instance will also delete + // the storage. + FieldInstanceConfig::loadByName('node', $this->type, $this->field_name)->delete(); + + $this->drupalGet('admin/config/development/configuration'); + $this->drupalPostForm(NULL, array(), t('Import all')); + + $field_storage = FieldStorageConfig::loadByName('node', $this->field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five')); + } +} \ No newline at end of file