function CKEditorTest::testBuildToolbarJSSetting

Same name and namespace in other branches
  1. 8.9.x core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php \Drupal\Tests\ckeditor\Kernel\CKEditorTest::testBuildToolbarJSSetting()

Tests CKEditor::buildToolbarJSSetting().

File

core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php, line 231

Class

CKEditorTest
Tests for the 'CKEditor' text editor plugin.

Namespace

Drupal\Tests\ckeditor\Kernel

Code

public function testBuildToolbarJSSetting() {
  $editor = Editor::load('filtered_html');
  // Default toolbar.
  $expected = $this->getDefaultToolbarConfig();
  $this->assertSame($expected, $this->ckeditor
    ->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
  // Customize the configuration.
  $settings = $editor->getSettings();
  $settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
  $editor->setSettings($settings);
  $editor->save();
  $expected[0]['items'][] = 'Strike';
  $this->assertEquals($expected, $this->ckeditor
    ->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
  // Enable the editor_test module, customize further.
  $this->enableModules([
    'ckeditor_test',
  ]);
  $this->container
    ->get('plugin.manager.ckeditor.plugin')
    ->clearCachedDefinitions();
  // Override the label of a toolbar component.
  $settings['toolbar']['rows'][0][0]['name'] = 'JunkScience';
  $settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
  $editor->setSettings($settings);
  $editor->save();
  $expected[0]['name'] = 'JunkScience';
  $expected[0]['items'][] = 'Llama';
  $this->assertEquals($expected, $this->ckeditor
    ->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.');
}

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