public function MultiversionManagerTest::testRevisionIdGeneration in Multiversion 8
File
- tests/
src/ Functional/ MultiversionManagerTest.php, line 41
Class
- MultiversionManagerTest
- Test the MultiversionManager class.
Namespace
Drupal\Tests\multiversion\FunctionalCode
public function testRevisionIdGeneration() {
$entity = EntityTestRev::create();
$first_rev = $this->multiversionManager
->newRevisionId($entity, 0);
$this
->assertRevisionId(1, $first_rev, 'First revision ID was generated correctly.');
$new_rev = $this->multiversionManager
->newRevisionId($entity, 0);
$this
->assertEqual($first_rev, $new_rev, 'Identical revision IDs with same input parameters.');
$second_rev = $this->multiversionManager
->newRevisionId($entity, 1);
$this
->assertRevisionId(2, $second_rev, 'Second revision ID was generated correctly.');
$this
->assertEqual($this
->extractRevisionHash($first_rev), $this
->extractRevisionHash($second_rev), 'First and second revision hashes was identical (entity did not change).');
$revs = [
$first_rev,
];
$test_entity = clone $entity;
$test_entity->_rev->value = $first_rev;
$revs[] = $this->multiversionManager
->newRevisionId($test_entity, 0);
$this
->assertTrue(count($revs) == count(array_unique($revs)), 'Revision ID varies on old revision.');
$test_entity = clone $entity;
$test_entity->name = $this
->randomMachineName();
$revs[] = $this->multiversionManager
->newRevisionId($test_entity, 0);
$this
->assertTrue(count($revs) == count(array_unique($revs)), 'Revision ID varies on entity fields.');
$test_entity = clone $entity;
$test_entity->_deleted->value = TRUE;
$revs[] = $this->multiversionManager
->newRevisionId($test_entity, 0);
$this
->assertTrue(count($revs) == count(array_unique($revs)), 'Revision ID varies on deleted flag.');
}