SimpleMergeTest.php in Conflict 8
File
tests/src/Kernel/SimpleMergeTest.php
View source
<?php
namespace Drupal\Tests\conflict\Kernel;
use Drupal;
use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\conflict;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
class SimpleMergeTest extends EntityKernelTestBase {
protected $entityType;
public static $modules = [
'entity_test',
'conflict',
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('entity_test_rev');
}
public function testsimpleMergeResolver() {
$entity = EntityTestRev::create([
'name' => 'revision 1',
]);
$entity
->save();
$entity
->setName('revision 2');
$entity
->setNewRevision();
$entity
->save();
$entity
->setName('revision 3');
$entity
->setNewRevision();
$entity
->save();
$entity
->setName('revision 4');
$entity
->setNewRevision();
$entity
->save();
$entity
->setName('revision 5');
$entity
->setNewRevision();
$entity
->save();
$entity
->setName('revision 6');
$entity
->setNewRevision();
$entity
->save();
$revision2 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(2);
$revision3 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(3);
$revision4 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(4);
$revision5 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(5);
$revision6 = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision(6);
$manager = Drupal::service('conflict.merge_manager');
$newest_revision1 = $manager
->resolveSimpleMerge($revision2, $revision3, $revision4);
$revisionLca = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision($newest_revision1);
$this
->assertEquals($revisionLca
->label(), "revision 4");
$newest_revision2 = $manager
->resolveSimpleMerge($revision2, $revision3, $revision6);
$revisionLca = Drupal::entityTypeManager()
->getStorage('entity_test_rev')
->loadRevision($newest_revision2);
$this
->assertEquals($revisionLca
->label(), "revision 6");
}
}