function EntityRevisionTranslationTest::testDefaultRevision

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest::testDefaultRevision()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionTranslationTest::testDefaultRevision()
  3. 11.x 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 148

Class

EntityRevisionTranslationTest
Tests proper revision propagation of entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

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

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