tests/src/Functional/EntityEmbedFilterTest.php | 44 ++++++++++++-------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/tests/src/Functional/EntityEmbedFilterTest.php b/tests/src/Functional/EntityEmbedFilterTest.php index 99f709d..0d2ac38 100644 --- a/tests/src/Functional/EntityEmbedFilterTest.php +++ b/tests/src/Functional/EntityEmbedFilterTest.php @@ -232,61 +232,59 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { $this->assertTrue(strpos($placeholder->getAttribute('src'), 'core/modules/media/images/icons/no-thumbnail.png') > 0); } + /** + * Tests the filter in different translation contexts. + */ public function testTranslation() { $content = 'This placeholder should not be rendered.'; ConfigurableLanguage::createFromLangcode('pt-br')->save(); - $node = $this->drupalCreateNode([ + $host_entity = $this->drupalCreateNode([ 'type' => 'page', 'body' => [ 'value' => $content, 'format' => 'custom_format', ], ]); - $this->drupalGet($node->toUrl()); + $this->drupalGet($host_entity->toUrl()); $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->pageTextContains($node->getTitle()); + $this->assertSession()->pageTextContains($host_entity->getTitle()); $this->assertSession()->pageTextContains($this->node->getTitle()); - // Add a translation. - $translation = $node->addTranslation('pt-br') + // Translate the host entity, but keep the same body; only change the title. + $translated_host_entity = $host_entity->addTranslation('pt-br') ->getTranslation('pt-br') ->setTitle('Em portugues') - ->set('body', $node->get('body')->getValue()); - $translation->save(); -// $url = $translation->toUrl('canonical', [ -// 'language' => $translation->language(), -// ]); - // @todo This is a cheat. Figure out how to honestly generate the URL of - // the translation. - $this->drupalGet('/pt-br/node/' . $node->id()); + ->set('body', $host_entity->get('body')->getValue()); + $translated_host_entity->save(); + $this->drupalGet('/pt-br/node/' . $host_entity->id()); $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->pageTextContains($translation->getTitle()); + $this->assertSession()->pageTextContains($translated_host_entity->getTitle()); // The embedded node does not have a Portuguese translation, so it should // display in English. $this->assertSession()->pageTextContains($this->node->getTitle()); - // Reload the embedded node so we can create a translation of it. + // Translate the embedded entity to the same language as the host entity. $this->node = Node::load($this->node->id()); $this->node->addTranslation('pt-br') ->getTranslation('pt-br') ->setTitle('Embed em portugues') ->save(); - $this->getSession()->reload(); $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->pageTextContains($translation->getTitle()); - // Now that the embedded node is translated into Portuguese, it should be - // displayed in Portuguese. + $this->assertSession()->pageTextContains($translated_host_entity->getTitle()); + // The translated host entity now should show the matching translation of + // the embedded entity. $this->assertSession()->pageTextContains($this->node->getTranslation('pt-br')->getTitle()); - $translation->body->value = 'This placeholder should not be rendered.'; - $translation->save(); + // Change the translated host entity to explicitly embed the untranslated + // entity. + $translated_host_entity->body->value = 'This placeholder should not be rendered.'; + $translated_host_entity->save(); $this->getSession()->reload(); $this->assertSession()->statusCodeEquals(200); - $this->assertSession()->pageTextContains($translation->getTitle()); + $this->assertSession()->pageTextContains($translated_host_entity->getTitle()); $this->assertSession()->pageTextContains($this->node->getTitle()); - } }