You are here

public function EntityEmbedFilterTranslationTest::testTranslationSelection in Entity Embed 8

Tests that the expected embedded entity translation is selected.

@dataProvider providerTranslationSituations

File

tests/src/Kernel/EntityEmbedFilterTranslationTest.php, line 44

Class

EntityEmbedFilterTranslationTest
Tests that entity embeds are translated based on host and `data-langcode`.

Namespace

Drupal\Tests\entity_embed\Kernel

Code

public function testTranslationSelection($text_langcode, array $additional_attributes, $expected_title_langcode) {
  $text = $this
    ->createEmbedCode([
    'data-entity-type' => 'node',
    'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
    'data-view-mode' => 'teaser',
    'data-entity-embed-display' => 'entity_reference:entity_reference_label',
    'data-entity-embed-settings' => '{"link":"0"}',
  ] + $additional_attributes);
  $result = $this
    ->processText($text, $text_langcode, [
    'entity_embed',
  ]);
  $this
    ->setRawContent($result
    ->getProcessedText());
  $this
    ->assertSame($this->embeddedEntity
    ->getTranslation($expected_title_langcode)
    ->label(), (string) $this
    ->cssSelect('div.embedded-entity')[0]);

  // Verify that the filtered text does not vary by translation-related cache
  // contexts: a particular translation of the embedded entity is selected
  // based on either the `data-langcode` attribute or the host entity's
  // language, neither of which should require a cache context to be
  // associated. (The host entity's language may itself be selected based on
  // some request context, but that is of no concern to this filter.)
  $this
    ->assertSame($result
    ->getCacheContexts(), [
    'user.permissions',
  ]);
}