$this->
assertTrue(isset($entity->name
),
new FormattableMarkup('%entity_type: Name field is set.',
['%entity_type' =>
$entity_type]));
$this->
assertTrue($entity->name->
isEmpty(),
new FormattableMarkup('%entity_type: Name field is set.',
['%entity_type' =>
$entity_type]));
$this->
assertCount(0,
$entity->name,
new FormattableMarkup('%entity_type: Name field contains no items.',
['%entity_type' =>
$entity_type]));
$this->
assertSame([],
$entity->name->
getValue(),
new FormattableMarkup('%entity_type: Name field value is an empty array.',
['%entity_type' =>
$entity_type]));
$this->
assertFalse(isset($entity->name
[0
]),
new FormattableMarkup('%entity_type: Name field item is not set.',
['%entity_type' =>
$entity_type]));
$this->
assertFalse(isset($entity->name
[0
]->value
),
new FormattableMarkup('%entity_type: First name item value is not set.',
['%entity_type' =>
$entity_type]));
$this->
assertFalse(isset($entity->name->value
),
new FormattableMarkup('%entity_type: Name value is not set.',
['%entity_type' =>
$entity_type]));
} // Access the language field.
$langcode_key =
$this->entityTypeManager->
getDefinition($entity_type)->
getKey('langcode'
);
$this->
assertEquals($langcode,
$entity->
{$langcode_key}->value,
new FormattableMarkup('%entity_type: Language code can be read.',
['%entity_type' =>
$entity_type]));
$this->
assertEquals(\Drupal::
languageManager()->
getLanguage($langcode),
$entity->
{$langcode_key}->language,
new FormattableMarkup('%entity_type: Language object can be read.',
['%entity_type' =>
$entity_type]));
// Change the language by code.
$entity->
{$langcode_key}->value = \Drupal::
languageManager()->
getDefaultLanguage()->
getId();
$this->
assertEquals(\Drupal::
languageManager()->
getDefaultLanguage()->
getId(),
$entity->
{$langcode_key}->value,
new FormattableMarkup('%entity_type: Language code can be read.',
['%entity_type' =>
$entity_type]));
$this->
assertEquals(\Drupal::
languageManager()->
getDefaultLanguage(),
$entity->
{$langcode_key}->language,
new FormattableMarkup('%entity_type: Language object can be read.',
['%entity_type' =>
$entity_type]));
// Revert language by code then try setting it by language object.
$entity->
{$langcode_key}->value =
$langcode;
$entity->
{$langcode_key}->language = \Drupal::
languageManager()->
getDefaultLanguage();