You are here

class CKEditorStylesComboTranslationTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php \Drupal\Tests\ckeditor\Functional\CKEditorStylesComboTranslationTest
  2. 9 core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php \Drupal\Tests\ckeditor\Functional\CKEditorStylesComboTranslationTest

Tests administration of the CKEditor StylesCombo plugin.

@group ckeditor

Hierarchy

Expanded class hierarchy of CKEditorStylesComboTranslationTest

File

core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php, line 15

Namespace

Drupal\Tests\ckeditor\Functional
View source
class CKEditorStylesComboTranslationTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'ckeditor',
    'config_translation',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * A user with the 'administer filters' permission.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

  /**
   * A randomly generated format machine name.
   *
   * @var string
   */
  protected $format;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->format = strtolower($this
      ->randomMachineName());
    $filter_format = FilterFormat::create([
      'format' => $this->format,
      'name' => $this
        ->randomString(),
      'filters' => [],
    ]);
    $filter_format
      ->save();
    $ckeditor = $this->container
      ->get('plugin.manager.editor')
      ->createInstance('ckeditor');
    $settings = $ckeditor
      ->getDefaultSettings();
    $settings['toolbar']['rows'][0][] = [
      'name' => 'Styles dropdown',
      'items' => [
        'Styles',
      ],
    ];
    $editor = Editor::create([
      'format' => $this->format,
      'editor' => 'ckeditor',
      'settings' => $settings,
    ]);
    $editor
      ->save();
    $this->adminUser = $this
      ->drupalCreateUser([
      'administer filters',
      'translate configuration',
    ]);
    ConfigurableLanguage::createFromLangcode('de')
      ->save();
  }

  /**
   * Tests translations of CKEditor styles configuration.
   */
  public function testExistingFormat() {
    $this
      ->drupalLogin($this->adminUser);
    $edit = [
      'editor[settings][plugins][stylescombo][styles]' => 'h1.title|Title',
    ];
    $this
      ->drupalGet('admin/config/content/formats/manage/' . $this->format);
    $this
      ->submitForm($edit, 'Save configuration');
    $this
      ->drupalGet('admin/config/content/formats/manage/' . $this->format . '/translate/de/add');
    $this
      ->assertEquals('textarea', $this
      ->assertSession()
      ->fieldExists('List of styles')
      ->getTagName());
    $this
      ->assertSession()
      ->fieldValueEquals('List of styles', 'h1.title|Title');
    $page = $this
      ->getSession()
      ->getPage();
    $page
      ->fillField('List of styles', 'h1.title|Titel');
    $page
      ->pressButton('Save translation');
    $this
      ->assertSession()
      ->pageTextContains('Successfully saved German translation.');
  }

}

Members