You are here

public function CKEditorTest::testBuildContentsCssJSSetting in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php \Drupal\Tests\ckeditor\Kernel\CKEditorTest::testBuildContentsCssJSSetting()
  2. 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 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 Olivero theme, which specifies a CKEditor stylesheet.
  \Drupal::service('theme_installer')
    ->install([
    'olivero',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'olivero')
    ->save();
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/olivero/css/base/fonts.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/olivero/css/base/base.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/olivero/css/components/embedded-media.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/olivero/css/components/table.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/olivero/css/components/text-content.css') . $query_string;
  $expected[] = $this->fileUrlGenerator
    ->generateString('core/themes/olivero/css/theme/ckeditor-frame.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.');
}