public function KernelLcaTest::testsimpleLcaResolver in Conflict 8
Creates an entity and it's revisions then performs a simple algorithm to find common parent of two revisions.
File
- tests/
src/ Kernel/ KernelLcaTest.php, line 34
Class
- KernelLcaTest
- @group conflict
Namespace
Drupal\Tests\conflict\KernelCode
public function testsimpleLcaResolver() {
// Creates a new entity
$entity = EntityTestRev::create([
'name' => 'revision 1',
]);
$entity
->save();
// Updates it multiple times to create new revisions.
$entity
->setName('revision 2');
$entity
->setNewRevision();
$entity
->save();
$entity
->setName('revision 3');
$entity
->setNewRevision();
$entity
->save();
$entity
->setName('revision 4');
$entity
->setNewRevision();
$entity
->save();
// Load the revisions from database.
$revision2 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(2);
$revision3 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(3);
$revision4 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(4);
$manager = Drupal::service('conflict.lca_manager');
// Gets the parent id for revision 2 and 3.
$parent_revision_id1 = $manager
->resolveLowestCommonAncestor($revision2, $revision3);
$revisionLca = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision($parent_revision_id1);
$this
->assertEquals($revisionLca
->label(), "revision 1");
// Gets the parent id for revision 3 and 4.
$parent_revision_id2 = $manager
->resolveLowestCommonAncestor($revision3, $revision4);
$revisionLca = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision($parent_revision_id2);
$this
->assertEquals($revisionLca
->label(), "revision 2");
}