class EntityNonRevisionableTranslatableFieldTest in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityNonRevisionableTranslatableFieldTest.php \Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslatableFieldTest
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityNonRevisionableTranslatableFieldTest.php \Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslatableFieldTest
Tests translating a non-revisionable field.
@group Entity
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
- class \Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslatableFieldTest
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
Expanded class hierarchy of EntityNonRevisionableTranslatableFieldTest
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityNonRevisionableTranslatableFieldTest.php, line 13
Namespace
Drupal\KernelTests\Core\EntityView source
class EntityNonRevisionableTranslatableFieldTest extends EntityKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
'language',
'content_translation',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test_mulrev');
$this
->installEntitySchema('configurable_language');
ConfigurableLanguage::createFromLangcode('es')
->save();
}
/**
* Tests translating a non-revisionable field.
*/
public function testTranslatingNonRevisionableField() {
/** @var \Drupal\Core\Entity\ContentEntityBase $entity */
$entity = EntityTestMulRev::create();
$entity
->set('non_rev_field', 'Hello');
$entity
->save();
$translation = $entity
->addTranslation('es');
$translation
->set('non_rev_field', 'Hola');
$translation
->save();
$reloaded = EntityTestMulRev::load($entity
->id());
$this
->assertEquals('Hello', $reloaded
->getTranslation('en')
->get('non_rev_field')->value);
$this
->assertEquals('Hola', $reloaded
->getTranslation('es')
->get('non_rev_field')->value);
}
}