You are here

public function EntityEmbedFilterTest::testMissingEntityIndicator in Entity Embed 8

Tests the indicator for missing entities.

@dataProvider providerMissingEntityIndicator

File

tests/src/Kernel/EntityEmbedFilterTest.php, line 242

Class

EntityEmbedFilterTest
@coversDefaultClass \Drupal\entity_embed\Plugin\Filter\EntityEmbedFilter @group entity_embed

Namespace

Drupal\Tests\entity_embed\Kernel

Code

public function testMissingEntityIndicator($entity_type_id, $uuid, $expected_missing_text) {
  $content = $this
    ->createEmbedCode([
    'data-entity-type' => $entity_type_id,
    'data-entity-uuid' => $uuid,
    'data-view-mode' => 'default',
  ]);

  // If the UUID being used in the embed is that of the sample entity, first
  // assert that it currently results in a functional embed, then delete it.
  if ($uuid === static::EMBEDDED_ENTITY_UUID) {
    $this
      ->applyFilter($content);
    $this
      ->assertCount(1, $this
      ->cssSelect('div.embedded-entity > [data-entity-embed-test-view-mode="default"]'));
    $this->embeddedEntity
      ->delete();
  }
  $this
    ->applyFilter($content);
  $this
    ->assertCount(0, $this
    ->cssSelect('div.embedded-entity > [data-entity-embed-test-view-mode="default"]'));
  $this
    ->assertCount(0, $this
    ->cssSelect('div.embedded-entity'));
  $deleted_embed_warning = $this
    ->cssSelect('img')[0];
  $this
    ->assertNotEmpty($deleted_embed_warning);
  $this
    ->assertHasAttributes($deleted_embed_warning, [
    'alt' => $expected_missing_text,
    'src' => file_url_transform_relative(file_create_url('core/modules/media/images/icons/no-thumbnail.png')),
    'title' => $expected_missing_text,
  ]);
}