function EntityRevisionTranslationTest::testRevertRevisionAfterTranslation

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

Tests if the translation object has the right revision id after new revision.

File

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

Class

EntityRevisionTranslationTest
Tests proper revision propagation of entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testRevertRevisionAfterTranslation() : void {
    $user = $this->createUser();
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
    $storage = $this->entityTypeManager
        ->getStorage('entity_test_mulrev');
    // Create a test entity.
    $entity = EntityTestMulRev::create([
        'name' => $this->randomString(),
        'user_id' => $user->id(),
        'language' => 'en',
    ]);
    $entity->save();
    $old_rev_id = $entity->getRevisionId();
    $translation = $entity->addTranslation('de');
    $translation->setNewRevision();
    $translation->save();
    $entity = $this->reloadEntity($entity);
    $this->assertTrue($entity->hasTranslation('de'));
    $entity = $storage->loadRevision($old_rev_id);
    $entity->setNewRevision();
    $entity->isDefaultRevision(TRUE);
    $entity->save();
    $entity = $this->reloadEntity($entity);
    $this->assertFalse($entity->hasTranslation('de'));
}

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