You are here

public function CKEditorTest::testBuildContentsCssJSSetting in Drupal 9

Same name and namespace in other branches
  1. 8 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 258

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
    ->assertEquals($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[] = $this->fileUrlGenerator
    ->generateString($this
    ->getModulePath('ckeditor_test') . '/ckeditor_test.css') . $query_string;
  $this
    ->assertSame($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[] = $this->fileUrlGenerator
    ->generateString($this
    ->getModulePath('ckeditor_test') . '/css/llama.css') . $query_string;
  $this
    ->assertSame($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[] = $this->fileUrlGenerator
    ->generateString('core/themes/bartik/css/base/elements.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/bartik/css/components/captions.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/bartik/css/components/table.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/bartik/css/components/text-formatted.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/bartik/css/classy/components/media-embed-error.css') . $query_string;
  $this
    ->assertSame($expected, $this->ckeditor
    ->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a theme providing a CKEditor stylesheet exists.');
}