Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -0,0 +1,5 @@
ajax_css:
js:
js/ajax-css.js: {}
dependencies:
- ckeditor/drupal.ckeditor

View file

@ -0,0 +1,7 @@
ckeditor_test.ajax_css:
path: '/ckeditor_test/ajax_css'
defaults:
_title: 'AJAX CSS Test'
_form: '\Drupal\ckeditor_test\Form\AjaxCssForm'
requirements:
_access: 'TRUE'

View file

@ -0,0 +1,3 @@
body {
color: red;
}

View file

@ -0,0 +1,24 @@
/**
* @file
* Contains client-side code for testing CSS delivered to CKEditor via AJAX.
*/
(function (Drupal, ckeditor, editorSettings, $) {
'use strict';
Drupal.behaviors.ajaxCssForm = {
attach: function (context) {
// Initialize an inline CKEditor on the #edit-inline element if it
// isn't editable already.
$(context)
.find('#edit-inline')
.not('[contenteditable]')
.each(function () {
ckeditor.attachInlineEditor(this, editorSettings.formats.test_format);
});
}
};
})(Drupal, Drupal.editors.ckeditor, drupalSettings.editor, jQuery);

View file

@ -0,0 +1,111 @@
<?php
namespace Drupal\ckeditor_test\Form;
use Drupal\ckeditor\Ajax\AddStyleSheetCommand;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* A form for testing delivery of CSS to CKEditor via AJAX.
*/
class AjaxCssForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ckeditor_test_ajax_css_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Create an inline and iframe CKEditor instance so we can test against
// both.
$form['inline'] = [
'#type' => 'container',
'#attached' => [
'library' => [
'ckeditor_test/ajax_css',
],
],
'#children' => $this->t('Here be dragons.'),
];
$form['iframe'] = [
'#type' => 'text_format',
'#default_value' => $this->t('Here be llamas.'),
];
// A pair of buttons to trigger the AJAX events.
$form['actions'] = [
'css_inline' => [
'#type' => 'submit',
'#value' => $this->t('Add CSS to inline CKEditor instance'),
'#ajax' => [
'callback' => [$this, 'addCssInline'],
],
],
'css_frame' => [
'#type' => 'submit',
'#value' => $this->t('Add CSS to iframe CKEditor instance'),
'#ajax' => [
'callback' => [$this, 'addCssIframe'],
],
],
'#type' => 'actions',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Nothing to do here.
}
/**
* Generates an AJAX response to add CSS to a CKEditor Text Editor instance.
*
* @param string $editor_id
* The Text Editor instance ID.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
protected function generateResponse($editor_id) {
// Build a URL to the style sheet that will be added.
$url = drupal_get_path('module', 'ckeditor_test') . '/css/test.css';
$url = file_create_url($url);
$url = file_url_transform_relative($url);
$response = new AjaxResponse();
return $response
->addCommand(new AddStyleSheetCommand($editor_id, [$url]));
}
/**
* Handles the AJAX request to add CSS to the inline editor.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
public function addCssInline() {
return $this->generateResponse('edit-inline');
}
/**
* Handles the AJAX request to add CSS to the iframe editor.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
public function addCssIframe() {
return $this->generateResponse('edit-iframe-value');
}
}

View file

@ -18,7 +18,7 @@ class CKEditorPluginManagerTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor');
public static $modules = ['system', 'user', 'filter', 'editor', 'ckeditor'];
/**
* The manager for "CKEditor plugin" plugins.
@ -33,12 +33,12 @@ class CKEditorPluginManagerTest extends KernelTestBase {
// Install the Filter module.
// Create text format, associate CKEditor.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(),
));
'filters' => [],
]);
$filtered_html_format->save();
$editor = Editor::create([
'format' => 'filtered_html',
@ -50,34 +50,34 @@ class CKEditorPluginManagerTest extends KernelTestBase {
/**
* Tests the enabling of plugins.
*/
function testEnabledPlugins() {
public function testEnabledPlugins() {
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$editor = Editor::load('filtered_html');
// Case 1: no CKEditor plugins.
$definitions = array_keys($this->manager->getDefinitions());
sort($definitions);
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'stylescombo'), $definitions, 'No CKEditor plugins found besides the built-in ones.');
$enabled_plugins = array(
$this->assertIdentical(['drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'stylescombo'], $definitions, 'No CKEditor plugins found besides the built-in ones.');
$enabled_plugins = [
'drupalimage' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js',
'drupallink' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupallink/plugin.js',
);
];
$this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only built-in plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
$this->assertIdentical(['internal' => NULL] + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
// Enable the CKEditor Test module, which has the Llama plugin (plus four
// variations of it, to cover all possible ways a plugin can be enabled) and
// clear the editor manager's cache so it is picked up.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$this->manager->clearCachedDefinitions();
// Case 2: CKEditor plugins are available.
$plugin_ids = array_keys($this->manager->getDefinitions());
sort($plugin_ids);
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'llama_css', 'stylescombo'), $plugin_ids, 'Additional CKEditor plugins found.');
$this->assertIdentical(['drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'llama_css', 'stylescombo'], $plugin_ids, 'Additional CKEditor plugins found.');
$this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only the internal plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
$this->assertIdentical(['internal' => NULL] + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
// Case 3: enable each of the newly available plugins, if possible:
// a. Llama: cannot be enabled, since it does not implement
@ -100,48 +100,48 @@ class CKEditorPluginManagerTest extends KernelTestBase {
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save();
$file = array();
$file = [];
$file['b'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_button.js';
$file['c'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual.js';
$file['cb'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js';
$file['css'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js';
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']);
$expected = $enabled_plugins + ['llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']];
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$settings['toolbar'] = $original_toolbar;
$settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$editor->setSettings($settings);
$editor->save();
$expected = $enabled_plugins + array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$expected = $enabled_plugins + ['llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']];
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save();
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$expected = $enabled_plugins + ['llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']];
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS';
$editor->setSettings($settings);
$editor->save();
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb'], 'llama_css' => $file['css']);
$expected = $enabled_plugins + ['llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb'], 'llama_css' => $file['css']];
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
$this->assertIdentical(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
}
/**
* Tests the iframe instance CSS files of plugins.
*/
function testCssFiles() {
public function testCssFiles() {
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$editor = Editor::load('filtered_html');
// Case 1: no CKEditor iframe instance CSS file.
$this->assertIdentical(array(), $this->manager->getCssFiles($editor), 'No iframe instance CSS file found.');
$this->assertIdentical([], $this->manager->getCssFiles($editor), 'No iframe instance CSS file found.');
// Enable the CKEditor Test module, which has the LlamaCss plugin and
// clear the editor manager's cache so it is picked up.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$settings = $editor->getSettings();
// LlamaCss: automatically enabled by adding its 'LlamaCSS' button.
@ -150,9 +150,9 @@ class CKEditorPluginManagerTest extends KernelTestBase {
$editor->save();
// Case 2: CKEditor iframe instance CSS file.
$expected = array(
'llama_css' => array(drupal_get_path('module', 'ckeditor_test') . '/css/llama.css')
);
$expected = [
'llama_css' => [drupal_get_path('module', 'ckeditor_test') . '/css/llama.css']
];
$this->assertIdentical($expected, $this->manager->getCssFiles($editor), 'Iframe instance CSS file found.');
}

View file

@ -19,7 +19,7 @@ class CKEditorTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor', 'filter_test');
public static $modules = ['system', 'user', 'filter', 'editor', 'ckeditor', 'filter_test'];
/**
* An instance of the "CKEditor" text editor plugin.
@ -41,19 +41,19 @@ class CKEditorTest extends KernelTestBase {
// Install the Filter module.
// Create text format, associate CKEditor.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(
'filter_html' => array(
'filters' => [
'filter_html' => [
'status' => 1,
'settings' => array(
'settings' => [
'allowed_html' => '<h2 id> <h3> <h4> <h5> <h6> <p> <br> <strong> <a href hreflang>',
)
),
),
));
]
],
],
]);
$filtered_html_format->save();
$editor = Editor::create([
'format' => 'filtered_html',
@ -68,11 +68,11 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests CKEditor::getJSSettings().
*/
function testGetJSSettings() {
public function testGetJSSettings() {
$editor = Editor::load('filtered_html');
// Default toolbar.
$expected_config = $this->getDefaultInternalConfig() + array(
$expected_config = $this->getDefaultInternalConfig() + [
'drupalImage_dialogTitleAdd' => 'Insert Image',
'drupalImage_dialogTitleEdit' => 'Edit Image',
'drupalLink_dialogTitleAdd' => 'Add Link',
@ -84,11 +84,11 @@ class CKEditorTest extends KernelTestBase {
'extraPlugins' => 'drupalimage,drupallink',
'language' => 'en',
'stylesSet' => FALSE,
'drupalExternalPlugins' => array(
'drupalExternalPlugins' => [
'drupalimage' => file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/plugin.js')),
'drupallink' => file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupallink/plugin.js')),
),
);
],
];
$expected_config = $this->castSafeStrings($expected_config);
ksort($expected_config);
ksort($expected_config['allowedContent']);
@ -96,7 +96,7 @@ class CKEditorTest extends KernelTestBase {
// Customize the configuration: add button, have two contextually enabled
// buttons, and configure a CKEditor plugin setting.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$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();
@ -121,16 +121,16 @@ class CKEditorTest extends KernelTestBase {
$format->filters('filter_html')->settings['allowed_html'] .= '<pre class> <h1> <blockquote class="*"> <address class="foo bar-* *">';
$format->save();
$expected_config['allowedContent']['pre'] = array('attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE);
$expected_config['allowedContent']['h1'] = array('attributes' => FALSE, 'styles' => FALSE, 'classes' => FALSE);
$expected_config['allowedContent']['blockquote'] = array('attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE);
$expected_config['allowedContent']['address'] = array('attributes' => 'class', 'styles' => FALSE, 'classes' => 'foo,bar-*');
$expected_config['allowedContent']['pre'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE];
$expected_config['allowedContent']['h1'] = ['attributes' => FALSE, 'styles' => FALSE, 'classes' => FALSE];
$expected_config['allowedContent']['blockquote'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE];
$expected_config['allowedContent']['address'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => 'foo,bar-*'];
$expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
ksort($expected_config['allowedContent']);
$this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Disable the filter_html filter: allow *all *tags.
$format->setFilterConfig('filter_html', array('status' => 0));
$format->setFilterConfig('filter_html', ['status' => 0]);
$format->save();
$expected_config['allowedContent'] = TRUE;
@ -139,73 +139,73 @@ class CKEditorTest extends KernelTestBase {
$this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Enable the filter_test_restrict_tags_and_attributes filter.
$format->setFilterConfig('filter_test_restrict_tags_and_attributes', array(
$format->setFilterConfig('filter_test_restrict_tags_and_attributes', [
'status' => 1,
'settings' => array(
'restrictions' => array(
'allowed' => array(
'settings' => [
'restrictions' => [
'allowed' => [
'p' => TRUE,
'a' => array(
'a' => [
'href' => TRUE,
'rel' => array('nofollow' => TRUE),
'class' => array('external' => TRUE),
'target' => array('_blank' => FALSE),
),
'span' => array(
'class' => array('dodo' => FALSE),
'property' => array('dc:*' => TRUE),
'rel' => array('foaf:*' => FALSE),
'style' => array('underline' => FALSE, 'color' => FALSE, 'font-size' => TRUE),
),
'*' => array(
'rel' => ['nofollow' => TRUE],
'class' => ['external' => TRUE],
'target' => ['_blank' => FALSE],
],
'span' => [
'class' => ['dodo' => FALSE],
'property' => ['dc:*' => TRUE],
'rel' => ['foaf:*' => FALSE],
'style' => ['underline' => FALSE, 'color' => FALSE, 'font-size' => TRUE],
],
'*' => [
'style' => FALSE,
'on*' => FALSE,
'class' => array('is-a-hipster-llama' => TRUE, 'and-more' => TRUE),
'class' => ['is-a-hipster-llama' => TRUE, 'and-more' => TRUE],
'data-*' => TRUE,
),
],
'del' => FALSE,
),
),
),
));
],
],
],
]);
$format->save();
$expected_config['allowedContent'] = array(
'p' => array(
$expected_config['allowedContent'] = [
'p' => [
'attributes' => TRUE,
'styles' => FALSE,
'classes' => 'is-a-hipster-llama,and-more',
),
'a' => array(
],
'a' => [
'attributes' => 'href,rel,class,target',
'styles' => FALSE,
'classes' => 'external',
),
'span' => array(
],
'span' => [
'attributes' => 'class,property,rel,style',
'styles' => 'font-size',
'classes' => FALSE,
),
'*' => array(
],
'*' => [
'attributes' => 'class,data-*',
'styles' => FALSE,
'classes' => 'is-a-hipster-llama,and-more',
),
'del' => array(
],
'del' => [
'attributes' => FALSE,
'styles' => FALSE,
'classes' => FALSE,
),
);
$expected_config['disallowedContent'] = array(
'span' => array(
],
];
$expected_config['disallowedContent'] = [
'span' => [
'styles' => 'underline,color',
'classes' => 'dodo',
),
'*' => array(
],
'*' => [
'attributes' => 'on*',
),
);
],
];
$expected_config['format_tags'] = 'p';
ksort($expected_config);
ksort($expected_config['allowedContent']);
@ -216,7 +216,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests CKEditor::buildToolbarJSSetting().
*/
function testBuildToolbarJSSetting() {
public function testBuildToolbarJSSetting() {
$editor = Editor::load('filtered_html');
// Default toolbar.
@ -232,7 +232,7 @@ class CKEditorTest extends KernelTestBase {
$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->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';
@ -247,7 +247,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests CKEditor::buildContentsCssJSSetting().
*/
function testBuildContentsCssJSSetting() {
public function testBuildContentsCssJSSetting() {
$editor = Editor::load('filtered_html');
// Default toolbar.
@ -255,7 +255,7 @@ class CKEditorTest extends KernelTestBase {
$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(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$expected[] = file_url_transform_relative(file_create_url(drupal_get_path('module', 'ckeditor_test') . '/ckeditor_test.css'));
$this->assertIdentical($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a hook_ckeditor_css_alter() implementation exists.');
@ -273,7 +273,7 @@ class CKEditorTest extends KernelTestBase {
// Enable the Bartik theme, which specifies a CKEditor stylesheet.
\Drupal::service('theme_handler')->install(['bartik']);
\Drupal::service('theme_handler')->setDefault('bartik');
$this->config('system.theme')->set('default', 'bartik')->save();
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/base/elements.css'));
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/captions.css'));
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/table.css'));
@ -284,7 +284,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests Internal::getConfig().
*/
function testInternalGetConfig() {
public function testInternalGetConfig() {
$editor = Editor::load('filtered_html');
$internal_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('internal');
@ -305,7 +305,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests StylesCombo::getConfig().
*/
function testStylesComboGetConfig() {
public function testStylesComboGetConfig() {
$editor = Editor::load('filtered_html');
$stylescombo_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('stylescombo');
@ -315,7 +315,7 @@ class CKEditorTest extends KernelTestBase {
$settings['plugins']['stylescombo']['styles'] = '';
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array();
$expected['stylesSet'] = [];
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Configure the optional "styles" setting in odd ways that shouldn't affect
@ -333,10 +333,10 @@ class CKEditorTest extends KernelTestBase {
$settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.mAgical.Callout|Callout";
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array(
array('name' => 'Title', 'element' => 'h1', 'attributes' => array('class' => 'title')),
array('name' => 'Callout', 'element' => 'p', 'attributes' => array('class' => 'mAgical Callout')),
);
$expected['stylesSet'] = [
['name' => 'Title', 'element' => 'h1', 'attributes' => ['class' => 'title']],
['name' => 'Callout', 'element' => 'p', 'attributes' => ['class' => 'mAgical Callout']],
];
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Same configuration, but now interspersed with nonsense. Should yield the
@ -350,7 +350,7 @@ class CKEditorTest extends KernelTestBase {
$settings['plugins']['stylescombo']['styles'] = " h1 | Title ";
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array(array('name' => 'Title', 'element' => 'h1'));
$expected['stylesSet'] = [['name' => 'Title', 'element' => 'h1']];
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Invalid syntax should cause stylesSet to be set to FALSE.
@ -364,10 +364,10 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests language list availability in CKEditor.
*/
function testLanguages() {
public function testLanguages() {
// Get CKEditor supported language codes and spot-check.
$this->enableModules(array('language'));
$this->installConfig(array('language'));
$this->enableModules(['language']);
$this->installConfig(['language']);
$langcodes = $this->ckeditor->getLangcodes();
// Language codes transformed with browser mappings.
@ -389,15 +389,15 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests that CKEditor plugins participate in JS translation.
*/
function testJSTranslation() {
$this->enableModules(array('language', 'locale'));
public function testJSTranslation() {
$this->enableModules(['language', 'locale']);
$this->installSchema('locale', 'locales_source');
$this->installSchema('locale', 'locales_location');
$this->installSchema('locale', 'locales_target');
$editor = Editor::load('filtered_html');
$this->ckeditor->getJSSettings($editor);
$localeStorage = $this->container->get('locale.storage');
$string = $localeStorage->findString(array('source' => 'Edit Link', 'context' => ''));
$string = $localeStorage->findString(['source' => 'Edit Link', 'context' => '']);
$this->assertTrue(!empty($string), 'String from JavaScript file saved.');
// With locale module, CKEditor should not adhere to the language selected.
@ -428,14 +428,14 @@ class CKEditorTest extends KernelTestBase {
}
protected function getDefaultInternalConfig() {
return array(
return [
'customConfig' => '',
'pasteFromWordPromptCleanup' => TRUE,
'resize_dir' => 'vertical',
'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'),
'justifyClasses' => ['text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'],
'entities' => FALSE,
'disableNativeSpellChecker' => FALSE,
);
];
}
protected function getDefaultAllowedContentConfig() {
@ -454,42 +454,42 @@ class CKEditorTest extends KernelTestBase {
}
protected function getDefaultDisallowedContentConfig() {
return array(
'*' => array('attributes' => 'on*'),
);
return [
'*' => ['attributes' => 'on*'],
];
}
protected function getDefaultToolbarConfig() {
return array(
array(
return [
[
'name' => 'Formatting',
'items' => array('Bold', 'Italic',),
),
array(
'items' => ['Bold', 'Italic'],
],
[
'name' => 'Links',
'items' => array('DrupalLink', 'DrupalUnlink',),
),
array(
'items' => ['DrupalLink', 'DrupalUnlink'],
],
[
'name' => 'Lists',
'items' => array('BulletedList', 'NumberedList',),
),
array(
'items' => ['BulletedList', 'NumberedList'],
],
[
'name' => 'Media',
'items' => array('Blockquote', 'DrupalImage',),
),
array(
'items' => ['Blockquote', 'DrupalImage'],
],
[
'name' => 'Tools',
'items' => array('Source',),
),
'items' => ['Source', ],
],
'/',
);
];
}
protected function getDefaultContentsCssConfig() {
return array(
return [
file_url_transform_relative(file_create_url('core/modules/ckeditor/css/ckeditor-iframe.css')),
file_url_transform_relative(file_create_url('core/modules/system/css/components/align.module.css')),
);
];
}
}

View file

@ -29,28 +29,28 @@ class Llama extends PluginBase implements CKEditorPluginInterface {
/**
* {@inheritdoc}
*/
function getDependencies(Editor $editor) {
return array();
public function getDependencies(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
function getLibraries(Editor $editor) {
return array();
public function getLibraries(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
function isInternal() {
public function isInternal() {
return FALSE;
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama.js';
}
@ -58,7 +58,7 @@ class Llama extends PluginBase implements CKEditorPluginInterface {
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
return array();
return [];
}
}

View file

@ -17,18 +17,18 @@ class LlamaButton extends Llama implements CKEditorPluginButtonsInterface {
/**
* {@inheritdoc}
*/
function getButtons() {
return array(
'Llama' => array(
public function getButtons() {
return [
'Llama' => [
'label' => t('Insert Llama'),
),
);
],
];
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_button.js';
}

View file

@ -18,7 +18,7 @@ class LlamaContextual extends Llama implements CKEditorPluginContextualInterface
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor) {
public function isEnabled(Editor $editor) {
// Automatically enable this plugin if the Underline button is enabled.
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
@ -34,7 +34,7 @@ class LlamaContextual extends Llama implements CKEditorPluginContextualInterface
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual.js';
}

View file

@ -22,7 +22,7 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor) {
public function isEnabled(Editor $editor) {
// Automatically enable this plugin if the Strike button is enabled.
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
@ -38,37 +38,37 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual
/**
* {@inheritdoc}
*/
function getButtons() {
return array(
'Llama' => array(
public function getButtons() {
return [
'Llama' => [
'label' => t('Insert Llama'),
),
);
],
];
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js';
}
/**
* {@inheritdoc}
*/
function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
// Defaults.
$config = array('ultra_llama_mode' => FALSE);
$config = ['ultra_llama_mode' => FALSE];
$settings = $editor->getSettings();
if (isset($settings['plugins']['llama_contextual_and_button'])) {
$config = $settings['plugins']['llama_contextual_and_button'];
}
$form['ultra_llama_mode'] = array(
$form['ultra_llama_mode'] = [
'#title' => t('Ultra llama mode'),
'#type' => 'checkbox',
'#default_value' => $config['ultra_llama_mode'],
);
];
return $form;
}

View file

@ -19,27 +19,27 @@ class LlamaCss extends Llama implements CKEditorPluginButtonsInterface, CKEditor
/**
* {@inheritdoc}
*/
function getButtons() {
return array(
'LlamaCSS' => array(
public function getButtons() {
return [
'LlamaCSS' => [
'label' => t('Insert Llama CSS'),
),
);
],
];
}
/**
* {@inheritdoc}
*/
function getCssFiles(Editor $editor) {
return array(
public function getCssFiles(Editor $editor) {
return [
drupal_get_path('module', 'ckeditor_test') . '/css/llama.css'
);
];
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js';
}

View file

@ -0,0 +1,77 @@
<?php
namespace Drupal\Tests\ckeditor\Functional;
use Drupal\filter\Entity\FilterFormat;
use Drupal\editor\Entity\Editor;
use Drupal\Tests\BrowserTestBase;
use Drupal\Component\Serialization\Json;
/**
* Tests CKEditor toolbar buttons when the language direction is RTL.
*
* @group ckeditor
*/
class CKEditorToolbarButtonTest extends BrowserTestBase {
/**
* Modules to enable for this test.
*
* @var array
*/
public static $modules = ['filter', 'editor', 'ckeditor', 'locale'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a text format and associate this with CKEditor.
FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => [],
])->save();
Editor::create([
'format' => 'full_html',
'editor' => 'ckeditor',
])->save();
// Create a new user with admin rights.
$this->admin_user = $this->drupalCreateUser([
'administer languages',
'access administration pages',
'administer site configuration',
'administer filters',
]);
}
/**
* Method tests CKEditor image buttons.
*/
public function testImageButtonDisplay() {
$this->drupalLogin($this->admin_user);
// Install the Arabic language (which is RTL) and configure as the default.
$edit = [];
$edit['predefined_langcode'] = 'ar';
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$edit = ['site_default_language' => 'ar'];
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
// Once the default language is changed, go to the tested text format
// configuration page.
$this->drupalGet('admin/config/content/formats/manage/full_html');
// Check if any image button is loaded in CKEditor json.
$json_encode = function($html) {
return trim(Json::encode($html), '"');
};
$markup = $json_encode(file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/icons/drupalimage.png')));
$this->assertRaw($markup);
}
}

View file

@ -0,0 +1,123 @@
<?php
namespace Drupal\Tests\ckeditor\FunctionalJavascript;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests delivery of CSS to CKEditor via AJAX.
*
* @group ckeditor
*/
class AjaxCssTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['ckeditor', 'ckeditor_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
FilterFormat::create([
'format' => 'test_format',
'name' => $this->randomMachineName(),
])->save();
Editor::create([
'editor' => 'ckeditor',
'format' => 'test_format',
])->save();
user_role_grant_permissions('anonymous', ['use text format test_format']);
}
/**
* Tests adding style sheets dynamically to CKEditor.
*/
public function testCkeditorAjaxAddCss() {
$this->drupalGet('/ckeditor_test/ajax_css');
$session = $this->getSession();
$page = $session->getPage();
$this->waitOnCkeditorInstance('edit-iframe-value');
$this->waitOnCkeditorInstance('edit-inline');
$style_color = 'rgb(255, 0, 0)';
// Add the inline CSS and assert that the style is applied to the main body,
// but not the iframe.
$page->pressButton('Add CSS to inline CKEditor instance');
$result = $page->waitFor(10, function() use ($style_color) {
return ($this->getEditorStyle('edit-inline', 'color') == $style_color)
&& ($this->getEditorStyle('edit-iframe-value', 'color') != $style_color);
});
$this->assertTrue($result);
$session->reload();
$this->waitOnCkeditorInstance('edit-iframe-value');
$this->waitOnCkeditorInstance('edit-inline');
// Add the iframe CSS and assert that the style is applied to the iframe,
// but not the main body.
$page->pressButton('Add CSS to iframe CKEditor instance');
$result = $page->waitFor(10, function() use ($style_color) {
return ($this->getEditorStyle('edit-inline', 'color') != $style_color)
&& ($this->getEditorStyle('edit-iframe-value', 'color') == $style_color);
});
$this->assertTrue($result);
}
/**
* Gets a computed style value for a CKEditor instance.
*
* @param string $instance_id
* The CKEditor instance ID.
* @param string $attribute
* The style attribute.
*
* @return string
* The computed style value.
*/
protected function getEditorStyle($instance_id, $attribute) {
$js = sprintf(
'CKEDITOR.instances["%s"].document.getBody().getComputedStyle("%s")',
$instance_id,
$attribute
);
return $this->getSession()->evaluateScript($js);
}
/**
* Wait for a CKEditor instance to finish loading and initializing.
*
* @param string $instance_id
* The CKEditor instance ID.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*/
protected function waitOnCkeditorInstance($instance_id, $timeout = 10000) {
$condition = <<<JS
(function() {
return (
typeof CKEDITOR !== 'undefined'
&& typeof CKEDITOR.instances["$instance_id"] !== 'undefined'
&& CKEDITOR.instances["$instance_id"].instanceReady
);
}());
JS;
$this->getSession()->wait($timeout, $condition);
}
}