$this->
assertSame(SAVED_NEW,
$media_type->
save());
// The media type form creates a source field if it does not exist yet. The
// same must be done in a kernel test, since it does not use that form.
// @see \Drupal\media\MediaTypeForm::save()
$source_field->
getFieldStorageDefinition()->
save();
// The source field storage has been created, now the field can be saved.
$source_field->
save();
// Add the source field to the form display for the media type.
$form_display = \Drupal::
service('entity_display.repository'
)->
getFormDisplay('media',
$media_type->
id(), 'default'
);
$source->
prepareFormDisplay($media_type,
$form_display);
$form_display->
save();
return $media_type;
}}