public function GraphCreationTest::testGraphCreation2 in Multiversion 8.2
Shape of tree is: 1 / \ 2 6 / \ / \ 3 5 7 8 / \ / 4 9 10
File
- src/
Tests/ GraphCreationTest.php, line 124
Class
- GraphCreationTest
- Test the getGraph method from the RevisionTreeIndex class.
Namespace
Drupal\multiversion\TestsCode
public function testGraphCreation2() {
$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[] = $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;
$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
->save();
$revs[] = $entity->_rev->value;
// Continue the last branch.
$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;
$graph = $this->tree
->getGraph($uuid);
$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[2], 'node 4\'s parent is 3');
}
foreach ($vertices[$revs[4]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[1], 'node 5\'s parent is 2');
}
foreach ($vertices[$revs[5]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[0], 'node 6\'s parent is 1');
}
foreach ($vertices[$revs[6]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[5], 'node 7\'s parent is 6');
}
foreach ($vertices[$revs[7]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[5], 'node 8\'s parent is 6');
}
foreach ($vertices[$revs[8]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[2], 'node 9\'s parent is 3');
}
foreach ($vertices[$revs[9]]
->getVerticesEdgeFrom() as $parent) {
$this
->assertEqual($parent
->getId(), $revs[7], 'node 10\'s parent is 8');
}
}