You are here

public function EntityEmbedFilterTest::testBasics in Entity Embed 8

Ensures entities are rendered with correct data attributes.

@dataProvider providerTestBasics

File

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

Class

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

Namespace

Drupal\Tests\entity_embed\Kernel

Code

public function testBasics(array $embed_attributes, $expected_view_mode, array $expected_attributes) {
  $content = $this
    ->createEmbedCode($embed_attributes);
  $result = $this
    ->applyFilter($content);
  $this
    ->assertCount(1, $this
    ->cssSelect('div.embedded-entity > [data-entity-embed-test-view-mode="' . $expected_view_mode . '"]'));
  $this
    ->assertHasAttributes($this
    ->cssSelect('div.embedded-entity')[0], $expected_attributes);
  $this
    ->assertSame([
    'config:filter.format.plain_text',
    'foo:1',
    'node:1',
    'node_view',
    'user:2',
    'user_view',
  ], $result
    ->getCacheTags());
  $this
    ->assertSame([
    'timezone',
    'user.permissions',
  ], $result
    ->getCacheContexts());
  $this
    ->assertSame(Cache::PERMANENT, $result
    ->getCacheMaxAge());
  $this
    ->assertSame([
    'library',
  ], array_keys($result
    ->getAttachments()));
  $this
    ->assertSame([
    'entity_embed/caption',
  ], $result
    ->getAttachments()['library']);
}