You are here

public function JSTranslationTest::test in Drupal 10

Integration test to ensure that CKEditor 5 Plugins translations are loaded.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/JSTranslationTest.php, line 42

Class

JSTranslationTest
Tests for CKEditor 5 plugins using Drupal's translation system.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function test() : void {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->createNewTextFormat($page, $assert_session);
  $this
    ->assertNotEmpty($assert_session
    ->waitForElement('css', '.ckeditor5-toolbar-item-drupalMedia'));
  $this
    ->click('#edit-filters-media-embed-status');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->triggerKeyUp('.ckeditor5-toolbar-item-drupalMedia', 'ArrowDown');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->saveNewTextFormat($page, $assert_session);
  $langcode = 'fr';
  ConfigurableLanguage::createFromLangcode($langcode)
    ->save();
  $this
    ->config('system.site')
    ->set('default_langcode', $langcode)
    ->save();

  // Visit a page that will trigger a JavaScript file parsing for
  // translatable strings.
  $this
    ->drupalGet('node/add');
  $this
    ->assertNotEmpty($assert_session
    ->waitForElement('css', '.ck-editor'));

  // Ensure a string from the CKEditor 5 plugin is picked up by translation.
  // @see core/modules/ckeditor5/js/ckeditor5_plugins/drupalMedia/src/drupalmediatoolbar.js
  $locale_storage = $this->container
    ->get('locale.storage');
  $string = $locale_storage
    ->findString([
    'source' => 'Drupal Media toolbar',
    'context' => '',
  ]);
  $this
    ->assertNotEmpty($string, 'String from JavaScript file saved.');
}