diff --git a/tests/src/Functional/EntityEmbedFilterTest.php b/tests/src/Functional/EntityEmbedFilterTest.php index 21f202c..fbdd1d8 100644 --- a/tests/src/Functional/EntityEmbedFilterTest.php +++ b/tests/src/Functional/EntityEmbedFilterTest.php @@ -3,6 +3,8 @@ namespace Drupal\Tests\entity_embed\Functional; use Drupal\Component\Utility\Html; +use Drupal\Core\Entity\TranslatableInterface; +use Drupal\Core\Render\RenderContext; use Drupal\file\Entity\File; use Drupal\filter\FilterPluginCollection; use Drupal\media\Entity\Media; @@ -300,7 +302,7 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { * * @dataProvider providerTestInvalidEntity */ - public function testInvalidEntity(array $embed_attributes, $contains, $not_contains) { + public function testInvalidEntity(array $embed_attributes, array $contains, array $not_contains) { $content = $this->createEmbedCode($embed_attributes); /** @var \Drupal\filter\FilterProcessResult $filter_result */ @@ -324,7 +326,7 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { 'data-entity-id' => 'InvalidID', 'data-view-mode' => 'teaser', ], - 'contains' => NULL, + 'contains' => [], 'not_contains' => [ '. + * Test if tag of container element remains when not . */ public function testContainerTagElementReplace() { $content = $this->createEmbedCode([ @@ -376,14 +377,14 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { * Data provider for testFigCaption. */ public function providerTestFigCaption() { - return [ - - ]; + return []; } /** - * Ensure that Entity Embed Display plugin is preferred over view mode when - * both attributes are present. + * Ensure that Entity Embed Display plugin is preferred over view mode. + * + * When both Embed Display plugin and view mode attributes are present. + * Ensure our Embed Display plugin is preferred. */ public function testDisplayPluginPreference() { $content = $this->createEmbedCode([ @@ -471,6 +472,8 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { } /** + * Test embed-settings legacy naming. + * * Data-entity-embed-settings has been replaced with * data-entity-embed-display-settings. * Check to see if data-entity-embed-settings is still working. @@ -637,4 +640,67 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { ]); } + /** + * Loads an entity (in the appropriate translation) given HTML attributes. + * + * @param string[] $attributes + * An array of HTML attributes, including at least `data-entity-type` and + * `data-entity-uuid`, and optionally `data-langcode`. + * + * @return \Drupal\Core\Entity\EntityInterface|null + * The requested entity, or NULL. + */ + public function loadEntityByAttributes(array $attributes) { + if (!empty($attributes['data-entity-uuid'])) { + $entity = $this->container->get('entity_type.manager') + ->getStorage($attributes['data-entity-type']) + ->loadByProperties(['uuid' => $attributes['data-entity-uuid']]); + $entity = current($entity); + } + elseif (!empty($attributes['data-entity-id'])) { + $entity = $this->container->get('entity_type.manager') + ->getStorage($attributes['data-entity-type']) + ->load($attributes['data-entity-id']); + } + if ($entity && $entity instanceof TranslatableInterface && !empty($attributes['data-langcode'])) { + if ($entity->hasTranslation($attributes['data-langcode'])) { + $entity = $entity->getTranslation($attributes['data-langcode']); + } + } + + return $entity; + } + + /** + * Assert that the DOMNode object has the given attributes. + * + * @param \DOMNode $node + * The DOMNode object to check. + * @param array $attributes + * An array of attributes. + */ + public function assertHasAttributes(\DOMNode $node, array $attributes) { + foreach ($attributes as $attribute => $value) { + $this->assertEquals($value, $node->getAttribute($attribute)); + } + } + + /** + * Process text containing html for elements containing data-caption. + * + * @param string $input + * String containing HTML. + * @param string $langcode + * The langcode to use. + * + * @return \Drupal\filter\FilterProcessResult + * The processed text with caption. + */ + public function processFilterCaption($input, $langcode = 'en') { + $filter = $this->filterCaption; + return $this->renderer->executeInRenderContext(new RenderContext(), function () use ($input, $filter, $langcode) { + return $filter->process($input, $langcode); + }); + } + } diff --git a/tests/src/Functional/EntityEmbedFilterTranslationTest.php b/tests/src/Functional/EntityEmbedFilterTranslationTest.php index 1c58242..eca87f4 100644 --- a/tests/src/Functional/EntityEmbedFilterTranslationTest.php +++ b/tests/src/Functional/EntityEmbedFilterTranslationTest.php @@ -2,11 +2,8 @@ namespace Drupal\Tests\entity_embed\Functional; -use Drupal\Component\Utility\Html; -use Drupal\file\Entity\File; use Drupal\filter\FilterPluginCollection; use Drupal\language\Entity\ConfigurableLanguage; -use Drupal\media\Entity\Media; use Drupal\node\Entity\Node; /** @@ -21,8 +18,6 @@ class EntityEmbedFilterTranslationTest extends EntityEmbedTestBase { */ protected static $modules = [ 'content_translation', - 'file', - 'image', 'entity_embed', 'entity_embed_test', 'node', diff --git a/tests/src/Functional/EntityEmbedTestBase.php b/tests/src/Functional/EntityEmbedTestBase.php index ba1559d..9ff9d5a 100644 --- a/tests/src/Functional/EntityEmbedTestBase.php +++ b/tests/src/Functional/EntityEmbedTestBase.php @@ -132,24 +132,6 @@ abstract class EntityEmbedTestBase extends BrowserTestBase { $this->assertEquals([], array_diff($expected_plugins, array_keys($plugin_options)), $message); } - /** - * Process text containing html for elements containing data-caption. - * - * @param string $input - * String containing HTML. - * @param string $langcode - * The langcode to use. - * - * @return \Drupal\filter\FilterProcessResult - * The processed text with caption. - */ - public function processFilterCaption($input, $langcode = 'en') { - $filter = $this->filterCaption; - return $this->renderer->executeInRenderContext(new RenderContext(), function () use ($input, $filter, $langcode) { - return $filter->process($input, $langcode); - }); - } - /** * Get an embed code with given attributes. * @@ -169,50 +151,4 @@ abstract class EntityEmbedTestBase extends BrowserTestBase { return Html::serialize($dom); } - /** - * Assert that the DOMNode object has the given attributes. - * - * @param \DOMNode $node - * The DOMNode object to check. - * @param array $attributes - * An array of attributes. - */ - public function assertHasAttributes(\DOMNode $node, array $attributes) { - foreach ($attributes as $attribute => $value) { - $this->assertEquals($value, $node->getAttribute($attribute)); - } - } - - /** - * Loads an entity (in the appropriate translation) given HTML attributes. - * - * @param string[] $attributes - * An array of HTML attributes, including at least `data-entity-type` and - * `data-entity-uuid`, and optionally `data-langcode`. - * - * @return \Drupal\Core\Entity\EntityInterface|null - * The requested entity, or NULL. - */ - public function loadEntityByAttributes(array $attributes) { - if (!empty($attributes['data-entity-uuid'])) { - $entity = $this->container->get('entity_type.manager') - ->getStorage($attributes['data-entity-type']) - ->loadByProperties(['uuid' => $attributes['data-entity-uuid']]); - $entity = current($entity); - } - elseif (!empty($attributes['data-entity-id'])) { - $entity = $this->container->get('entity_type.manager') - ->getStorage($attributes['data-entity-type']) - ->load($attributes['data-entity-id']); - } - if ($entity && $entity instanceof TranslatableInterface && !empty($attributes['data-langcode'])) { - if ($entity->hasTranslation($attributes['data-langcode'])) { - $entity = $entity->getTranslation($attributes['data-langcode']); - } - } - - return $entity; - } - - }