You are here

public function EntityReferenceRevisionsCompositeTest::testCompositeDeleteAfterRemovingReferenceWithRevisions in Entity Reference Revisions 8

Tests the composite entity is deleted after removing its reference.

Includes revisions on the host entity.

File

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

Class

EntityReferenceRevisionsCompositeTest
Tests the entity_reference_revisions composite relationship.

Namespace

Drupal\Tests\entity_reference_revisions\Kernel

Code

public function testCompositeDeleteAfterRemovingReferenceWithRevisions() {
  list($composite, $node) = $this
    ->assignCompositeToNode();

  // Remove reference to the composite entity from the node in a new revision.
  $node
    ->set('composite_reference', NULL);
  $node
    ->setNewRevision();
  $node
    ->save();
  $composite = EntityTestCompositeRelationship::load($composite
    ->id());

  // Verify the composite entity is not removed on nodes with revisions.
  $this
    ->assertNotNull($composite);

  // Verify that the composite entity is not yet removed after deleting the
  // parent.
  $node
    ->delete();
  $composite = EntityTestCompositeRelationship::load($composite
    ->id());
  $this
    ->assertNotNull($composite);

  // Verify that the composite entity is removed after running cron.
  $this->cron
    ->run();
  $composite = EntityTestCompositeRelationship::load($composite
    ->id());
  $this
    ->assertNull($composite);
}