tests/src/Kernel/EntityEmbedFilterTest.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/src/Kernel/EntityEmbedFilterTest.php b/tests/src/Kernel/EntityEmbedFilterTest.php index d9fefc3..9b42050 100644 --- a/tests/src/Kernel/EntityEmbedFilterTest.php +++ b/tests/src/Kernel/EntityEmbedFilterTest.php @@ -336,8 +336,9 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { * Tests integration with the caption filter. * * @covers \Drupal\filter\Plugin\Filter\FilterCaption + * @dataProvider providerCaptionFilterIntegration */ - public function testCaptionFilterIntegration() { + public function testCaptionFilterIntegration(array $filter_ids, $expected_figure, array $expected_asset_libraries) { $content = $this->createEmbedCode([ 'data-entity-type' => 'node', 'data-entity-uuid' => 'e7a3e1fe-b69b-417e-8ee4-c80cb7640e63', @@ -353,16 +354,9 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { 'data-entity-embed-display-settings' => 'teaser', ]; - // No captioned embed when running only the `entity_embed` filter - $this->applyFilter($content); - $this->assertCount(0, $this->cssSelect('figure')); - $this->assertHasAttributes($this->cssSelect('div.embedded-entity')[0], $expected_attributes); - - // That changes when running both the `entity-embed` and `filter_caption` - // filters. - $result = $this->processText($content, 'en', ['filter_caption', 'entity_embed']); + $result = $this->processText($content, 'en', $filter_ids); $this->setRawContent($result->getProcessedText()); - $this->assertCount(1, $this->cssSelect('figure')); + $this->assertCount($expected_figure ? 1 : 0, $this->cssSelect('figure')); $this->assertHasAttributes($this->cssSelect('div.embedded-entity')[0], $expected_attributes); // Expected bubbleable metadata. @@ -370,7 +364,6 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { ->setCacheTags(['config:filter.format.plain_text', 'config:filter.settings', 'node:1', 'node_view', 'user:2', 'user_view']) ->setCacheContexts(['timezone', 'user.permissions']) ->setCacheMaxAge(Cache::PERMANENT); - $expected_asset_libraries = ['filter/caption', 'entity_embed/caption']; $this->assertSame($result->getCacheTags(), $expected_cacheability->getCacheTags()); $this->assertSame($result->getCacheContexts(), $expected_cacheability->getCacheContexts()); $this->assertSame($result->getCacheMaxAge(), $expected_cacheability->getCacheMaxAge()); @@ -378,6 +371,21 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { $this->assertSame($result->getAttachments()['library'], $expected_asset_libraries); } + public function providerCaptionFilterIntegration() { + return [ + 'only `entity_embed`' => [ + ['entity_embed'], + FALSE, + ['entity_embed/caption'], + ], + '`filter_caption` + `entity_embed`' => [ + ['filter_caption', 'entity_embed'], + TRUE, + ['filter/caption', 'entity_embed/caption'] + ] + ]; + } + /** * Tests that data-entity-embed-display is preferred over data-view-mode. */