3 namespace Drupal\Tests\options\Functional;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\Tests\field\Functional\FieldTestBase;
10 * Tests option fields can be updated and created through config synchronization.
14 class OptionsFloatFieldImportTest extends FieldTestBase {
21 public static $modules = ['node', 'options', 'field_ui', 'config', 'options_config_install_test'];
23 protected function setUp() {
27 $admin_user = $this->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']);
28 $this->drupalLogin($admin_user);
32 * Tests that importing list_float fields works.
34 public function testImport() {
35 $field_name = 'field_options_float';
36 $type = 'options_install_test';
38 // Test the results on installing options_config_install_test. All the
39 // necessary configuration for this test is created by installing that
41 $field_storage = FieldStorageConfig::loadByName('node', $field_name);
42 $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);
44 $admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage';
46 // Export active config to sync.
47 $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
49 // Set the active to not use dots in the allowed values key names.
50 $edit = ['settings[allowed_values]' => "0|Zero\n1|One"];
51 $this->drupalPostForm($admin_path, $edit, t('Save field settings'));
52 $field_storage = FieldStorageConfig::loadByName('node', $field_name);
53 $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '1' => 'One']);
55 // Import configuration with dots in the allowed values key names. This
56 // tests \Drupal\Core\Config\Entity\ConfigEntityStorage::importUpdate().
57 $this->drupalGet('admin/config/development/configuration');
58 $this->drupalPostForm(NULL, [], t('Import all'));
59 $field_storage = FieldStorageConfig::loadByName('node', $field_name);
60 $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);
62 // Delete field to test creation. This tests
63 // \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate().
64 FieldConfig::loadByName('node', $type, $field_name)->delete();
66 $this->drupalGet('admin/config/development/configuration');
67 $this->drupalPostForm(NULL, [], t('Import all'));
68 $field_storage = FieldStorageConfig::loadByName('node', $field_name);
69 $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);