function TranslationsTest::testMediaLibraryTranslations

Same name in other branches
  1. 9 core/modules/media_library/tests/src/FunctionalJavascript/TranslationsTest.php \Drupal\Tests\media_library\FunctionalJavascript\TranslationsTest::testMediaLibraryTranslations()
  2. 8.9.x core/modules/media_library/tests/src/FunctionalJavascript/TranslationsTest.php \Drupal\Tests\media_library\FunctionalJavascript\TranslationsTest::testMediaLibraryTranslations()
  3. 10 core/modules/media_library/tests/src/FunctionalJavascript/TranslationsTest.php \Drupal\Tests\media_library\FunctionalJavascript\TranslationsTest::testMediaLibraryTranslations()

Tests the media library widget shows all media only once.

File

core/modules/media_library/tests/src/FunctionalJavascript/TranslationsTest.php, line 124

Class

TranslationsTest
Tests media library for translatable media.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

public function testMediaLibraryTranslations() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    // All translations should be shown in the administration overview,
    // regardless of the interface language.
    $this->drupalGet('nl/admin/content/media-grid');
    $assert_session->elementsCount('css', '.js-media-library-item', 6);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    $media_names = [];
    foreach ($media_items as $media_item) {
        $media_names[] = $media_item->getText();
    }
    sort($media_names);
    // cSpell:disable-next-line
    $this->assertSame([
        'Ardilla',
        'Eekhoorn',
        'Hert',
        'Tejón',
        'Vos',
        'Zorro',
    ], $media_names);
    $this->drupalGet('es/admin/content/media-grid');
    $assert_session->elementsCount('css', '.js-media-library-item', 6);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    $media_names = [];
    foreach ($media_items as $media_item) {
        $media_names[] = $media_item->getText();
    }
    sort($media_names);
    // cSpell:disable-next-line
    $this->assertSame([
        'Ardilla',
        'Eekhoorn',
        'Hert',
        'Tejón',
        'Vos',
        'Zorro',
    ], $media_names);
    // All media should only be shown once, and should be shown in the interface
    // language.
    $this->drupalGet('nl/node/add/article');
    $assert_session->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
        ->click();
    $assert_session->waitForText('Add or select media');
    $assert_session->elementsCount('css', '.js-media-library-item', 4);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    $media_names = [];
    foreach ($media_items as $media_item) {
        $media_names[] = $media_item->getText();
    }
    sort($media_names);
    // cSpell:disable-next-line
    $this->assertSame([
        'Eekhoorn',
        'Hert',
        'Tejón',
        'Vos',
    ], $media_names);
    $this->drupalGet('es/node/add/article');
    $assert_session->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
        ->click();
    $assert_session->waitForText('Add or select media');
    $assert_session->elementsCount('css', '.js-media-library-item', 4);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    $media_names = [];
    foreach ($media_items as $media_item) {
        $media_names[] = $media_item->getText();
    }
    sort($media_names);
    // cSpell:disable-next-line
    $this->assertSame([
        'Ardilla',
        'Hert',
        'Tejón',
        'Zorro',
    ], $media_names);
}

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