function MediaEmbedFilterTranslationTest::testTranslationSelection

Same name in other branches
  1. 9 core/modules/media/tests/src/Kernel/MediaEmbedFilterTranslationTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTranslationTest::testTranslationSelection()
  2. 8.9.x core/modules/media/tests/src/Kernel/MediaEmbedFilterTranslationTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTranslationTest::testTranslationSelection()
  3. 10 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 49

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) : void {
    $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',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.