.../src/Kernel/EntityEmbedFilterOverridesTest.php | 10 ++----- tests/src/Kernel/EntityEmbedFilterTest.php | 34 +++++++--------------- tests/src/Kernel/EntityEmbedFilterTestBase.php | 14 +++++++-- .../Kernel/EntityEmbedFilterTranslationTest.php | 3 +- 4 files changed, 24 insertions(+), 37 deletions(-) diff --git a/tests/src/Kernel/EntityEmbedFilterOverridesTest.php b/tests/src/Kernel/EntityEmbedFilterOverridesTest.php index 1e27bfe..4296cee 100644 --- a/tests/src/Kernel/EntityEmbedFilterOverridesTest.php +++ b/tests/src/Kernel/EntityEmbedFilterOverridesTest.php @@ -69,10 +69,7 @@ class EntityEmbedFilterOverridesTest extends EntityEmbedFilterTestBase { 'title' => 'This is title text', ]); - /** @var \Drupal\filter\FilterProcessResult $filter_result */ - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); - $this->assertEntityEmbedFilterHasRun($output); + $output = $this->applyFilter($content); $dom = Html::load($output); $xpath = new \DOMXPath($dom); @@ -139,10 +136,7 @@ class EntityEmbedFilterOverridesTest extends EntityEmbedFilterTestBase { 'title' => 'title 3', ] + $base); - /** @var \Drupal\filter\FilterProcessResult $filter_result */ - $filter_result = $this->filter->process($input, 'en'); - $output = $filter_result->getProcessedText(); - $this->assertEntityEmbedFilterHasRun($output); + $output = $this->applyFilter($input); $dom = Html::load($output); $xpath = new \DOMXPath($dom); diff --git a/tests/src/Kernel/EntityEmbedFilterTest.php b/tests/src/Kernel/EntityEmbedFilterTest.php index 609cda0..15e668f 100644 --- a/tests/src/Kernel/EntityEmbedFilterTest.php +++ b/tests/src/Kernel/EntityEmbedFilterTest.php @@ -42,15 +42,12 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { $this->container->get('current_user') ->addRole($this->drupalCreateRole($permissions)); - /** @var \Drupal\filter\FilterProcessResult $filter_result */ - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); + $output = $this->applyFilter($content); if (!$is_published && !$allowed_to_view_unpublished) { $this->assertEmpty($output); return; } - $this->assertEntityEmbedFilterHasRun($output); $this->assertContainsMultiple($contains, $output); $this->assertNotContainsMultiple($not_contains, $output); @@ -249,10 +246,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { public function testInvalidEntity(array $embed_attributes, array $contains, array $not_contains) { $content = $this->createEmbedCode($embed_attributes); - /** @var \Drupal\filter\FilterProcessResult $filter_result */ - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); - $this->assertEntityEmbedFilterHasRun($output); + $output = $this->applyFilter($content); $this->assertContainsMultiple($contains, $output); $this->assertNotContainsMultiple($not_contains, $output); @@ -295,6 +289,10 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { $filter_result = $this->filter->process($content, 'en'); $output = $filter_result->getProcessedText(); + // The text content of the tag should still exist since + // the filter should not have touched it at all. For the same reason, the + // content of the to-be-embedded entity should not be present. + $this->assertContains('This placeholder should not be rendered.', $output); $this->assertNotContains($this->node->body->value, $output); $dom = Html::load($output); @@ -338,12 +336,8 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { 'data-entity-embed-display-settings' => '{"view_mode":"full"}', 'data-view-mode' => 'some-invalid-view-mode', ]); - - /** @var \Drupal\filter\FilterProcessResult $filter_result */ - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); + $output = $this->applyFilter($content); $this->assertContains($this->node->body->value, $output); - $this->assertEntityEmbedFilterHasRun($output); } /** @@ -358,12 +352,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { 'data-entity-embed-display' => 'entity_reference:entity_reference_label', 'data-entity-embed-settings' => '{"link":"0"}', ]); - - /** @var \Drupal\filter\FilterProcessResult $filter_result */ - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); - $this->assertEntityEmbedFilterHasRun($output); - + $output = $this->applyFilter($content); $dom = Html::load($output); $xpath = new \DOMXPath($dom); $this->assertSame(0, $xpath->query('//div[contains(@class, "embedded-entity")]/a')->length); @@ -380,17 +369,14 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { 'data-view-mode' => 'default', ]); - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); + $output = $this->applyFilter($content); $this->assertContains($this->node->body->value, $output); $this->assertNotContains('Deleted content encountered, site owner alerted', $output); $this->node->delete(); - $filter_result = $this->filter->process($content, 'en'); - $output = $filter_result->getProcessedText(); + $output = $this->applyFilter($content); $this->assertNotContains('Embedded text content', $output); - $dom = Html::load($output); $xpath = new \DOMXPath($dom); $deleted_embed_warning = $xpath->query('//img')[0]; diff --git a/tests/src/Kernel/EntityEmbedFilterTestBase.php b/tests/src/Kernel/EntityEmbedFilterTestBase.php index 16d3568..ef37356 100644 --- a/tests/src/Kernel/EntityEmbedFilterTestBase.php +++ b/tests/src/Kernel/EntityEmbedFilterTestBase.php @@ -127,16 +127,24 @@ abstract class EntityEmbedFilterTestBase extends KernelTestBase { } /** - * Asserts that `@Filter=entity_embed` has been run successfully. + * Applies the `@Filter=entity_embed` filter to the given text. * - * @param string $output + * @param string $text + * The text passed to the filter. + * + * @return string * The string returned by the filtering process. * * @see \Drupal\Tests\entity_embed\Kernel\EntityEmbedFilterTestBase::createEmbedCode() */ - protected function assertEntityEmbedFilterHasRun($output) { + protected function applyFilter($text) { + $this->assertContains('assertContains('This placeholder should not be rendered.', $text); + $filter_result = $this->filter->process($text, 'en'); + $output = $filter_result->getProcessedText(); $this->assertNotContains('assertNotContains('This placeholder should not be rendered.', $output); + return $output; } /** diff --git a/tests/src/Kernel/EntityEmbedFilterTranslationTest.php b/tests/src/Kernel/EntityEmbedFilterTranslationTest.php index 8bd6702..69bf895 100644 --- a/tests/src/Kernel/EntityEmbedFilterTranslationTest.php +++ b/tests/src/Kernel/EntityEmbedFilterTranslationTest.php @@ -81,8 +81,7 @@ class EntityEmbedFilterTranslationTest extends EntityEmbedFilterTestBase { ->setTitle('Embed em portugues') ->save(); - $filter_result = $this->filter->process($content, $process_lang); - $output = $filter_result->getProcessedText(); + $output = $this->applyFilter($content); // Run the assertions based on the data. if ($assert_title_from_source) {