'label' => 'Test type',
'source' => 'test',
]);
/** @var \Drupal\field\Entity\FieldConfig $field */
$field =
$type->
getSource()->
createSourceField($type);
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage =
$field->
getFieldStorageDefinition();
// Test field storage.
$this->
assertTrue($field_storage->
isNew(), 'Field storage is saved automatically.'
);
$this->
assertFalse($field_storage->
isLocked(), 'Field storage is not locked.'
);
$this->
assertSame('string',
$field_storage->
getType(), 'Field is not of correct type.'
);
$this->
assertSame('field_media_test_1',
$field_storage->
getName(), 'Incorrect field name is used.'
);
$this->
assertSame('media',
$field_storage->
getTargetEntityTypeId(), 'Field is not targeting media entities.'
);
// Test field.
$this->
assertTrue($field->
isNew(), 'Field is saved automatically.'
);
$this->
assertSame('field_media_test_1',
$field->
getName(), 'Incorrect field name is used.'
);
$this->
assertSame('string',
$field->
getType(), 'Field is of incorrect type.'
);
$this->
assertTrue($field->
isRequired(), 'Field is not required.'
);
$this->
assertEquals('Test source',
$field->
label(), 'Incorrect label is used.'
);
$this->
assertSame('test_type',
$field->
getTargetBundle(), 'Field is not targeting correct bundle.'
);