function WildcardHtmlSupportTest::testGhsConfiguration

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/Kernel/WildcardHtmlSupportTest.php \Drupal\Tests\ckeditor5\Kernel\WildcardHtmlSupportTest::testGhsConfiguration()
  2. 11.x core/modules/ckeditor5/tests/src/Kernel/WildcardHtmlSupportTest.php \Drupal\Tests\ckeditor5\Kernel\WildcardHtmlSupportTest::testGhsConfiguration()

@covers \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing::getDynamicPluginConfig @dataProvider providerGhsConfiguration

File

core/modules/ckeditor5/tests/src/Kernel/WildcardHtmlSupportTest.php, line 48

Class

WildcardHtmlSupportTest
@covers \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getCKEditor5PluginConfig @group ckeditor5 @internal

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

public function testGhsConfiguration(string $filter_html_allowed, array $source_editing_tags, array $expected_ghs_configuration, ?array $additional_toolbar_items = []) : void {
    FilterFormat::create([
        'format' => 'test_format',
        'name' => 'Test format',
        'filters' => [
            'filter_html' => [
                'status' => TRUE,
                'settings' => [
                    'allowed_html' => $filter_html_allowed,
                ],
            ],
        ],
    ])->save();
    $editor_config = [
        'editor' => 'ckeditor5',
        'format' => 'test_format',
        'settings' => [
            'toolbar' => [
                'items' => array_merge([
                    'sourceEditing',
                ], $additional_toolbar_items),
            ],
            'plugins' => [
                'ckeditor5_sourceEditing' => [
                    'allowed_tags' => $source_editing_tags,
                ],
            ],
        ],
        'image_upload' => [
            'status' => FALSE,
        ],
    ];
    if (in_array('alignment', $additional_toolbar_items, TRUE)) {
        $editor_config['settings']['plugins']['ckeditor5_alignment'] = [
            'enabled_alignments' => [
                'left',
                'center',
                'right',
                'justify',
            ],
        ];
    }
    $editor = Editor::create($editor_config);
    $editor->save();
    $this->assertSame([], array_map(function (ConstraintViolation $v) {
        return (string) $v->getMessage();
    }, iterator_to_array(CKEditor5::validatePair(Editor::load('test_format'), FilterFormat::load('test_format')))));
    $config = $this->manager
        ->getCKEditor5PluginConfig($editor);
    $ghs_configuration = $config['config']['htmlSupport']['allow'];
    // The first two entries in the GHS configuration are from the
    // `ckeditor5_globalAttributeDir` and `ckeditor5_globalAttributeLang`
    // plugins. They are out of scope for this test, so omit them.
    $ghs_configuration = array_slice($ghs_configuration, 2);
    $this->assertEquals($expected_ghs_configuration, $ghs_configuration);
}

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