public function EntityRevisionTranslationTest::testTranslationValuesWhenSavingPendingRevisions in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest::testTranslationValuesWhenSavingPendingRevisions()
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest::testTranslationValuesWhenSavingPendingRevisions()
Tests the translation values when saving a pending revision.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityRevisionTranslationTest.php, line 99
Class
- EntityRevisionTranslationTest
- Tests proper revision propagation of entities.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testTranslationValuesWhenSavingPendingRevisions() {
$user = $this
->createUser();
$storage = $this->entityTypeManager
->getStorage('entity_test_mulrev');
// Create a test entity and a translation for it.
$entity = EntityTestMulRev::create([
'name' => 'default revision - en',
'user_id' => $user
->id(),
'language' => 'en',
]);
$entity
->addTranslation('de', [
'name' => 'default revision - de',
]);
$entity
->save();
// Create a pending revision for the entity and change a field value for
// both languages.
$pending_revision = $this
->reloadEntity($entity);
$pending_revision
->setNewRevision();
$pending_revision
->isDefaultRevision(FALSE);
$pending_revision->name = 'pending revision - en';
$pending_revision
->save();
$pending_revision_translation = $pending_revision
->getTranslation('de');
$pending_revision_translation->name = 'pending revision - de';
$pending_revision_translation
->save();
$pending_revision_id = $pending_revision
->getRevisionId();
$pending_revision = $storage
->loadRevision($pending_revision_id);
// Change the value of the field in the default language, save the pending
// revision and check that the value of the field in the second language is
// also taken from the pending revision, *not* from the default revision.
$pending_revision->name = 'updated pending revision - en';
$pending_revision
->save();
$pending_revision = $storage
->loadRevision($pending_revision_id);
$this
->assertEquals('updated pending revision - en', $pending_revision->name->value);
$this
->assertEquals('pending revision - de', $pending_revision
->getTranslation('de')->name->value);
}