You are here

public function ComplexLcaResolverTest::testLcaFinder2 in Multiversion 8

Shape of tree is: 1 / \ 2 6 / \ / \ 3 5 7 8 / \ / 4 9 10

File

tests/src/Functional/ComplexLcaResolverTest.php, line 111

Class

ComplexLcaResolverTest
Test the Integration of LCA library with multiversion module.

Namespace

Drupal\Tests\multiversion\Functional

Code

public function testLcaFinder2() {
  $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;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

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

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

  // Creating a new branch from sixth revision.
  $entity = $storage
    ->loadRevision(6);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Creating another revision branch from sixth revision.
  $entity = $storage
    ->loadRevision(6);
  $entity->name = 'Revision6';
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity = $storage
    ->loadRevision(3);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Create a new branch based on the first revision.
  $entity = $storage
    ->loadRevision(8);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $revision = [];
  for ($i = 1; $i <= 10; $i++) {
    $revision[$i] = $storage
      ->loadRevision($i);
  }
  $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[2], $revision[6], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[0]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[3], $revision[5], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[1]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[2], $revision[3], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[1]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[4], $revision[5], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[1]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[4], $revision[9], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[7], $revision[10], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[5]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[6], $revision[7], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[5]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[7], $revision[8], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[5]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[8], $revision[9], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[0]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[6], $revision[8], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[5]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[3], $revision[9], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
}