Given a translated node is embedded inside another translated node, double check that the embedded node is displayed with the same language as the parent node. Also double check that tweaking the data-langcode attribute modifies the embed as well.

Comments

Dave Reid created an issue. See original summary.

dave reid’s picture

Issue summary: View changes
dave reid’s picture

wim leers’s picture

Title: Add tests to ensure translated content works as expected » [PP-1] Add tests to ensure translated content works as expected
Status: Active » Postponed
Related issues: +#2328659: Convert all existing entity_embed tests from WebTestBase to BrowserTestBase
wim leers’s picture

Title: [PP-1] Add tests to ensure translated content works as expected » Add tests to ensure translated content works as expected
Status: Postponed » Active
phenaproxima’s picture

Status: Active » Needs review
StatusFileSize
new3.64 KB

Here's a basic, albeit sloppy, test. There is still a lot of clean-up needed, and I'd love to know what edge cases need to be covered as well.

wim leers’s picture

Issue tags: +D8MI

Yay, thanks for getting this started! Will review tomorrow.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +D8 cacheability, +Security improvements
StatusFileSize
new4.9 KB
new3.92 KB

Basically only nits!

  1. +++ b/tests/src/Functional/EntityEmbedFilterTest.php
    @@ -195,4 +199,61 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    $node = $this->drupalCreateNode([
    

    s/$node/$host_entity/

  2. +++ b/tests/src/Functional/EntityEmbedFilterTest.php
    @@ -195,4 +199,61 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    $translation = $node->addTranslation('pt-br')
    

    s/$translation/$host_entity_translation/

  3. +++ b/tests/src/Functional/EntityEmbedFilterTest.php
    @@ -195,4 +199,61 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +//    $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());
    

    This is a test. Tests should be as simple and readable as possible. Using APIs to compute the URL is the wrong thing to do here. Hardcoding the expected URL is perfectly appropriate.

    So we can remove the 3 commented lines and the todo.

  4. +++ b/tests/src/Functional/EntityEmbedFilterTest.php
    @@ -195,4 +199,61 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    // The embedded node does not have a Portuguese translation, so it should
    +    // display in English.
    +    $this->assertSession()->pageTextContains($this->node->getTitle());
    

    👍

  5. +++ b/tests/src/Functional/EntityEmbedFilterTest.php
    @@ -195,4 +199,61 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    // Now that the embedded node is translated into Portuguese, it should be
    +    // displayed in Portuguese.
    +    $this->assertSession()->pageTextContains($this->node->getTranslation('pt-br')->getTitle());
    

    This also proves that no explicit cache invalidation was necessary; thereby confirming that Entity Embed already is bubbling the appropriate cacheability! 🎉

  6. +++ b/tests/src/Functional/EntityEmbedFilterTest.php
    @@ -195,4 +199,61 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    $translation->body->value = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid() . '" data-entity-embed-display="entity_reference:entity_reference_label" data-entity-embed-settings=\'{"link":"0"}\' data-align="left" data-caption="test caption" data-langcode="' . $node->language()->getId() . '">This placeholder should not be rendered.</drupal-entity>';
    

    This is missing a comment. Something like:
    // Now make the Portuguese translation of the host entity use the data-langcode attribute to refer to a specific translation of the embedded entity.

Nits addressed.

phenaproxima’s picture

+1 on the cleanup. Thanks!

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

wim leers’s picture