public function GraphCreationTest::testGraphCreation in Multiversion 8
Shape of Tree created is: 1 / \ 2 6 / \ 3 4 / 5
File
- tests/
src/ Functional/ GraphCreationTest.php, line 42
Class
- GraphCreationTest
- Test the getGraph method from the RevisionTreeIndex class.
Namespace
Drupal\Tests\multiversion\FunctionalCode
public function testGraphCreation() {
$storage = $this->entityTypeManager
->getStorage('entity_test_rev');
$entity = $storage
->create();
$uuid = $entity
->uuid();
// Create a conflict scenario to fully test the parsing.
// Initial revision.
$entity
->save();
$revs[] = $entity->_rev->value;
$entity
->save();
$revs[] = $entity->_rev->value;
$entity
->save();
$revs[] = $leaf_one = $entity->_rev->value;
$entity = $storage
->load(1);
$this
->assertEqual($entity
->getRevisionId(), 3, 'Default revision has been set correctly.');
// Create a new branch from the second revision.
$entity = $storage
->loadRevision(2);
$entity
->save();
$revs[] = $leaf_two = $entity->_rev->value;
// We now have two leafs at the tip of the tree.
$leafs = [
$leaf_one,
$leaf_two,
];
sort($leafs);
$expected_leaf = array_pop($leafs);
$entity = $storage
->load(1);
$this
->assertEqual($entity->_rev->value, $expected_leaf, 'The correct revision won while having two open revisions.');
// Continue the last branch.
$entity = $storage
->loadRevision(4);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->load(1);
$this
->assertEqual($entity
->getRevisionId(), 5, 'Default revision has been set correctly.');
// Create a new branch based on the first revision.
$entity = $storage
->loadRevision(1);
$entity
->save();
$revs[] = $entity->_rev->value;
$entity = $storage
->load(1);
$this
->assertEqual($entity
->getRevisionId(), 5, 'Default revision has been set correctly.');
// Creating graph from the revision tree.
$graph = $this->tree
->getGraph($uuid);
// Storing the graph's vertices in $vertices array.
$vertices = $graph
->getVertices()
->getMap();
foreach ($vertices[$revs[1]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[0], 'node 2\'s parent is 1');
}
foreach ($vertices[$revs[2]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[1], 'node 3\'s parent is 2');
}
foreach ($vertices[$revs[3]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[1], 'node 4\'s parent is 2');
}
foreach ($vertices[$revs[4]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[3], 'node 5\'s parent is 4');
}
foreach ($vertices[$revs[5]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[0], 'node 6\'s parent is 1');
}
}