UuidIndexHooksTest.php in Multiversion 8.2
File
src/Tests/UuidIndexHooksTest.php
View source
<?php
namespace Drupal\multiversion\Tests;
class UuidIndexHooksTest extends MultiversionWebTestBase {
public function testEntityHooks() {
$keys = $this->uuidIndex
->get('foo');
$this
->assertTrue(empty($keys), 'Empty array was returned when fetching non-existing UUID.');
$entity_test_storage = $this->container
->get('entity.manager')
->getStorage('entity_test');
$entity = $entity_test_storage
->create();
$entity
->save();
$keys = $this->uuidIndex
->get($entity
->uuid());
$this
->assertEqual([
'entity_type_id' => $entity
->getEntityTypeId(),
'entity_id' => $entity
->id(),
'revision_id' => $entity
->getRevisionId(),
'rev' => $entity->_rev->value,
'is_stub' => $entity->_rev->is_stub,
'uuid' => $entity
->uuid(),
'status' => 'available',
], $keys, 'Index entry was created by insert hook.');
$entities = $entity_test_storage
->loadMultiple([
$entity
->id(),
]);
$entity_test_storage
->delete($entities);
$keys = $this->uuidIndex
->get($entity
->uuid());
$this
->assertTrue(!empty($keys), 'Index entry should not be removed when an entity is deleted.');
}
}