function CKEditorLoadingTest::testLoadingWithoutInternalButtons

Same name in other branches
  1. 8.9.x core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php \Drupal\Tests\ckeditor\Functional\CKEditorLoadingTest::testLoadingWithoutInternalButtons()

Tests presence of essential configuration even without Internal's buttons.

File

core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php, line 187

Class

CKEditorLoadingTest
Tests loading of CKEditor.

Namespace

Drupal\Tests\ckeditor\Functional

Code

public function testLoadingWithoutInternalButtons() {
    // Change the CKEditor text editor configuration to only have link buttons.
    // This means:
    // - 0 buttons are from \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal
    // - 2 buttons are from \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink
    $filtered_html_editor = Editor::load('filtered_html');
    $settings = $filtered_html_editor->getSettings();
    $settings['toolbar']['rows'] = [
        0 => [
            0 => [
                'name' => 'Links',
                'items' => [
                    'DrupalLink',
                    'DrupalUnlink',
                ],
            ],
        ],
    ];
    $filtered_html_editor->setSettings($settings)
        ->save();
    // Even when no buttons of \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal
    // are in use, its configuration (Internal::getConfig()) is still essential:
    // this is configuration that is associated with the (custom, optimized)
    // build of CKEditor that Drupal core ships with. For example, it configures
    // CKEditor to not perform its default action of loading a config.js file,
    // to not convert special characters into HTML entities, and the allowedContent
    // setting to configure CKEditor's Advanced Content Filter.
    $this->drupalLogin($this->normalUser);
    $this->drupalGet('node/add/article');
    $editor_settings = $this->getDrupalSettings()['editor']['formats']['filtered_html']['editorSettings'];
    $this->assertTrue(isset($editor_settings['customConfig']));
    $this->assertTrue(isset($editor_settings['entities']));
    $this->assertTrue(isset($editor_settings['allowedContent']));
    $this->assertTrue(isset($editor_settings['disallowedContent']));
}

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