$entity =
$this->entityTypeManager
->
getStorage($entity_type) ->
create(['name' =>
$this->
randomMachineName(),
$langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED
]);
$entity->
save();
$hooks =
$this->
getHooksInfo();
$this->
assertEmpty($hooks, 'No entity translation hooks are fired when creating an entity.'
);
// Verify that we obtain the entity object itself when we attempt to
// retrieve a translation referring to it.
$translation =
$entity->
getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED
);
$this->
assertFalse($translation->
isNewTranslation(), 'Existing translations are not marked as new.'
);
$this->
assertSame($entity,
$translation, 'The translation object corresponding to a non-default language is the entity object itself when the entity is language-neutral.'
);
$entity->
{$langcode_key}->value =
$default_langcode;
$translation =
$entity->
getTranslation($default_langcode);
$this->
assertSame($entity,
$translation, 'The translation object corresponding to the default language (explicit) is the entity object itself.'
);
$translation =
$entity->
getTranslation(LanguageInterface::LANGCODE_DEFAULT
);
$this->
assertSame($entity,
$translation, 'The translation object corresponding to the default language (implicit) is the entity object itself.'
);
$this->
assertTrue($entity->
{$default_langcode_key}->value, 'The translation object is the default one.'
);
// Verify that trying to retrieve a translation for a locked language when
// the entity is language-aware causes an exception to be thrown.
try {