$event_subscriber->
enableLiveDefinitionUpdates();
// Test field storage definition events.
$storage_definition = FieldStorageDefinition::
create('string'
) ->
setName('field_storage_test'
) ->
setLabel(new TranslatableMarkup('Field storage test'
)) ->
setTargetEntityTypeId('entity_test_rev'
);
$this->
assertFalse($event_subscriber->
hasEventFired(FieldStorageDefinitionEvents::CREATE
), 'Entity type create was not dispatched yet.'
);
\Drupal::
service('field_storage_definition.listener'
)->
onFieldStorageDefinitionCreate($storage_definition);
$this->
assertTrue($event_subscriber->
hasEventFired(FieldStorageDefinitionEvents::CREATE
), 'Entity type create event successfully dispatched.'
);
$this->
assertTrue($event_subscriber->
hasDefinitionBeenUpdated(FieldStorageDefinitionEvents::CREATE
), 'Last installed field storage definition was created before the event was fired.'
);
// Check that the newly added field can be retrieved from the live field
// storage definitions.
$field_storage_definitions =
$this->entityFieldManager->
getFieldStorageDefinitions('entity_test_rev'
);
$this->
assertArrayHasKey('field_storage_test',
$field_storage_definitions);
$updated_storage_definition =
clone $storage_definition;
$updated_storage_definition->
setLabel(new TranslatableMarkup('Updated field storage test'
));
$this->
assertFalse($event_subscriber->
hasEventFired(FieldStorageDefinitionEvents::UPDATE
), 'Entity type update was not dispatched yet.'
);
\Drupal::
service('field_storage_definition.listener'
)->
onFieldStorageDefinitionUpdate($updated_storage_definition,
$storage_definition);
$this->
assertTrue($event_subscriber->
hasEventFired(FieldStorageDefinitionEvents::UPDATE
), 'Entity type update event successfully dispatched.'
);