public function EntityRevisionsTest::testTranslatedLoadedRevisionId in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testTranslatedLoadedRevisionId()
Tests the loaded revision ID for translatable entities.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityRevisionsTest.php, line 121
Class
- EntityRevisionsTest
- Tests the loaded Revision of an entity.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testTranslatedLoadedRevisionId() {
ConfigurableLanguage::createFromLangcode('fr')
->save();
// Create a basic EntityTestMulRev entity and save it.
$entity = EntityTestMulRev::create();
$entity
->save();
// Load the created entity and create a new revision.
$loaded = EntityTestMulRev::load($entity
->id());
$loaded
->setNewRevision(TRUE);
$loaded
->save();
// Check it all works with translations.
$french = $loaded
->addTranslation('fr');
// Adding a revision should return the same for each language.
$this
->assertEquals($french
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertEquals($loaded
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertEquals($loaded
->getLoadedRevisionId(), $french
->getLoadedRevisionId());
$french
->save();
// After saving nothing should change.
$this
->assertEquals($french
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertEquals($loaded
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertEquals($loaded
->getLoadedRevisionId(), $french
->getLoadedRevisionId());
$first_revision_id = $french
->getRevisionId();
$french
->setNewRevision();
// Setting a new revision will reset the loaded Revision ID.
$this
->assertEquals($first_revision_id, $french
->getLoadedRevisionId());
$this
->assertEquals($first_revision_id, $loaded
->getLoadedRevisionId());
$this
->assertNotEquals($french
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertGreaterThan($french
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertNotEquals($loaded
->getRevisionId(), $loaded
->getLoadedRevisionId());
$this
->assertGreaterThan($loaded
->getRevisionId(), $loaded
->getLoadedRevisionId());
$french
->save();
// Saving the new revision will reset the origin revision ID again.
$this
->assertEquals($french
->getRevisionId(), $french
->getLoadedRevisionId());
$this
->assertEquals($loaded
->getRevisionId(), $loaded
->getLoadedRevisionId());
}