You are here

public function ComplexLcaResolverTest::testLcaFinder3 in Multiversion 8

File

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

Class

ComplexLcaResolverTest
Test the Integration of LCA library with multiversion module.

Namespace

Drupal\Tests\multiversion\Functional

Code

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

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

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

  // Create a new branch from the fifth revision.
  $entity = $storage
    ->loadRevision(5);
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity = $storage
    ->loadRevision(3);
  $entity->name = 'Revision3';
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity = $storage
    ->loadRevision(1);
  $entity->name = 'Revision6';
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity = $storage
    ->loadRevision(14);
  $entity->name = 'Revision14';
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity
    ->save();
  $revs[] = $entity->_rev->value;
  $entity = $storage
    ->loadRevision(16);
  $entity->name = 'Revision16';
  $entity
    ->save();
  $revs[] = $entity->_rev->value;

  // Creating graph from revision tree.
  $graph = $this->tree
    ->getGraph($uuid);

  // Loading and storing revisions in $revision array.
  $revision = [];
  for ($i = 1; $i <= 21; $i++) {
    $revision[$i] = $storage
      ->loadRevision($i);
  }
  $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[3], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[1]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[7], $revision[8], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[6]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[5], $revision[9], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[3]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[10], $revision[11], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[16], $revision[17], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[15]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[17], $revision[20], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[13]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[6], $revision[21], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[0]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[6], $revision[11], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[17], $revision[21], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[15]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[15], $revision[18], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[13]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[5], $revision[9], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[3]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[6], $revision[10], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[4]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[7], $revision[11], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[13], $revision[14], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[12]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[8], $revision[12], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
  $lca_id = $this->conflictLcaManager
    ->resolveLowestCommonAncestor($revision[4], $revision[8], $graph);
  $this
    ->assertEqual($lca_id
    ->getId(), $revs[2]);
}