function MediaEntityMetadataApiTest::testApiTranslation

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php \Drupal\Tests\ckeditor5\Functional\MediaEntityMetadataApiTest::testApiTranslation()
  2. 10 core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php \Drupal\Tests\ckeditor5\Functional\MediaEntityMetadataApiTest::testApiTranslation()

Tests the media entity metadata API with translations.

File

core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php, line 284

Class

MediaEntityMetadataApiTest
Tests the media entity metadata API.

Namespace

Drupal\Tests\ckeditor5\Functional

Code

public function testApiTranslation() : void {
    $this->container
        ->get('module_installer')
        ->install([
        'language',
        'content_translation',
    ]);
    $this->resetAll();
    ConfigurableLanguage::createFromLangcode('fi')->save();
    $this->container
        ->get('config.factory')
        ->getEditable('language.negotiation')
        ->set('url.source', 'path_prefix')
        ->set('url.prefixes.fi', 'fi')
        ->save();
    $this->rebuildContainer();
    ContentLanguageSettings::loadByEntityTypeBundle('media', 'image')->setDefaultLangcode('en')
        ->setLanguageAlterable(TRUE)
        ->save();
    $media_fi = Media::load($this->mediaImage
        ->id())
        ->addTranslation('fi');
    $media_fi->field_media_image
        ->setValue([
        [
            'target_id' => '1',
            // cSpell:disable-next-line
'alt' => 'oletus alt-teksti kuvalle',
        ],
    ]);
    $media_fi->save();
    $uuid = $this->mediaImage
        ->uuid();
    $path = '/ckeditor5/filtered_html/media-entity-metadata';
    $token = $this->container
        ->get('csrf_token')
        ->get(ltrim($path, '/'));
    // Ensure that translation is returned when language is specified.
    $this->drupalGet($path, [
        'query' => [
            'uuid' => $uuid,
            'token' => $token,
        ],
        'language' => $media_fi->language(),
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    // cSpell:disable-next-line
    $this->assertSame(json_encode([
        'type' => 'image',
        'imageSourceMetadata' => [
            'alt' => 'oletus alt-teksti kuvalle',
        ],
    ]), $this->getSession()
        ->getPage()
        ->getContent());
    // Ensure that default translation is returned when no language is
    // specified.
    $this->drupalGet($path, [
        'query' => [
            'uuid' => $uuid,
            'token' => $token,
        ],
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSame(json_encode([
        'type' => 'image',
        'imageSourceMetadata' => [
            'alt' => 'default alt',
        ],
    ]), $this->getSession()
        ->getPage()
        ->getContent());
}

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