$form_display->
save();
// Check that the entity displays exists before dependency removal.
$this->
assertNotNull(EntityViewDisplay::
load($view_display->
id()));
$this->
assertNotNull(EntityFormDisplay::
load($form_display->
id()));
// Delete the 'main_style' image style. Before that, emulate the UI process
// of selecting a replacement style by setting the replacement image style
// ID in the image style storage.
/** @var \Drupal\image\ImageStyleStorageInterface $storage */
$storage =
$this->container->
get('entity_type.manager'
)->
getStorage($style->
getEntityTypeId());
$storage->
setReplacementId('main_style', 'replacement_style'
);
$style->
delete();
// Check that the entity displays exists after dependency removal.
$this->
assertNotNull($view_display = EntityViewDisplay::
load($view_display->
id()));
$this->
assertNotNull($form_display = EntityFormDisplay::
load($form_display->
id()));
// Check that the 'sticker' formatter component exists in both displays.
$this->
assertNotNull($formatter =
$view_display->
getComponent('sticker'
));
$this->
assertNotNull($widget =
$form_display->
getComponent('sticker'
));
// Check that both displays are using now 'replacement_style' for images.
$this->
assertSame('replacement_style',
$formatter['settings'
]['image_style'
]);
$this->
assertSame('replacement_style',
$widget['settings'
]['preview_image_style'
]);