function EntityNonRevisionableTranslatableFieldTest::testTranslatingNonRevisionableField

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityNonRevisionableTranslatableFieldTest.php \Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslatableFieldTest::testTranslatingNonRevisionableField()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityNonRevisionableTranslatableFieldTest.php \Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslatableFieldTest::testTranslatingNonRevisionableField()
  3. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityNonRevisionableTranslatableFieldTest.php \Drupal\KernelTests\Core\Entity\EntityNonRevisionableTranslatableFieldTest::testTranslatingNonRevisionableField()

Tests translating a non-revisionable field.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityNonRevisionableTranslatableFieldTest.php, line 42

Class

EntityNonRevisionableTranslatableFieldTest
Tests translating a non-revisionable field.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testTranslatingNonRevisionableField() : void {
    
    /** @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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.