// Ensure that basic properties are preserved.
$this->
assertEquals($field_storage_definition['field_name'
],
$field_storage_config['field_name'
], 'The field name is properly saved.'
);
$this->
assertEquals($field_storage_definition['entity_type'
],
$field_storage_config['entity_type'
], 'The field entity type is properly saved.'
);
$this->
assertEquals($field_storage_definition['entity_type'
] . '.' .
$field_storage_definition['field_name'
],
$field_storage_config['id'
], 'The field id is properly saved.'
);
$this->
assertEquals($field_storage_definition['type'
],
$field_storage_config['type'
], 'The field type is properly saved.'
);
// Ensure that cardinality defaults to 1.
$this->
assertEquals(1,
$field_storage_config['cardinality'
], 'Cardinality defaults to 1.'
);
// Ensure that default settings are present.
$field_type_manager = \Drupal::
service('plugin.manager.field.field_type'
);
$this->
assertEquals($field_type_manager->
getDefaultStorageSettings($field_storage_definition['type'
]),
$field_storage_config['settings'
], 'Default storage settings have been written.'
);
// Guarantee that the name is unique.
try { FieldStorageConfig::
create($field_storage_definition)->
save();
$this->
fail('Cannot create two fields with the same name.'
);
} catch (\Exception
$e) { $this->
assertInstanceOf(EntityStorageException::
class,
$e);
} // Check that field type is required.