You are here

public function EntityEmbedFilterOverridesTest::testOverrideAltAndTitleForImage in Entity Embed 8

Tests overriding of `alt` and `title` for default image field formatter.

File

tests/src/Kernel/EntityEmbedFilterOverridesTest.php, line 62

Class

EntityEmbedFilterOverridesTest
Tests that entity embeds can have per-embed overrides for e.g. `alt`.

Namespace

Drupal\Tests\entity_embed\Kernel

Code

public function testOverrideAltAndTitleForImage() {
  $content = $this
    ->createEmbedCode([
    'data-entity-type' => 'file',
    'data-entity-uuid' => $this->image
      ->uuid(),
    'data-entity-embed-display' => 'image:image',
    'data-entity-embed-display-settings' => '{"image_style":"","image_link":""}',
    'alt' => 'This is alt text',
    'title' => 'This is title text',
  ]);
  $this
    ->applyFilter($content);
  $this
    ->assertHasAttributes($this
    ->cssSelect('div.embedded-entity')[0], [
    'alt' => 'This is alt text',
    'data-entity-embed-display' => 'image:image',
    'data-entity-type' => 'file',
    'data-entity-uuid' => $this->image
      ->uuid(),
    'title' => 'This is title text',
    'data-langcode' => 'en',
  ]);
  $this
    ->assertHasAttributes($this
    ->cssSelect('div.embedded-entity img')[0], [
    'alt' => 'This is alt text',
    'title' => 'This is title text',
  ]);
}