function FieldSettingsTest::testConfigurableFieldSettings

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php \Drupal\KernelTests\Core\Field\FieldSettingsTest::testConfigurableFieldSettings()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php \Drupal\KernelTests\Core\Field\FieldSettingsTest::testConfigurableFieldSettings()
  3. 10 core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php \Drupal\KernelTests\Core\Field\FieldSettingsTest::testConfigurableFieldSettings()

@covers \Drupal\field\Entity\FieldStorageConfig::getSettings @covers \Drupal\field\Entity\FieldStorageConfig::setSettings

File

core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php, line 109

Class

FieldSettingsTest
Tests field settings methods on field definition structures.

Namespace

Drupal\KernelTests\Core\Field

Code

public function testConfigurableFieldSettings() : void {
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'test_field',
        'entity_type' => 'entity_test',
        'type' => 'test_field',
    ]);
    $field_storage->save();
    $expected_settings = [
        'test_field_storage_setting' => 'dummy test string',
        'changeable' => 'a changeable field storage setting',
        'unchangeable' => 'an unchangeable field storage setting',
        'translatable_storage_setting' => 'a translatable field storage setting',
        'storage_setting_from_config_data' => 'TRUE',
    ];
    $this->assertEquals($expected_settings, $field_storage->getSettings());
    $field = FieldConfig::create([
        'field_storage' => $field_storage,
        'bundle' => 'entity_test',
    ]);
    // Check that the default settings have been populated. Note: getSettings()
    // returns both storage and field settings.
    $expected_settings = [
        'test_field_storage_setting' => 'dummy test string',
        'changeable' => 'a changeable field storage setting',
        'unchangeable' => 'an unchangeable field storage setting',
        'translatable_storage_setting' => 'a translatable field storage setting',
        'test_field_setting' => 'dummy test string',
        'translatable_field_setting' => 'a translatable field setting',
        'storage_setting_from_config_data' => 'TRUE',
    ];
    $this->assertEquals($expected_settings, $field->getSettings());
    // Change one single setting using setSettings(), and check that the other
    // expected settings are still present.
    $expected_settings['test_field_setting'] = 'another test string';
    $field->setSettings([
        'test_field_setting' => $expected_settings['test_field_setting'],
    ]);
    $this->assertEquals($expected_settings, $field->getSettings());
    // Save the field and check the expected settings.
    $field->save();
    $expected_settings['field_setting_from_config_data'] = 'TRUE';
    $this->assertEquals($expected_settings, $field->getSettings());
    $field = FieldConfig::loadByName('entity_test', 'entity_test', 'test_field');
    $this->assertEquals($expected_settings, $field->getSettings());
    $expected_settings['test_field_setting'] = 'yet another test string';
    $field->setSettings([
        'test_field_setting' => $expected_settings['test_field_setting'],
    ]);
    $this->assertEquals($expected_settings, $field->getSettings());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.