SequenceIndexTest.php in Multiversion 8.2
File
src/Tests/SequenceIndexTest.php
View source
<?php
namespace Drupal\multiversion\Tests;
use Drupal\entity_test\Entity\EntityTestRev;
class SequenceIndexTest extends MultiversionWebTestBase {
protected $sequenceIndex;
protected function setUp() {
parent::setUp();
$this->sequenceIndex = \Drupal::service('multiversion.entity_index.sequence');
}
public function testRecord() {
$entity = EntityTestRev::create();
$expected = [
'entity_type_id' => 'entity_test_rev',
'entity_id' => 1,
'entity_uuid' => $entity
->uuid(),
'revision_id' => 1,
'deleted' => FALSE,
'rev' => FALSE,
'local' => (bool) $entity
->getEntityType()
->get('local'),
'is_stub' => FALSE,
];
$entity->id->value = $expected['entity_id'];
$entity->revision_id->value = $expected['revision_id'];
$entity->_deleted->value = $expected['deleted'];
$entity->_rev->value = $expected['rev'];
$values = $this->sequenceIndex
->getRange(3);
$this
->assertEqual(0, count($values), 'There are 0 index entries');
$this->sequenceIndex
->add($entity);
$expected['seq'] = $this->multiversionManager
->lastSequenceId();
$values = $this->sequenceIndex
->getRange(4);
$this
->assertEqual(1, count($values), 'One new index entry was added.');
foreach ($expected as $key => $value) {
$this
->assertIdentical($value, $values[0][$key], "Index entry key {$key} have value {$value}");
}
$entity = EntityTestRev::create();
$workspace_name = $this
->randomMachineName();
$workspace_storage = $this->container
->get('entity.manager')
->getStorage('workspace');
$workspace_storage
->create([
'machine_name' => $workspace_name,
'type' => 'basic',
]);
$this->sequenceIndex
->useWorkspace($workspace_name)
->add($entity);
$values = $this->sequenceIndex
->getRange(3);
$this
->assertEqual(1, count($values), 'One index entry was added to the new workspace.');
}
}