public function EntityReferenceRevisionsOrphanRemovalTest::testNotUsedRevisionDeletion in Entity Reference Revisions 8
Tests that revisions that are no longer used are properly deleted.
File
- tests/
src/ Functional/ EntityReferenceRevisionsOrphanRemovalTest.php, line 59
Class
- EntityReferenceRevisionsOrphanRemovalTest
- Tests orphan composite revisions are properly removed.
Namespace
Drupal\Tests\entity_reference_revisions\FunctionalCode
public function testNotUsedRevisionDeletion() {
$entity_test_composite_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_composite');
$composite_entity_first = $entity_test_composite_storage
->loadByProperties([
'name' => 'first not used, second used',
]);
$composite_entity_first = reset($composite_entity_first);
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_first
->id());
$composite_entity_second = $entity_test_composite_storage
->loadByProperties([
'name' => 'first used, second not used',
]);
$composite_entity_second = reset($composite_entity_second);
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_second
->id());
$composite_entity_third = $entity_test_composite_storage
->loadByProperties([
'name' => 'first not used, second not used',
]);
$composite_entity_third = reset($composite_entity_third);
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_third
->id());
$composite_entity_fourth = $entity_test_composite_storage
->loadByProperties([
'name' => '1st filled not, 2nd filled not',
]);
$composite_entity_fourth = reset($composite_entity_fourth);
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_fourth
->id());
$composite_entity_fifth = $entity_test_composite_storage
->loadByProperties([
'name' => '1st not, 2nd used, 3rd not, 4th',
]);
$composite_entity_fifth = reset($composite_entity_fifth);
$this
->assertRevisionCount(4, 'entity_test_composite', $composite_entity_fifth
->id());
$composite_entity_sixth = $entity_test_composite_storage
->loadByProperties([
'name' => 'wrong parent fields',
]);
$composite_entity_sixth = reset($composite_entity_sixth);
$this
->assertRevisionCount(1, 'entity_test_composite', $composite_entity_sixth
->id());
// Test non revisionable parent entities.
$composite_entity_seventh = $entity_test_composite_storage
->loadByProperties([
'name' => 'NR first not used, second used',
]);
$composite_entity_seventh = reset($composite_entity_seventh);
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_seventh
->id());
$composite_entity_eighth = $entity_test_composite_storage
->loadByProperties([
'name' => 'NR first used, second not used',
]);
$composite_entity_eighth = reset($composite_entity_eighth);
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_eighth
->id());
$composite_entity_ninth = $entity_test_composite_storage
->loadByProperties([
'name' => 'NR 1st not, 2nd, 3rd not, 4th',
]);
$composite_entity_ninth = reset($composite_entity_ninth);
$this
->assertRevisionCount(3, 'entity_test_composite', $composite_entity_ninth
->id());
// Set the batch size to 1.
$settings = Settings::getInstance() ? Settings::getAll() : [];
$settings['entity_update_batch_size'] = 1;
new Settings($settings);
// Run the delete process through the form.
$this
->runDeleteForm();
$this
->assertSession()
->pageTextContains('Test entity - composite relationship: Deleted 8 revisions (1 entities)');
$this
->assertRevisionCount(1, 'entity_test_composite', $composite_entity_first
->id());
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_second
->id());
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_third
->id());
$this
->assertRevisionCount(0, 'entity_test_composite', $composite_entity_fourth
->id());
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_fifth
->id());
$this
->assertRevisionCount(1, 'entity_test_composite', $composite_entity_sixth
->id());
$this
->assertRevisionCount(1, 'entity_test_composite', $composite_entity_seventh
->id());
$this
->assertRevisionCount(2, 'entity_test_composite', $composite_entity_eighth
->id());
$this
->assertRevisionCount(1, 'entity_test_composite', $composite_entity_ninth
->id());
}