function CKEditor5PluginManagerTest::testProvidedElementsInvalidElementSubset

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php \Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::testProvidedElementsInvalidElementSubset()
  2. 10 core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php \Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::testProvidedElementsInvalidElementSubset()

Tests detection of invalid CKEditor5PluginElementsSubsetInterface classes.

@dataProvider providerProvidedElementsInvalidElementSubset

File

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

Class

CKEditor5PluginManagerTest
Tests different ways of enabling CKEditor 5 plugins.

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

public function testProvidedElementsInvalidElementSubset(array $configured_subset, string $expected_exception_message) : void {
    $this->enableModules([
        'ckeditor5_plugin_elements_subset',
    ]);
    // Configure the sneaky superset plugin.
    $sneaky_plugin_id = 'ckeditor5_plugin_elements_subset_sneakySuperset';
    $text_editor = Editor::create([
        'format' => 'dummy',
        'editor' => 'ckeditor5',
        'image_upload' => [
            'status' => FALSE,
        ],
        'settings' => [
            'plugins' => [
                $sneaky_plugin_id => [
                    'configured_subset' => $configured_subset,
                ],
            ],
        ],
    ]);
    // Invalid subsets are allowed on unsaved Text Editor config entities,
    // because they may have invalid configuration.
    $text_editor->enforceIsNew(FALSE);
    // No exception when getting all provided elements.
    $this->assertGreaterThan(0, count($this->manager
        ->getProvidedElements()));
    // No exception when getting the sneaky plugin's provided elements.
    $this->assertGreaterThan(0, count($this->manager
        ->getProvidedElements([
        $sneaky_plugin_id,
    ])));
    // Exception when getting the sneaky plugin's provided elements *and* a text
    // editor config entity is passed: only then can a subset be generated based
    // on configuration.
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage($expected_exception_message);
    $this->manager
        ->getProvidedElements([
        $sneaky_plugin_id,
    ], $text_editor);
}

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