You are here

public function EntityRevisionTranslationTest::testDefaultRevision in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest::testDefaultRevision()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest::testDefaultRevision()

Tests changing the default revision flag is propagated to all translations.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php, line 144

Class

EntityRevisionTranslationTest
Tests proper revision propagation of entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testDefaultRevision() {

  // Create a test entity with a translation, which will internally trigger
  // entity cloning for the new translation and create references for some of
  // the entity properties.
  $entity = EntityTestMulRev::create([
    'name' => 'original',
    'language' => 'en',
  ]);
  $translation = $entity
    ->addTranslation('de');
  $entity
    ->save();

  // Assert that the entity is in the default revision.
  $this
    ->assertTrue($entity
    ->isDefaultRevision());
  $this
    ->assertTrue($translation
    ->isDefaultRevision());

  // Change the default revision flag on one of the entity translations and
  // assert that the change is propagated to all entity translation objects.
  $translation
    ->isDefaultRevision(FALSE);
  $this
    ->assertFalse($entity
    ->isDefaultRevision());
  $this
    ->assertFalse($translation
    ->isDefaultRevision());
}