tests/src/Kernel/EntityEmbedFilterTest.php | 31 +++++--------------------- tests/src/Kernel/EntityEmbedFilterTestBase.php | 16 ++++++++++++- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/tests/src/Kernel/EntityEmbedFilterTest.php b/tests/src/Kernel/EntityEmbedFilterTest.php index f841858..d584ecd 100644 --- a/tests/src/Kernel/EntityEmbedFilterTest.php +++ b/tests/src/Kernel/EntityEmbedFilterTest.php @@ -83,7 +83,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { return; } $this->assertNotContains('drupal-entity data-entity-type="node" data-entity', $output); - $this->assertNotContains('This placeholder should not be rendered.', $output); + $this->assertEntityEmbedFilterHasRun($output); $this->assertContainsMultiple($contains, $output); $this->assertNotContainsMultiple($not_contains, $output); @@ -285,6 +285,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { /** @var \Drupal\filter\FilterProcessResult $filter_result */ $filter_result = $this->filter->process($content, 'en'); $output = $filter_result->getProcessedText(); + $this->assertEntityEmbedFilterHasRun($output); $this->assertContainsMultiple($contains, $output); $this->assertNotContainsMultiple($not_contains, $output); @@ -306,7 +307,6 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { 'contains' => [], 'not_contains' => [ 'filter->process($content, 'en'); $output = $filter_result->getProcessedText(); $this->assertContains($this->node->body->value, $output); - $this->assertNotContains('This placeholder should not be rendered.', $output); + $this->assertEntityEmbedFilterHasRun($output); } /** @@ -405,7 +405,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { $file_path = file_url_transform_relative(file_create_url($image->getFileUri())); $this->assertContains($file_path, $output); - $this->assertNotContains('This placeholder should not be rendered.', $output); + $this->assertEntityEmbedFilterHasRun($output); $dom = Html::load($output); $xpath = new \DOMXPath($dom); @@ -441,7 +441,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { /** @var \Drupal\filter\FilterProcessResult $filter_result */ $filter_result = $this->filter->process($content, 'en'); $output = $filter_result->getProcessedText(); - $this->assertNotContains('This placeholder should not be rendered.', $output); + $this->assertEntityEmbedFilterHasRun($output); $dom = Html::load($output); $xpath = new \DOMXPath($dom); @@ -552,7 +552,7 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { $filter_result = $this->filter->process($input, 'en'); $output = $filter_result->getProcessedText(); $this->assertNotContains('drupal-entity data-entity-type="media" data-entity', $output); - $this->assertNotContains('This placeholder should not be rendered.', $output); + $this->assertEntityEmbedFilterHasRun($output); $dom = Html::load($output); $xpath = new \DOMXPath($dom); @@ -669,25 +669,6 @@ class EntityEmbedFilterTest extends EntityEmbedFilterTestBase { } } - /** - * Get an embed code with given attributes. - * - * @param array $attributes - * The attributes to add. - * - * @return string - * A string containing a drupal-entity dom element. - */ - public function createEmbedCode(array $attributes) { - $dom = Html::load('This placeholder should not be rendered.'); - $xpath = new \DOMXPath($dom); - $drupal_entity = $xpath->query('//drupal-entity')[0]; - foreach ($attributes as $attribute => $value) { - $drupal_entity->setAttribute($attribute, $value); - } - return Html::serialize($dom); - } - /** * Retrieves a sample file of the specified type. */ diff --git a/tests/src/Kernel/EntityEmbedFilterTestBase.php b/tests/src/Kernel/EntityEmbedFilterTestBase.php index 9c87004..6e2d628 100644 --- a/tests/src/Kernel/EntityEmbedFilterTestBase.php +++ b/tests/src/Kernel/EntityEmbedFilterTestBase.php @@ -112,8 +112,10 @@ abstract class EntityEmbedFilterTestBase extends KernelTestBase { * * @return string * A string containing a drupal-entity dom element. + * + * @see assertEntityEmbedFilterHasRun() */ - public function createEmbedCode(array $attributes) { + protected function createEmbedCode(array $attributes) { $dom = Html::load('This placeholder should not be rendered.'); $xpath = new \DOMXPath($dom); $drupal_entity = $xpath->query('//drupal-entity')[0]; @@ -123,4 +125,16 @@ abstract class EntityEmbedFilterTestBase extends KernelTestBase { return Html::serialize($dom); } + /** + * Asserts that `@Filter=entity_embed` has been run successfully. + * + * @param string $output + * The string returned by the filtering process. + * + * @see \Drupal\Tests\entity_embed\Kernel\EntityEmbedFilterTestBase::createEmbedCode() + */ + protected function assertEntityEmbedFilterHasRun($output) { + $this->assertNotContains('This placeholder should not be rendered.', $output); + } + }