function AddItemToToolbarConfigActionTest::testAddItemToToolbar

Same name in other branches
  1. 10 core/modules/ckeditor5/tests/src/Kernel/ConfigAction/AddItemToToolbarConfigActionTest.php \Drupal\Tests\ckeditor5\Kernel\ConfigAction\AddItemToToolbarConfigActionTest::testAddItemToToolbar()

@testWith ["sourceEditing", ["heading", "bold", "italic", "sourceEditing"]] [{"item_name": "sourceEditing"}, ["heading", "bold", "italic", "sourceEditing"]] [{"item_name": "sourceEditing", "position": 1}, ["heading", "sourceEditing", "bold", "italic"]] [{"item_name": "sourceEditing", "position": 1, "replace": true}, ["heading", "sourceEditing", "italic"]]

Parameters

string|array<string, mixed> $action: The value to pass to the config action.

string[] $expected_toolbar_items: The items which should be in the editor toolbar, in the expected order.

File

core/modules/ckeditor5/tests/src/Kernel/ConfigAction/AddItemToToolbarConfigActionTest.php, line 73

Class

AddItemToToolbarConfigActionTest
@covers \Drupal\ckeditor5\Plugin\ConfigAction\AddItemToToolbar @group ckeditor5 @group Recipe

Namespace

Drupal\Tests\ckeditor5\Kernel\ConfigAction

Code

public function testAddItemToToolbar(string|array $action, array $expected_toolbar_items) : void {
    $recipe = $this->createRecipe([
        'name' => 'CKEditor 5 toolbar item test',
        'config' => [
            'actions' => [
                'editor.editor.filter_test' => [
                    'addItemToToolbar' => $action,
                ],
            ],
        ],
    ]);
    RecipeRunner::processRecipe($recipe);
    
    /** @var array{toolbar: array{items: string[]}, plugins: array<string, array<mixed>>} $settings */
    $settings = Editor::load('filter_test')?->getSettings();
    $this->assertSame($expected_toolbar_items, $settings['toolbar']['items']);
    // The plugin's default settings should have been added.
    $this->assertSame([], $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags']);
}

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