function EntityTranslationTest::testEntityAdapter
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityTranslationTest::testEntityAdapter()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityTranslationTest::testEntityAdapter()
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityTranslationTest::testEntityAdapter()
Tests how entity adapters work with translations.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityTranslationTest.php, line 779
Class
- EntityTranslationTest
- Tests entity translation functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testEntityAdapter() {
$entity_type = 'entity_test';
$default_langcode = 'en';
$values[$default_langcode] = [
'name' => $this->randomString(),
];
$controller = $this->entityTypeManager
->getStorage($entity_type);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $controller->create($values[$default_langcode]);
foreach ($this->langcodes as $langcode) {
$values[$langcode] = [
'name' => $this->randomString(),
];
$entity->addTranslation($langcode, $values[$langcode]);
}
$langcodes = array_merge([
$default_langcode,
], $this->langcodes);
foreach ($langcodes as $langcode) {
$adapter = $entity->getTranslation($langcode)
->getTypedData();
$name = $adapter->get('name')->value;
$this->assertEquals($values[$langcode]['name'], $name, new FormattableMarkup('Name correctly retrieved from "@langcode" adapter', [
'@langcode' => $langcode,
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.