You are here

public function ComplexLcaResolverTest::testLcaFinder in Multiversion 8.2

Shape of Tree created is: 1 / \ 2 6 / \ 3 4 / 5

File

src/Tests/ComplexLcaResolverTest.php, line 48

Class

ComplexLcaResolverTest
Test the Integration of LCA library with multiversion module.

Namespace

Drupal\multiversion\Tests

Code

public function testLcaFinder() {
  $storage = $this->entityTypeManager
    ->getStorage('entity_test');
  $entity = $storage
    ->create();
  $uuid = $entity
    ->uuid();

  // Initial revision.
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Create a new branch from the second revision.
  $entity = $storage
    ->loadRevision(2);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Continue the last branch.
  $entity = $storage
    ->loadRevision(4);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Create a new branch based on the first revision.
  $entity = $storage
    ->loadRevision(1);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Loading and storing revisions in $revision array.
  $revision = [];
  for ($i = 1; $i <= 6; $i++) {
    $revision[$i] = $storage
      ->loadRevision($i);
  }

  // Creating a graph of revision IDs from revision tree.
  $graph = $this->tree
    ->getGraph($uuid);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[1], $revision[2], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[0]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[3], $revision[4], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[1]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[3], $revision[6], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[0]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[2], $revision[6], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[0]);
}