$langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
$this->
assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED,
$entity->
language()->
getId(),
new FormattableMarkup('%entity_type: Entity language not specified.',
['%entity_type' =>
$entity_type]));
$this->
assertEmpty($entity->
getTranslationLanguages(FALSE
),
new FormattableMarkup('%entity_type: No translations are available',
['%entity_type' =>
$entity_type]));
// Set the value in default language.
$entity->
set($this->fieldName,
[0 =>
['value' => 'default value'
]]);
// Get the value.
$field =
$entity->
getTranslation(LanguageInterface::LANGCODE_DEFAULT
)->
get($this->fieldName
);
$this->
assertEquals('default value',
$field->value,
new FormattableMarkup('%entity_type: Untranslated value retrieved.',
['%entity_type' =>
$entity_type]));
$this->
assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED,
$field->
getLangcode(),
new FormattableMarkup('%entity_type: Field object has the expected langcode.',
['%entity_type' =>
$entity_type]));
// Try to get add a translation to language neutral entity.
try { $entity->
addTranslation($this->langcodes
[1
]);
$this->
fail('Adding a translation to a language-neutral entity results in an error.'
);
} catch (\InvalidArgumentException
$e) { // Expected exception; just continue testing.
} // Now, make the entity language-specific by assigning a language and test