function EntityRevisionsTest::testTranslatedLoadedRevisionId
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testTranslatedLoadedRevisionId()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testTranslatedLoadedRevisionId()
- 11.x 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() : void {
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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.