X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Foptions%2Ftests%2Fsrc%2FFunctional%2FOptionsFloatFieldImportTest.php;fp=web%2Fcore%2Fmodules%2Foptions%2Ftests%2Fsrc%2FFunctional%2FOptionsFloatFieldImportTest.php;h=befd48e42aca9649b02197be878d1f88f3dbe059;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/options/tests/src/Functional/OptionsFloatFieldImportTest.php b/web/core/modules/options/tests/src/Functional/OptionsFloatFieldImportTest.php new file mode 100644 index 000000000..befd48e42 --- /dev/null +++ b/web/core/modules/options/tests/src/Functional/OptionsFloatFieldImportTest.php @@ -0,0 +1,72 @@ +drupalCreateUser(['synchronize configuration', 'access content', 'access administration pages', 'administer site configuration', 'administer content types', 'administer nodes', 'bypass node access', 'administer node fields', 'administer node display']); + $this->drupalLogin($admin_user); + } + + /** + * Tests that importing list_float fields works. + */ + public function testImport() { + $field_name = 'field_options_float'; + $type = 'options_install_test'; + + // Test the results on installing options_config_install_test. All the + // necessary configuration for this test is created by installing that + // module. + $field_storage = FieldStorageConfig::loadByName('node', $field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']); + + $admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage'; + + // Export active config to sync. + $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync')); + + // Set the active to not use dots in the allowed values key names. + $edit = ['settings[allowed_values]' => "0|Zero\n1|One"]; + $this->drupalPostForm($admin_path, $edit, t('Save field settings')); + $field_storage = FieldStorageConfig::loadByName('node', $field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '1' => 'One']); + + // Import configuration with dots in the allowed values key names. This + // tests \Drupal\Core\Config\Entity\ConfigEntityStorage::importUpdate(). + $this->drupalGet('admin/config/development/configuration'); + $this->drupalPostForm(NULL, [], t('Import all')); + $field_storage = FieldStorageConfig::loadByName('node', $field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']); + + // Delete field to test creation. This tests + // \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate(). + FieldConfig::loadByName('node', $type, $field_name)->delete(); + + $this->drupalGet('admin/config/development/configuration'); + $this->drupalPostForm(NULL, [], t('Import all')); + $field_storage = FieldStorageConfig::loadByName('node', $field_name); + $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']); + } + +}