MediaEmbedFilterTranslationTest.php in Drupal 8
File
core/modules/media/tests/src/Kernel/MediaEmbedFilterTranslationTest.php
View source
<?php
namespace Drupal\Tests\media\Kernel;
use Drupal\language\Entity\ConfigurableLanguage;
class MediaEmbedFilterTranslationTest extends MediaEmbedFilterTestBase {
protected static $modules = [
'language',
];
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('pt-br')
->save();
$this->embeddedEntity = $this->container
->get('entity_type.manager')
->getStorage('media')
->load($this->embeddedEntity
->id());
$this->embeddedEntity
->addTranslation('pt-br')
->set('field_media_image', [
'target_id' => $this->image
->id(),
'alt' => 'pt-br alt',
'title' => 'pt-br title',
])
->save();
}
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']);
$this
->assertSame($result
->getCacheContexts(), [
'timezone',
'user.permissions',
]);
}
public function providerTranslationSituations() {
$embedded_entity_translation_languages = [
'en',
'pt-br',
];
foreach ([
'en',
'pt-br',
'nl',
] as $text_langcode) {
$match_or_fallback_langcode = in_array($text_langcode, $embedded_entity_translation_languages) ? $text_langcode : 'en';
(yield "text_langcode={$text_langcode} ⇒ {$match_or_fallback_langcode}" => [
$text_langcode,
$match_or_fallback_langcode,
]);
}
}
}