View source
<?php
namespace Drupal\system\Tests\Field;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
class FieldSettingsTest extends EntityUnitTestBase {
public static $modules = array(
'field',
'field_test',
);
public function testBaseFieldSettings() {
$base_field = BaseFieldDefinition::create('test_field');
$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',
];
$this
->assertEqual($base_field
->getSettings(), $expected_settings);
$expected_settings['test_field_setting'] = 'another test string';
$base_field
->setSettings([
'test_field_setting' => $expected_settings['test_field_setting'],
]);
$this
->assertEqual($base_field
->getSettings(), $expected_settings);
}
public function testConfigurableFieldStorageSettings() {
$field_storage = FieldStorageConfig::create([
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'type' => 'test_field',
]);
$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',
];
$this
->assertEqual($field_storage
->getSettings(), $expected_settings);
$expected_settings['test_field_storage_setting'] = 'another test string';
$field_storage
->setSettings([
'test_field_storage_setting' => $expected_settings['test_field_storage_setting'],
]);
$this
->assertEqual($field_storage
->getSettings(), $expected_settings);
}
public function testConfigurableFieldSettings() {
$field_storage = FieldStorageConfig::create([
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'type' => 'test_field',
]);
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
]);
$field
->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',
'test_field_setting' => 'dummy test string',
'translatable_field_setting' => 'a translatable field setting',
'field_setting_from_config_data' => TRUE,
];
$this
->assertEqual($field
->getSettings(), $expected_settings);
$expected_settings['test_field_setting'] = 'another test string';
$field
->setSettings([
'test_field_setting' => $expected_settings['test_field_setting'],
]);
$this
->assertEqual($field
->getSettings(), $expected_settings);
}
}