You are here

public function TranslationsTest::testMediaLibraryTranslations in Drupal 9

Same name and namespace in other branches
  1. 8 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 122

Class

TranslationsTest
Tests media library for translatable media.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

public function testMediaLibraryTranslations() {
  $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', '.media-library-item__name');
  $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', '.media-library-item__name');
  $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', '.media-library-item__name');
  $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', '.media-library-item__name');
  $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);
}