.../Kernel/EntityEmbedFilterTranslationTest.php | 53 +++++++++++++--------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/src/Kernel/EntityEmbedFilterTranslationTest.php b/tests/src/Kernel/EntityEmbedFilterTranslationTest.php index 7562ddf..7d55fb2 100644 --- a/tests/src/Kernel/EntityEmbedFilterTranslationTest.php +++ b/tests/src/Kernel/EntityEmbedFilterTranslationTest.php @@ -69,14 +69,14 @@ class EntityEmbedFilterTranslationTest extends EntityEmbedFilterTestBase { * * @dataProvider providerTestFilterTranslations */ - public function testFilterTranslations($data_langcode_attribute, $expected_title_langcode) { - $content = $this->createEmbedCode( [ + public function testFilterTranslations($text_langcode, $data_langcode, $expected_title_langcode) { + $text = $this->createEmbedCode( [ 'data-entity-type' => 'node', 'data-entity-uuid' => 'e7a3e1fe-b69b-417e-8ee4-c80cb7640e63', 'data-view-mode' => 'teaser', 'data-entity-embed-display' => 'entity_reference:entity_reference_label', 'data-entity-embed-settings' => '{"link":"0"}', - 'data-langcode' => $data_langcode_attribute, + 'data-langcode' => $data_langcode, ]); // Translate the embedded entity to the same language as the context (i.e. @@ -85,9 +85,7 @@ class EntityEmbedFilterTranslationTest extends EntityEmbedFilterTestBase { ->setTitle('Embed em portugues') ->save(); - // The embedded entity's language is explicitly specified and therefore does - // not depend on the context. Prove by specifying a non-existent language. - $this->applyFilter($content, $this->randomMachineName()); + $this->applyFilter($text, $text_langcode); $this->assertRaw($this->node->getTranslation($expected_title_langcode)->getTitle()); } @@ -95,24 +93,35 @@ class EntityEmbedFilterTranslationTest extends EntityEmbedFilterTestBase { * Data provider for testFilterTranslations. */ public function providerTestFilterTranslations() { - return [ - 'Change the translated context to explicitly embed the untranslated entity' => [ - 'data-langcode' => 'en', - 'en', - ], - 'Change the untranslated context to explicitly embed the Portugues translation of the embedded entity.' => [ - 'data-langcode' => 'pt-br', - 'pt-br', - ], - 'Change the translated context to explicitly embed a non-existing translation, en' => [ - 'data-langcode' => 'nl', + foreach (['en', 'pt-br', 'nl'] as $text_langcode) { + // When the embedded entity has a translation for the language code in the + // `data-langcode` attribute, that translation is used, regardless of the + // language of the text (which is set to the language of the host entity). + foreach (['en', 'pt-br'] as $data_langcode) { + yield "text_langcode=$text_langcode (✅); data-langcode=$data_langcode (✅) ⇒ $data_langcode" => [ + $text_langcode, + $data_langcode, + $data_langcode, + ]; + } + + // When specifying a (valid) language code but the embedded entity has no + // translation for that language, it falls back to the default translation + // of the embedded entity. + yield "text_langcode=$text_langcode (✅); data-langcode=nl (🚫) ⇒ en" => [ + $text_langcode, + 'nl', 'en', - ], - 'Change the translated context to explicitly embed a non-existing translation, pt-br' => [ - 'data-langcode' => 'nl', + ]; + + // When specifying a invalid language code, it falls back to the default + // translation of the embedded entity. + yield "text_langcode=$text_langcode (✅); data-langcode=non-existing-and-even-invalid-langcode (🚫) ⇒ en" => [ + 'text_langcode' => $text_langcode, + 'data-langcode' => 'non-existing-and-even-invalid-langcode', 'en', - ], - ]; + ]; + } } }