Unverified Commit 4d02e19f authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3231328 by Wim Leers, nod_: SmartDefaultSettings should select the CKE5...

Issue #3231328 by Wim Leers, nod_: SmartDefaultSettings should select the CKE5 plugin that minimizes creation of HTML restriction supersets
parent 0b783bfc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -357,6 +357,9 @@ public static function fromString(string $elements_string): HTMLRestrictions {
    // Omit the broad wildcard addition that FilterHtml::getHTMLRestrictions()
    // always sets; it is specific to how FilterHTML works and irrelevant here.
    unset($allowed_elements['*']);
    // @see \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()
    // @todo remove this in https://www.drupal.org/project/drupal/issues/3226368
    unset($allowed_elements['__zqh6vxfbk3cg__']);

    // Postprocess tag wildcards: convert `<__preprocessed-wildcard-block__>` to
    // `<$block>`.
+307 −115

File changed.

Preview size limit exceeded, changes collapsed.

+13 −0
Original line number Diff line number Diff line
@@ -12,3 +12,16 @@ ckeditor5_plugin_conditions_test_plugins_condition:
        - ckeditor5_table
    elements:
      - <foo>

# @todo remove in https://www.drupal.org/project/drupal/issues/3263384
ckeditor5_plugin_conditions_test_codeBlock_until_3263384_lands:
  ckeditor5:
    plugins: []
  drupal:
    label: TEST until #3263384 lands
    toolbar_items:
      codeBlockPlaceholder:
        label: TODO
    elements:
      - <pre>
      - <code class="lang-*">
+50 −18
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ class SmartDefaultSettingsTest extends KernelTestBase {
    'media',
    'media_library',
    'views',
    // @todo Remove in https://www.drupal.org/project/drupal/issues/3263384
    'ckeditor5_plugin_conditions_test',
  ];

  /**
@@ -113,6 +115,17 @@ protected function setUp(): void {
      Yaml::parseFile('core/profiles/standard/config/install/editor.editor.basic_html.yml')
    )->save();

    $basic_html_format_with_pre = $basic_html_format;
    $basic_html_format_with_pre['name'] .= ' (with <pre>)';
    $basic_html_format_with_pre['format'] = 'basic_html_with_pre';
    NestedArray::setValue($basic_html_format_with_pre, $allowed_html_parents, $current_value . ' <pre>');
    FilterFormat::create($basic_html_format_with_pre)->save();
    Editor::create(
      ['format' => 'basic_html_with_pre']
      +
      Yaml::parseFile('core/profiles/standard/config/install/editor.editor.basic_html.yml')
    )->save();

    $new_value = str_replace('<p>', '<p class="text-align-center text-align-justify">', $current_value);
    $basic_html_format_with_alignable_p = $basic_html_format;
    $basic_html_format_with_alignable_p['name'] .= ' (with alignable paragraph support)';
@@ -548,16 +561,39 @@ public function provider() {
      ),
    ];

    yield "basic_html_with_pre can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [
      'format_id' => 'basic_html_with_pre',
      'filters_to_drop' => $basic_html_test_case['filters_to_drop'],
      'expected_ckeditor5_settings' => [
        'toolbar' => [
          'items' => array_merge(
            $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'],
            ['codeBlockPlaceholder'],
          ),
        ],
        'plugins' => $basic_html_test_case['expected_ckeditor5_settings']['plugins'],
      ],
      'expected_superset' => '<code class="lang-*"> ' . $basic_html_test_case['expected_superset'],
      'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
      'expected_messages' => [
        'The following plugins were enabled to support tags that are allowed by this text format: <em class="placeholder">Code (for tags: &lt;code&gt;) Language (for tags: &lt;span&gt;) TEST until (for tags: &lt;pre&gt;)</em>.',
        $basic_html_test_case['expected_messages'][1],
        'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: &lt;a hreflang&gt; &lt;blockquote cite&gt; &lt;ul type&gt; &lt;ol start type&gt; &lt;h2 id&gt; &lt;h3 id&gt; &lt;h4 id&gt; &lt;h5 id&gt; &lt;h6 id&gt;.',
      ],
    ];

    yield "basic_html_with_alignable_p can be switched to CKEditor 5 without problems, align buttons added automatically" => [
      'format_id' => 'basic_html_with_alignable_p',
      'filters_to_drop' => $basic_html_test_case['filters_to_drop'],
      'expected_ckeditor5_settings' => [
        'toolbar' => [
          'items' => array_merge(
            $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'],
            array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, -1),
            [
              'alignment',
            ]
              'alignment:center',
              'alignment:justify',
            ],
            array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], -1)
          ),
        ],
        'plugins' => $basic_html_test_case['expected_ckeditor5_settings']['plugins'],
@@ -565,31 +601,27 @@ public function provider() {
      'expected_superset' => implode(' ', [
        // Note that aligning left and right is being added, on top of what the
        // original format allowed: center and justify.
        // @todo Improve in https://www.drupal.org/project/drupal/issues/3231328
        '<p class="text-align-left text-align-right">',
        // Note that aligning left/center/right/justify is possible on *all*
        // allowed block-level HTML5 tags.
        // @todo When https://www.drupal.org/project/ckeditor5/issues/3231328
        //   lands, only the center/justify classes will be added.
        // @todo When https://www.drupal.org/project/drupal/issues/3259367
        //   lands, none of the tags below should appear.
        '<h2 class="text-align-left text-align-center text-align-right text-align-justify">',
        '<h3 class="text-align-left text-align-center text-align-right text-align-justify">',
        '<h4 class="text-align-left text-align-center text-align-right text-align-justify">',
        '<h5 class="text-align-left text-align-center text-align-right text-align-justify">',
        '<h6 class="text-align-left text-align-center text-align-right text-align-justify">',
        '<dl class="text-align-left text-align-center text-align-right text-align-justify">',
        '<dd class="text-align-left text-align-center text-align-right text-align-justify">',
        '<blockquote class="text-align-left text-align-center text-align-right text-align-justify">',
        '<ul class="text-align-left text-align-center text-align-right text-align-justify">',
        '<ol class="text-align-left text-align-center text-align-right text-align-justify">',
        '<h2 class="text-align-center text-align-justify">',
        '<h3 class="text-align-center text-align-justify">',
        '<h4 class="text-align-center text-align-justify">',
        '<h5 class="text-align-center text-align-justify">',
        '<h6 class="text-align-center text-align-justify">',
        '<dl class="text-align-center text-align-justify">',
        '<dd class="text-align-center text-align-justify">',
        '<blockquote class="text-align-center text-align-justify">',
        '<ul class="text-align-center text-align-justify">',
        '<ol class="text-align-center text-align-justify">',
        $basic_html_test_case['expected_superset'],
      ]),
      'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'],
      'expected_messages' => array_merge($basic_html_test_case['expected_messages'],

        [
          'The following plugins were enabled to support specific attributes that are allowed by this text format: <em class="placeholder">Alignment ( for tag: &lt;p&gt; to support: class with value(s):  text-align-center, text-align-justify)</em>.',
          'The following plugins were enabled to support specific attributes that are allowed by this text format: <em class="placeholder">Align center ( for tag: &lt;p&gt; to support: class with value(s):  text-align-center), Justify ( for tag: &lt;p&gt; to support: class with value(s):  text-align-justify)</em>.',
          'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: &lt;a hreflang&gt; &lt;blockquote cite&gt; &lt;ul type&gt; &lt;ol start type&gt; &lt;h2 id&gt; &lt;h3 id&gt; &lt;h4 id&gt; &lt;h5 id&gt; &lt;h6 id&gt;.',
        ]),
    ];
+30 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\ckeditor5\Traits;

/**
 * Provides methods to test protected/private methods in unit tests.
 *
 * @internal
 */
trait PrivateMethodUnitTestTrait {

  /**
   * Gets a protected/private method to test.
   *
   * @param string $fqcn
   *   A fully qualified classname.
   * @param string $name
   *   The method name.
   *
   * @return \ReflectionMethod
   *   The accessible method.
   */
  protected static function getMethod(string $fqcn, string $name): \ReflectionMethod {
    $class = new \ReflectionClass($fqcn);
    $method = $class->getMethod($name);
    $method->setAccessible(TRUE);
    return $method;
  }

}
Loading