You are here

public function MediaEmbedFilterTranslationTest::testTranslationSelection in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Kernel/MediaEmbedFilterTranslationTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTranslationTest::testTranslationSelection()

Tests that the expected embedded media entity translation is selected.

@dataProvider providerTranslationSituations

File

core/modules/media/tests/src/Kernel/MediaEmbedFilterTranslationTest.php, line 47

Class

MediaEmbedFilterTranslationTest
Tests that media embeds are translated based on text (host entity) language.

Namespace

Drupal\Tests\media\Kernel

Code

public function testTranslationSelection($text_langcode, $expected_title_langcode) {
  $text = $this
    ->createEmbedCode([
    'data-entity-type' => 'media',
    'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
  ]);
  $result = $this
    ->processText($text, $text_langcode, [
    'media_embed',
  ]);
  $this
    ->setRawContent($result
    ->getProcessedText());
  $this
    ->assertSame($this->embeddedEntity
    ->getTranslation($expected_title_langcode)->field_media_image->alt, (string) $this
    ->cssSelect('img')[0]
    ->attributes()['alt']);

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