View source
<?php
namespace Drupal\Tests\multiversion\Functional;
class ComplexLcaResolverTest extends MultiversionFunctionalTestBase {
protected static $modules = [
'entity_test',
'key_value',
'multiversion',
'conflict',
];
protected $workspaceManager;
protected $tree;
protected $conflictLcaManager;
protected function setUp() {
parent::setUp();
$this->conflictLcaManager = $this->container
->get('conflict.lca_manager');
$this->tree = $this->container
->get('multiversion.entity_index.rev.tree');
}
public function testLcaFinder() {
$storage = $this->entityTypeManager
->getStorage('entity_test');
$entity = $storage
->create();
$uuid = $entity
->uuid();
$entity
->save();
$revs[] = $entity->_rev->value;
$entity
->save();
$revs[] = $entity->_rev->value;
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(2);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(4);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(1);
$entity
->save();
$revs[] = $entity->_rev->value;
$revision = [];
for ($i = 1; $i <= 6; $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[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]);
}
public function testLcaFinder2() {
$storage = $this->entityTypeManager
->getStorage('entity_test');
$entity = $storage
->create();
$uuid = $entity
->uuid();
$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(2);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(1);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(6);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(6);
$entity->name = 'Revision6';
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(3);
$entity
->save();
$revs[] = $entity->_rev->value;
$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]);
}
public function testLcaFinder3() {
$storage = $this->entityTypeManager
->getStorage('entity_test');
$entity = $storage
->create();
$uuid = $entity
->uuid();
$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;
$entity = $storage
->loadRevision(3);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->loadRevision(4);
$entity
->save();
$revs[] = $entity->_rev->value;
$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;
$graph = $this->tree
->getGraph($uuid);
$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]);
}
}