You are here

public function EntityReferenceRevisionsFormatterTest::testFormatterWithDeletedReference in Entity Reference Revisions 8

File

tests/src/Kernel/EntityReferenceRevisionsFormatterTest.php, line 70

Class

EntityReferenceRevisionsFormatterTest
@coversDefaultClass \Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsEntityFormatter @group entity_reference_revisions

Namespace

Drupal\Tests\entity_reference_revisions\Kernel

Code

public function testFormatterWithDeletedReference() {

  // Create the test composite entity.
  $text = 'Dummy text';
  $entity_test = EntityTestCompositeRelationship::create([
    'uuid' => $text,
    'name' => $text,
  ]);
  $entity_test
    ->save();
  $text = 'Clever text';

  // Set the name to a new text.

  /** @var \Drupal\entity_composite_relationship_test\Entity\EntityTestCompositeRelationship $entity_test */
  $entity_test->name = $text;
  $entity_test
    ->setNeedsSave(TRUE);
  $node = Node::create([
    'title' => $this
      ->randomMachineName(),
    'type' => 'article',
    'composite_reference' => $entity_test,
  ]);
  $node
    ->save();

  // entity_reference_revisions_entity_view
  $result = $node->composite_reference
    ->view([
    'type' => 'entity_reference_revisions_entity_view',
  ]);
  $this
    ->setRawContent($this
    ->render($result));
  $this
    ->assertText('Clever text');

  // Remove the referenced entity.
  $entity_test
    ->delete();
  $node = Node::load($node
    ->id());
  $result = $node->composite_reference
    ->view([
    'type' => 'entity_reference_revisions_entity_view',
  ]);
  $this
    ->render($result);
  $this
    ->assertNoText('Clever text');
}