You are here

function CKEditorTest::testBuildToolbarJSSetting in Zircon Profile 8

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

Tests CKEditor::buildToolbarJSSetting().

File

core/modules/ckeditor/src/Tests/CKEditorTest.php, line 224
Contains \Drupal\ckeditor\Tests\CKEditorTest.

Class

CKEditorTest
Tests for the 'CKEditor' text editor plugin.

Namespace

Drupal\ckeditor\Tests

Code

function testBuildToolbarJSSetting() {
  $editor = entity_load('editor', 'filtered_html');

  // Default toolbar.
  $expected = $this
    ->getDefaultToolbarConfig();
  $this
    ->assertIdentical($expected, $this
    ->castSafeStrings($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
    ->assertIdentical($expected, $this
    ->castSafeStrings($this->ckeditor
    ->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');

  // Enable the editor_test module, customize further.
  $this
    ->enableModules(array(
    '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
    ->assertIdentical($expected, $this
    ->castSafeStrings($this->ckeditor
    ->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.');
}