You are here

public function EntityReferenceRevisionsCompositeTest::testCompositeDeleteAfterDuplicatingParent in Entity Reference Revisions 8

Tests the composite entity is not deleted when duplicating host entity.

Includes revisions on the host entity.

File

tests/src/Kernel/EntityReferenceRevisionsCompositeTest.php, line 639

Class

EntityReferenceRevisionsCompositeTest
Tests the entity_reference_revisions composite relationship.

Namespace

Drupal\Tests\entity_reference_revisions\Kernel

Code

public function testCompositeDeleteAfterDuplicatingParent() {
  list($composite, $node) = $this
    ->assignCompositeToNode();
  $node
    ->setNewRevision(TRUE);
  $node
    ->save();

  // Create a duplicate of the node.
  $duplicate_node = $node
    ->createDuplicate();
  $duplicate_node
    ->save();
  $duplicate_node
    ->setNewRevision(TRUE);
  $duplicate_node
    ->save();

  // Verify the amount of revisions of each entity.
  $this
    ->assertRevisionCount(3, 'entity_test_composite', $composite
    ->id());
  $this
    ->assertRevisionCount(2, 'node', $node
    ->id());
  $this
    ->assertRevisionCount(2, 'node', $duplicate_node
    ->id());

  // Test that the composite entity is not deleted when the duplicate is
  // deleted.
  $duplicate_node
    ->delete();
  $composite = EntityTestCompositeRelationship::load($composite
    ->id());
  $this
    ->assertNotNull($composite);
  $this->cron
    ->run();
  $composite = EntityTestCompositeRelationship::load($composite
    ->id());
  $this
    ->assertNotNull($composite);
}