function CKEditor5PluginManagerTest::testProvidedElements

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

Tests the parsing of CKEditor 5 plugin element config.

@covers \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getProvidedElements @dataProvider providerTestProvidedElements

Parameters

string[] $plugins: The plugins to parse the elements list from.

array $text_editor_settings: The text editor settings.

array $expected_elements: An array of expected allowed elements an attributes in the structure used by filter_html.

string $expected_readable_string: The expected allowed tags and attributes as a string, typically used in the filter_html "Allowed tags" field.

File

core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php, line 1252

Class

CKEditor5PluginManagerTest
Tests different ways of enabling CKEditor 5 plugins.

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

public function testProvidedElements(array $plugins, array $text_editor_settings, array $expected_elements, string $expected_readable_string) {
    $this->enableModules([
        'ckeditor5_plugin_elements_test',
    ]);
    $text_editor = Editor::create([
        'format' => 'dummy',
        'editor' => 'ckeditor5',
        'settings' => $text_editor_settings,
        'image_upload' => [
            'status' => FALSE,
        ],
    ]);
    FilterFormat::create([
        'format' => 'dummy',
        'name' => 'dummy',
    ])->save();
    $this->assertConfigSchema($this->typedConfig, $text_editor->getConfigDependencyName(), $text_editor->toArray());
    // @todo Remove in https://www.drupal.org/project/drupal/issues/3361534, which moves this into ::assertConfigSchema()
    $this->assertSame([], array_map(fn($v) => sprintf("[%s] %s", $v->getPropertyPath(), (string) $v->getMessage()), iterator_to_array($this->typedConfig
        ->createFromNameAndData($text_editor->getConfigDependencyName(), $text_editor->toArray())
        ->validate())));
    $provided_elements = $this->manager
        ->getProvidedElements($plugins, $text_editor);
    $this->assertSame($expected_elements, $provided_elements);
    $this->assertSame($expected_readable_string, (new HTMLRestrictions($provided_elements))->toFilterHtmlAllowedTagsString());
}

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