d4d6afff9537688b7a9b565b55948468ee481929
[yaffs-website] / web / core / modules / options / tests / src / Functional / OptionsFloatFieldImportTest.php
1 <?php
2
3 namespace Drupal\Tests\options\Functional;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\Tests\field\Functional\FieldTestBase;
8
9 /**
10  * Tests option fields can be updated and created through config synchronization.
11  *
12  * @group options
13  */
14 class OptionsFloatFieldImportTest extends FieldTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['node', 'options', 'field_ui', 'config', 'options_config_install_test'];
22
23   protected function setUp() {
24     parent::setUp();
25
26     // Create test user.
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);
29   }
30
31   /**
32    * Tests that importing list_float fields works.
33    */
34   public function testImport() {
35     $field_name = 'field_options_float';
36     $type = 'options_install_test';
37
38     // Test the results on installing options_config_install_test. All the
39     // necessary configuration for this test is created by installing that
40     // module.
41     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
42     $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);
43
44     $admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage';
45
46     // Export active config to sync.
47     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
48
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']);
54
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']);
61
62     // Delete field to test creation. This tests
63     // \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate().
64     FieldConfig::loadByName('node', $type, $field_name)->delete();
65
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']);
70   }
71
72 }