function JSTranslationTest::test

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/JSTranslationTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\JSTranslationTest::test()
  2. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/JSTranslationTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\JSTranslationTest::test()

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->assertExpectedAjaxRequest(2);
    $this->triggerKeyUp('.ckeditor5-toolbar-item-drupalMedia', 'ArrowDown');
    $assert_session->assertExpectedAjaxRequest(3);
    $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.');
}

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