View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\ckeditor5\FunctionalJavascript;
use Drupal\language\Entity\ConfigurableLanguage;
class LanguageTest extends CKEditor5TestBase {
protected static $modules = [
'language',
'locale',
];
public function test(string $langcode, string $toolbar_item_name, string $toolbar_item_translation) : void {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->createNewTextFormat($page, $assert_session);
if ($toolbar_item_name === 'textPartLanguage') {
$this
->assertNotEmpty($assert_session
->waitForElement('css', '.ckeditor5-toolbar-item-sourceEditing'));
$this
->triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown');
$assert_session
->assertWaitOnAjaxRequest();
$page
->clickLink('Source editing');
$this
->assertNotNull($assert_session
->waitForElementVisible('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting-allowed-tags"]'));
$javascript = <<<JS
const allowedTags = document.querySelector('[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting-allowed-tags"]');
allowedTags.value = '<span>';
allowedTags.dispatchEvent(new Event('input'));
JS;
$this
->getSession()
->executeScript($javascript);
}
$this
->assertNotEmpty($assert_session
->waitForElement('css', ".ckeditor5-toolbar-item-{$toolbar_item_name}"));
$this
->triggerKeyUp(".ckeditor5-toolbar-item-{$toolbar_item_name}", 'ArrowDown');
$assert_session
->assertWaitOnAjaxRequest();
$this
->saveNewTextFormat($page, $assert_session);
ConfigurableLanguage::createFromLangcode($langcode)
->save();
$this
->config('system.site')
->set('default_langcode', $langcode)
->save();
$this
->drupalGet('node/add');
$this
->assertNotEmpty($assert_session
->waitForElement('css', '.ck-editor'));
$assert_session
->elementExists('xpath', "//span[text()='{$toolbar_item_translation}']");
}
public function provider() : array {
return [
'Language code both in Drupal and CKEditor' => [
'langcode' => 'th',
'toolbar_item_name' => 'blockQuote',
'toolbar_item_translation' => 'คำพูดบล็อก',
],
'Language code transformed from browser mappings' => [
'langcode' => 'zh-hans',
'toolbar_item_name' => 'blockQuote',
'toolbar_item_translation' => '块引用',
],
'Language configuration conflict' => [
'langcode' => 'fr',
'toolbar_item_name' => 'textPartLanguage',
'toolbar_item_translation' => 'Choisir la langue',
],
];
}
}