function CKEditorTest::testBuildContentsCssJSSetting

Same name in other branches
  1. 9 core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php \Drupal\Tests\ckeditor\Kernel\CKEditorTest::testBuildContentsCssJSSetting()

Tests CKEditor::buildContentsCssJSSetting().

File

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

Class

CKEditorTest
Tests for the 'CKEditor' text editor plugin.

Namespace

Drupal\Tests\ckeditor\Kernel

Code

public function testBuildContentsCssJSSetting() {
    $editor = Editor::load('filtered_html');
    $query_string = '?0=';
    // Default toolbar.
    $expected = $this->getDefaultContentsCssConfig();
    $this->assertIdentical($expected, $this->ckeditor
        ->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly for default toolbar.');
    // Enable the editor_test module, which implements hook_ckeditor_css_alter().
    $this->enableModules([
        'ckeditor_test',
    ]);
    $expected[] = file_url_transform_relative(file_create_url(drupal_get_path('module', 'ckeditor_test') . '/ckeditor_test.css')) . $query_string;
    $this->assertIdentical($expected, $this->ckeditor
        ->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a hook_ckeditor_css_alter() implementation exists.');
    // Enable LlamaCss plugin, which adds an additional CKEditor stylesheet.
    $this->container
        ->get('plugin.manager.editor')
        ->clearCachedDefinitions();
    $this->ckeditor = $this->container
        ->get('plugin.manager.editor')
        ->createInstance('ckeditor');
    $this->container
        ->get('plugin.manager.ckeditor.plugin')
        ->clearCachedDefinitions();
    $settings = $editor->getSettings();
    // LlamaCss: automatically enabled by adding its 'LlamaCSS' button.
    $settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS';
    $editor->setSettings($settings);
    $editor->save();
    $expected[] = file_url_transform_relative(file_create_url(drupal_get_path('module', 'ckeditor_test') . '/css/llama.css')) . $query_string;
    $this->assertIdentical($expected, $this->ckeditor
        ->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a CKEditorPluginInterface implementation exists.');
    // Enable the Bartik theme, which specifies a CKEditor stylesheet.
    \Drupal::service('theme_installer')->install([
        'bartik',
    ]);
    $this->config('system.theme')
        ->set('default', 'bartik')
        ->save();
    $expected[] = file_url_transform_relative(file_create_url('core/themes/classy/css/components/media-embed-error.css')) . $query_string;
    $expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/base/elements.css')) . $query_string;
    $expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/captions.css')) . $query_string;
    $expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/table.css')) . $query_string;
    $expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/text-formatted.css')) . $query_string;
    $expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/classy/components/media-embed-error.css')) . $query_string;
    $this->assertIdentical($expected, $this->ckeditor
        ->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a theme providing a CKEditor stylesheet exists.');
}

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