8
0
Просмотр исходного кода

Merge branch 'master' into t/ckeditor5/1151

Aleksander Nowodzinski 6 лет назад
Родитель
Сommit
f699675316

+ 18 - 2
packages/ckeditor5-core/CHANGELOG.md

@@ -1,11 +1,27 @@
 Changelog
 =========
 
+## [12.2.0](https://github.com/ckeditor/ckeditor5-core/compare/v12.1.1...v12.2.0) (2019-07-04)
+
+### Features
+
+* Added an editor instance reference to the native editable DOM element under the `ckeditorInstance` property. Closes [ckeditor/ckeditor5#1838](https://github.com/ckeditor/ckeditor5/issues/1838). ([fa94600](https://github.com/ckeditor/ckeditor5-core/commit/fa94600))
+
+  Implemented the `EditorUI#setEditableElement()` method.
+  Deprecated the `EditorUI#_editableElements` property.
+* Introduced `MultiCommand` which acts as a composite command – it can group multiple commands under the hood. ([ebcbd01](https://github.com/ckeditor/ckeditor5-core/commit/ebcbd01))
+
+### Other changes
+
+* Introduce the `editor-wrong-element` error thrown when the editor is created over a wrong element. Closes [ckeditor/ckeditor5#1591](https://github.com/ckeditor/ckeditor5/issues/1591). ([9945fc6](https://github.com/ckeditor/ckeditor5-core/commit/9945fc6))
+* Updated translations. ([43f5b6e](https://github.com/ckeditor/ckeditor5-core/commit/43f5b6e))
+
+
 ## [12.1.1](https://github.com/ckeditor/ckeditor5-core/compare/v12.1.0...v12.1.1) (2019-06-05)
 
 ### Other changes
 
-* Updated translations. ([ed6bd3c](https://github.com/ckeditor/ckeditor5-core/commit/ed6bd3c)) 
+* Updated translations. ([ed6bd3c](https://github.com/ckeditor/ckeditor5-core/commit/ed6bd3c))
 
 
 ## [12.1.0](https://github.com/ckeditor/ckeditor5-core/compare/v12.0.0...v12.1.0) (2019-04-10)
@@ -17,7 +33,7 @@ Changelog
 ### Other changes
 
 * Optimized icons. ([a5f8d34](https://github.com/ckeditor/ckeditor5-core/commit/a5f8d34))
-* Updated translations. ([2dedc43](https://github.com/ckeditor/ckeditor5-core/commit/2dedc43)) 
+* Updated translations. ([2dedc43](https://github.com/ckeditor/ckeditor5-core/commit/2dedc43))
 
 
 ## [12.0.0](https://github.com/ckeditor/ckeditor5-core/compare/v11.1.0...v12.0.0) (2019-02-28)

+ 25 - 0
packages/ckeditor5-core/lang/translations/af.po

@@ -0,0 +1,25 @@
+# Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+#
+#                                     !!! IMPORTANT !!!
+#
+#         Before you edit this file, please keep in mind that contributing to the project
+#                translations is possible ONLY via the Transifex online service.
+#
+#         To submit your translations, visit https://www.transifex.com/ckeditor/ckeditor5.
+#
+#                   To learn more, check out the official contributor's guide:
+#     https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
+#
+msgid ""
+msgstr ""
+"Language-Team: Afrikaans (https://www.transifex.com/ckeditor/teams/11143/af/)\n"
+"Language: af\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+msgctxt "Label for the Save button."
+msgid "Save"
+msgstr "Berg"
+
+msgctxt "Label for the Cancel button."
+msgid "Cancel"
+msgstr "Kanselleer"

+ 16 - 16
packages/ckeditor5-core/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@ckeditor/ckeditor5-core",
-  "version": "12.1.1",
+  "version": "12.2.0",
   "description": "The core architecture of CKEditor 5 – the best browser-based rich text editor.",
   "keywords": [
     "ckeditor5-lib",
@@ -21,24 +21,24 @@
     "framework"
   ],
   "dependencies": {
-    "@ckeditor/ckeditor5-engine": "^13.1.1",
-    "@ckeditor/ckeditor5-utils": "^12.1.1",
+    "@ckeditor/ckeditor5-engine": "^13.2.0",
+    "@ckeditor/ckeditor5-utils": "^13.0.0",
     "lodash-es": "^4.17.10"
   },
   "devDependencies": {
-    "@ckeditor/ckeditor5-autoformat": "^11.0.2",
-    "@ckeditor/ckeditor5-basic-styles": "^11.1.1",
-    "@ckeditor/ckeditor5-block-quote": "^11.1.0",
-    "@ckeditor/ckeditor5-editor-classic": "^12.1.1",
-    "@ckeditor/ckeditor5-essentials": "^11.0.2",
-    "@ckeditor/ckeditor5-heading": "^11.0.2",
-    "@ckeditor/ckeditor5-image": "^13.1.0",
-    "@ckeditor/ckeditor5-link": "^11.0.2",
-    "@ckeditor/ckeditor5-list": "^12.0.2",
-    "@ckeditor/ckeditor5-media-embed": "^11.1.1",
-    "@ckeditor/ckeditor5-paragraph": "^11.0.2",
-    "@ckeditor/ckeditor5-table": "^13.0.0",
-    "@ckeditor/ckeditor5-ui": "^13.0.0",
+    "@ckeditor/ckeditor5-autoformat": "^11.0.3",
+    "@ckeditor/ckeditor5-basic-styles": "^11.1.2",
+    "@ckeditor/ckeditor5-block-quote": "^11.1.1",
+    "@ckeditor/ckeditor5-editor-classic": "^12.1.2",
+    "@ckeditor/ckeditor5-essentials": "^11.0.3",
+    "@ckeditor/ckeditor5-heading": "^11.0.3",
+    "@ckeditor/ckeditor5-image": "^13.1.1",
+    "@ckeditor/ckeditor5-link": "^11.1.0",
+    "@ckeditor/ckeditor5-list": "^12.0.3",
+    "@ckeditor/ckeditor5-media-embed": "^11.1.2",
+    "@ckeditor/ckeditor5-paragraph": "^11.0.3",
+    "@ckeditor/ckeditor5-table": "^13.0.1",
+    "@ckeditor/ckeditor5-ui": "^13.0.1",
     "eslint": "^5.5.0",
     "eslint-config-ckeditor5": "^1.0.11",
     "husky": "^1.3.1",

+ 1 - 1
packages/ckeditor5-core/src/commandcollection.js

@@ -62,7 +62,7 @@ export default class CommandCollection {
 			 * @error commandcollection-command-not-found
 			 * @param {String} commandName Name of the command.
 			 */
-			throw new CKEditorError( 'commandcollection-command-not-found: Command does not exist.', { commandName } );
+			throw new CKEditorError( 'commandcollection-command-not-found: Command does not exist.', this, { commandName } );
 		}
 
 		command.execute( ...args );

+ 52 - 5
packages/ckeditor5-core/src/editor/editorui.js

@@ -12,6 +12,7 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 
 /**
  * A class providing the minimal interface that is required to successfully bootstrap any editor UI.
@@ -54,10 +55,10 @@ export default class EditorUI {
 		/**
 		 * Stores all editable elements used by the editor instance.
 		 *
-		 * @protected
+		 * @private
 		 * @member {Map.<String,HTMLElement>}
 		 */
-		this._editableElements = new Map();
+		this._editableElementsMap = new Map();
 
 		// Informs UI components that should be refreshed after layout change.
 		this.listenTo( editor.editing.view.document, 'layoutChanged', () => this.update() );
@@ -100,7 +101,29 @@ export default class EditorUI {
 
 		this.focusTracker.destroy();
 
-		this._editableElements = new Map();
+		// Clean–up the references to the CKEditor instance stored in the native editable DOM elements.
+		for ( const domElement of this._editableElementsMap.values() ) {
+			domElement.ckeditorInstance = null;
+		}
+
+		this._editableElementsMap = new Map();
+	}
+
+	/**
+	 * Store the native DOM editable element used by the editor under
+	 * a unique name.
+	 *
+	 * @param {String} rootName The unique name of the editable element.
+	 * @param {HTMLElement} domElement The native DOM editable element.
+	 */
+	setEditableElement( rootName, domElement ) {
+		this._editableElementsMap.set( rootName, domElement );
+
+		// Put a reference to the CKEditor instance in the editable native DOM element.
+		// It helps 3rd–party software (browser extensions, other libraries) access and recognize
+		// CKEditor 5 instances (editing roots) and use their API (there is no global editor
+		// instance registry).
+		domElement.ckeditorInstance = this.editor;
 	}
 
 	/**
@@ -110,7 +133,7 @@ export default class EditorUI {
 	 * @returns {HTMLElement|undefined}
 	 */
 	getEditableElement( rootName = 'main' ) {
-		return this._editableElements.get( rootName );
+		return this._editableElementsMap.get( rootName );
 	}
 
 	/**
@@ -119,7 +142,31 @@ export default class EditorUI {
 	 * @returns {Iterable.<String>}
 	 */
 	getEditableElementsNames() {
-		return this._editableElements.keys();
+		return this._editableElementsMap.keys();
+	}
+
+	/**
+	 * Stores all editable elements used by the editor instance.
+	 *
+	 * @protected
+	 * @deprecated
+	 * @member {Map.<String,HTMLElement>}
+	 */
+	get _editableElements() {
+		/**
+		 * The {@link module:core/editor/editorui~EditorUI#_editableElements `EditorUI#_editableElements`} property has been
+		 * deprecated and will be removed in the near future. Please use {@link #setEditableElement `setEditableElement()`} and
+		 * {@link #getEditableElement `getEditableElement()`} methods instead.
+		 *
+		 * @error editor-ui-deprecated-editable-elements
+		 * @param {module:core/editor/editorui~EditorUI} editorUI Editor UI instance the deprecated property belongs to.
+		 */
+		log.warn(
+			'editor-ui-deprecated-editable-elements: ' +
+			'The EditorUI#_editableElements property has been deprecated and will be removed in the near future.',
+			{ editorUI: this } );
+
+		return this._editableElementsMap;
 	}
 
 	/**

+ 4 - 1
packages/ckeditor5-core/src/editor/utils/attachtoform.js

@@ -26,7 +26,10 @@ export default function attachToForm( editor ) {
 		 *
 		 * @error attachtoform-missing-elementapi-interface
 		 */
-		throw new CKEditorError( 'attachtoform-missing-elementapi-interface: Editor passed to attachToForm() must implement ElementApi.' );
+		throw new CKEditorError(
+			'attachtoform-missing-elementapi-interface: Editor passed to attachToForm() must implement ElementApi.',
+			editor
+		);
 	}
 
 	const sourceElement = editor.sourceElement;

+ 4 - 1
packages/ckeditor5-core/src/editor/utils/elementapimixin.js

@@ -30,7 +30,10 @@ const ElementApiMixin = {
 			 *
 			 * @error editor-missing-sourceelement
 			 */
-			throw new CKEditorError( 'editor-missing-sourceelement: Cannot update the source element of a detached editor.' );
+			throw new CKEditorError(
+				'editor-missing-sourceelement: Cannot update the source element of a detached editor.',
+				this
+			);
 		}
 
 		setDataInElement( this.sourceElement, this.data.get() );

+ 99 - 0
packages/ckeditor5-core/src/multicommand.js

@@ -0,0 +1,99 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import Command from './command';
+
+/**
+ * @module core/multicommand
+ */
+
+/**
+ * A CKEditor command that aggregates other commands.
+ *
+ * This command is used to proxy multiple commands. The multi-command is enabled when
+ * at least one of its registered child commands is enabled.
+ * When executing a multi-command the first command that is enabled will be executed.
+ *
+ *		const multiCommand = new MultiCommand( editor );
+ *
+ *		const commandFoo = new Command( editor );
+ *		const commandBar = new Command( editor );
+ *
+ *		// Register child commands.
+ *		multiCommand.registerChildCommand( commandFoo );
+ *		multiCommand.registerChildCommand( commandBar );
+ *
+ *		// Enable one of the commands.
+ *		commandBar.isEnabled = true;
+ *
+ *		multiCommand.execute(); // Will execute commandBar.
+ *
+ * @extends module:core/command~Command
+ */
+export default class MultiCommand extends Command {
+	/**
+	 * @inheritDoc
+	 */
+	constructor( editor ) {
+		super( editor );
+
+		/**
+		 * Registered child commands.
+		 *
+		 * @type {Array.<module:core/command~Command>}
+		 * @private
+		 */
+		this._childCommands = [];
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	refresh() {
+		// Override base command refresh(): the command's state is changed when one of child commands changes states.
+	}
+
+	/**
+	 * Executes the first of it registered child commands.
+	 */
+	execute( ...args ) {
+		const command = this._getFirstEnabledCommand();
+
+		command.execute( args );
+	}
+
+	/**
+	 * Registers a child command.
+	 *
+	 * @param {module:core/command~Command} command
+	 */
+	registerChildCommand( command ) {
+		this._childCommands.push( command );
+
+		// Change multi command enabled state when one of registered commands changes state.
+		command.on( 'change:isEnabled', () => this._checkEnabled() );
+
+		this._checkEnabled();
+	}
+
+	/**
+	 * Checks if any of child commands is enabled.
+	 *
+	 * @private
+	 */
+	_checkEnabled() {
+		this.isEnabled = !!this._getFirstEnabledCommand();
+	}
+
+	/**
+	 * Returns a first enabled command or undefined if none of them is enabled.
+	 *
+	 * @returns {module:core/command~Command|undefined}
+	 * @private
+	 */
+	_getFirstEnabledCommand() {
+		return this._childCommands.find( command => command.isEnabled );
+	}
+}

+ 1 - 1
packages/ckeditor5-core/src/pendingactions.js

@@ -99,7 +99,7 @@ export default class PendingActions extends Plugin {
 			 *
 			 * @error pendingactions-add-invalid-message
 			 */
-			throw new CKEditorError( 'pendingactions-add-invalid-message: The message must be a string.' );
+			throw new CKEditorError( 'pendingactions-add-invalid-message: The message must be a string.', this );
 		}
 
 		const action = Object.create( ObservableMixin );

+ 3 - 2
packages/ckeditor5-core/src/plugincollection.js

@@ -119,7 +119,7 @@ export default class PluginCollection {
 				pluginName = key.pluginName || key.name;
 			}
 
-			throw new CKEditorError( errorMsg, { plugin: pluginName } );
+			throw new CKEditorError( errorMsg, this._editor, { plugin: pluginName } );
 		}
 
 		return plugin;
@@ -191,7 +191,7 @@ export default class PluginCollection {
 			// Log the error so it's more visible on the console. Hopefully, for better DX.
 			log.error( errorMsg, { plugins: missingPlugins } );
 
-			return Promise.reject( new CKEditorError( errorMsg, { plugins: missingPlugins } ) );
+			return Promise.reject( new CKEditorError( errorMsg, this._editor, { plugins: missingPlugins } ) );
 		}
 
 		return Promise.all( pluginConstructors.map( loadPlugin ) )
@@ -266,6 +266,7 @@ export default class PluginCollection {
 							throw new CKEditorError(
 								'plugincollection-required: Cannot load a plugin because one of its dependencies is listed in' +
 								'the `removePlugins` option.',
+								editor,
 								{ plugin: RequiredPluginConstructor, requiredBy: PluginConstructor }
 							);
 						}

+ 2 - 3
packages/ckeditor5-core/tests/_utils-tests/classictesteditor.js

@@ -22,7 +22,7 @@ import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
 
 import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import testUtils from '../../tests/_utils/utils';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'ClassicTestEditor', () => {
 	let editorElement;
@@ -225,8 +225,7 @@ describe( 'ClassicTestEditor', () => {
 				.then( () => {
 					throw new Error( 'It should throw an error' );
 				}, err => {
-					expect( err.message ).to.match( /^editor-create-initial-data:/ );
-					expect( err ).to.be.instanceOf( CKEditorError );
+					assertCKEditorError( err, /^editor-create-initial-data:/, null );
 				} );
 		} );
 	} );

+ 19 - 0
packages/ckeditor5-core/tests/_utils-tests/virtualtesteditor.js

@@ -41,6 +41,8 @@ describe( 'VirtualTestEditor', () => {
 			return VirtualTestEditor.create( { initialData: '<p>foo</p>', plugins: [ Paragraph ] } )
 				.then( editor => {
 					expect( editor.getData() ).to.equal( '<p>foo</p>' );
+
+					return editor.destroy();
 				} );
 		} );
 
@@ -48,6 +50,23 @@ describe( 'VirtualTestEditor', () => {
 			return VirtualTestEditor.create()
 				.then( editor => {
 					expect( editor.getData() ).to.equal( '' );
+
+					return editor.destroy();
+				} );
+		} );
+
+		it( 'fires the `data#ready` event once', () => {
+			const dataReadySpy = sinon.spy();
+
+			const Plugin = function( editor ) {
+				editor.data.on( 'ready', dataReadySpy );
+			};
+
+			return VirtualTestEditor.create( { plugins: [ Plugin ] } )
+				.then( editor => {
+					sinon.assert.calledOnce( dataReadySpy );
+
+					return editor.destroy();
 				} );
 		} );
 	} );

+ 3 - 2
packages/ckeditor5-core/tests/_utils/classictesteditor.js

@@ -79,7 +79,8 @@ export default class ClassicTestEditor extends Editor {
 							// Documented in core/editor/editorconfig.jsdoc.
 							throw new CKEditorError(
 								'editor-create-initial-data: ' +
-								'The config.initialData option cannot be used together with initial data passed in Editor.create().'
+								'The config.initialData option cannot be used together with initial data passed in Editor.create().',
+								null
 							);
 						}
 
@@ -138,7 +139,7 @@ class ClassicTestEditorUI extends EditorUI {
 
 		view.main.add( view.editable );
 
-		this._editableElements.set( 'main', view.editable.element );
+		this.setEditableElement( 'main', view.editable.element );
 
 		if ( replacementElement ) {
 			this._elementReplacer.replace( replacementElement, view.element );

+ 2 - 5
packages/ckeditor5-core/tests/_utils/virtualtesteditor.js

@@ -33,14 +33,11 @@ export default class VirtualTestEditor extends Editor {
 
 			resolve(
 				editor.initPlugins()
+					.then( () => editor.data.init( config.initialData || '' ) )
 					.then( () => {
-						editor.data.init( config.initialData || '' );
-
-						// Fire `data#ready` event manually as `data#init()` method is not used.
-						editor.data.fire( 'ready' );
 						editor.fire( 'ready' );
+						return editor;
 					} )
-					.then( () => editor )
 			);
 		} );
 	}

+ 6 - 3
packages/ckeditor5-core/tests/commandcollection.js

@@ -4,9 +4,9 @@
  */
 
 import CommandCollection from '../src/commandcollection';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Command from '../src/command';
 import ModelTestEditor from './_utils/modeltesteditor';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 class SomeCommand extends Command {
 	execute() {}
@@ -56,9 +56,12 @@ describe( 'CommandCollection', () => {
 		} );
 
 		it( 'throws an error if command does not exist', () => {
-			expect( () => {
+			const command = new SomeCommand( editor );
+			collection.add( 'bar', command );
+
+			expectToThrowCKEditorError( () => {
 				collection.execute( 'foo' );
-			} ).to.throw( CKEditorError, /^commandcollection-command-not-found:/ );
+			}, /^commandcollection-command-not-found:/, editor );
 		} );
 	} );
 

+ 3 - 3
packages/ckeditor5-core/tests/editor/editor.js

@@ -11,10 +11,10 @@ import Config from '@ckeditor/ckeditor5-utils/src/config';
 import EditingController from '@ckeditor/ckeditor5-engine/src/controller/editingcontroller';
 import PluginCollection from '../../src/plugincollection';
 import CommandCollection from '../../src/commandcollection';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 import Command from '../../src/command';
 import EditingKeystrokeHandler from '../../src/editingkeystrokehandler';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 class TestEditor extends Editor {
 	static create( config ) {
@@ -368,9 +368,9 @@ describe( 'Editor', () => {
 		it( 'should throw an error if specified command has not been added', () => {
 			const editor = new TestEditor();
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				editor.execute( 'command' );
-			} ).to.throw( CKEditorError, /^commandcollection-command-not-found:/ );
+			}, /^commandcollection-command-not-found:/, editor );
 		} );
 	} );
 

+ 56 - 9
packages/ckeditor5-core/tests/editor/editorui.js

@@ -10,6 +10,7 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
 
 import testUtils from '../_utils/utils';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 
 /* global document */
 
@@ -85,14 +86,50 @@ describe( 'EditorUI', () => {
 		} );
 
 		it( 'should reset editables array', () => {
-			ui._editableElements.set( 'foo', {} );
-			ui._editableElements.set( 'bar', {} );
+			ui.setEditableElement( 'foo', {} );
+			ui.setEditableElement( 'bar', {} );
 
-			expect( ui._editableElements.size ).to.equal( 2 );
+			expect( [ ...ui.getEditableElementsNames() ] ).to.deep.equal( [ 'foo', 'bar' ] );
 
 			ui.destroy();
 
-			expect( ui._editableElements.size ).to.equal( 0 );
+			expect( [ ...ui.getEditableElementsNames() ] ).to.have.length( 0 );
+		} );
+
+		it( 'removes domElement#ckeditorInstance references from registered root elements', () => {
+			const fooElement = document.createElement( 'foo' );
+			const barElement = document.createElement( 'bar' );
+
+			ui.setEditableElement( 'foo', fooElement );
+			ui.setEditableElement( 'bar', barElement );
+
+			expect( fooElement.ckeditorInstance ).to.equal( editor );
+			expect( barElement.ckeditorInstance ).to.equal( editor );
+
+			ui.destroy();
+
+			expect( fooElement.ckeditorInstance ).to.be.null;
+			expect( barElement.ckeditorInstance ).to.be.null;
+		} );
+	} );
+
+	describe( 'setEditableElement()', () => {
+		it( 'should register the editable element under a name', () => {
+			const ui = new EditorUI( editor );
+			const element = document.createElement( 'div' );
+
+			ui.setEditableElement( 'main', element );
+
+			expect( ui.getEditableElement( 'main' ) ).to.equal( element );
+		} );
+
+		it( 'puts a reference to the editor instance in domElement#ckeditorInstance', () => {
+			const ui = new EditorUI( editor );
+			const element = document.createElement( 'div' );
+
+			ui.setEditableElement( 'main', element );
+
+			expect( element.ckeditorInstance ).to.equal( editor );
 		} );
 	} );
 
@@ -101,7 +138,7 @@ describe( 'EditorUI', () => {
 			const ui = new EditorUI( editor );
 			const editableMock = { name: 'main', element: document.createElement( 'div' ) };
 
-			ui._editableElements.set( editableMock.name, editableMock.element );
+			ui.setEditableElement( editableMock.name, editableMock.element );
 
 			expect( ui.getEditableElement() ).to.equal( editableMock.element );
 		} );
@@ -111,8 +148,8 @@ describe( 'EditorUI', () => {
 			const editableMock1 = { name: 'root1', element: document.createElement( 'div' ) };
 			const editableMock2 = { name: 'root2', element: document.createElement( 'p' ) };
 
-			ui._editableElements.set( editableMock1.name, editableMock1.element );
-			ui._editableElements.set( editableMock2.name, editableMock2.element );
+			ui.setEditableElement( editableMock1.name, editableMock1.element );
+			ui.setEditableElement( editableMock2.name, editableMock2.element );
 
 			expect( ui.getEditableElement( 'root1' ) ).to.equal( editableMock1.element );
 			expect( ui.getEditableElement( 'root2' ) ).to.equal( editableMock2.element );
@@ -131,8 +168,8 @@ describe( 'EditorUI', () => {
 			const editableMock1 = { name: 'main', element: document.createElement( 'div' ) };
 			const editableMock2 = { name: 'root2', element: document.createElement( 'p' ) };
 
-			ui._editableElements.set( editableMock1.name, editableMock1.element );
-			ui._editableElements.set( editableMock2.name, editableMock2.element );
+			ui.setEditableElement( editableMock1.name, editableMock1.element );
+			ui.setEditableElement( editableMock2.name, editableMock2.element );
 
 			const names = ui.getEditableElementsNames();
 			expect( names[ Symbol.iterator ] ).to.instanceof( Function );
@@ -145,4 +182,14 @@ describe( 'EditorUI', () => {
 			expect( ui.getEditableElementsNames() ).to.be.empty;
 		} );
 	} );
+
+	describe( '_editableElements()', () => {
+		it( 'should warn about deprecation', () => {
+			const ui = new EditorUI( editor );
+			const stub = testUtils.sinon.stub( log, 'warn' );
+
+			expect( ui._editableElements ).to.be.instanceOf( Map );
+			sinon.assert.calledWithMatch( stub, 'editor-ui-deprecated-editable-elements' );
+		} );
+	} );
 } );

+ 6 - 4
packages/ckeditor5-core/tests/editor/utils/attachtoform.js

@@ -7,8 +7,8 @@ import attachToForm from '../../../src/editor/utils/attachtoform';
 import ElementApiMixin from '../../../src/editor/utils/elementapimixin';
 import Editor from '../../../src/editor/editor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 /* global document, Event */
 
@@ -47,9 +47,11 @@ describe( 'attachToForm()', () => {
 	} );
 
 	it( 'should throw an error when is used with editor without `ElementApiMixin`', () => {
-		expect( () => {
-			attachToForm( new Editor() );
-		} ).to.throw( CKEditorError, /^attachtoform-missing-elementapi-interface/ );
+		const editor = new Editor();
+
+		expectToThrowCKEditorError( () => {
+			attachToForm( editor );
+		}, /^attachtoform-missing-elementapi-interface/, editor );
 	} );
 
 	it( 'should update editor#element after the "submit" event', () => {

+ 6 - 2
packages/ckeditor5-core/tests/editor/utils/elementapimixin.js

@@ -9,7 +9,7 @@ import ElementApiMixin from '../../../src/editor/utils/elementapimixin';
 import Editor from '../../../src/editor/editor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'ElementApiMixin', () => {
 	let editor;
@@ -46,7 +46,11 @@ describe( 'ElementApiMixin', () => {
 		} );
 
 		it( 'throws an error if "sourceElement" has not been set', () => {
-			expect( () => editor.updateSourceElement() ).to.throw( CKEditorError, /editor-missing-sourceelement/ );
+			expectToThrowCKEditorError(
+				() => editor.updateSourceElement(),
+				/editor-missing-sourceelement/,
+				editor
+			);
 		} );
 	} );
 } );

+ 124 - 0
packages/ckeditor5-core/tests/multicommand.js

@@ -0,0 +1,124 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import MultiCommand from '../src/multicommand';
+import ModelTestEditor from './_utils/modeltesteditor';
+import Command from '../src/command';
+
+describe( 'MultiCommand', () => {
+	let editor, multiCommand;
+
+	beforeEach( () => {
+		return ModelTestEditor
+			.create()
+			.then( newEditor => {
+				editor = newEditor;
+				multiCommand = new MultiCommand( editor );
+			} );
+	} );
+
+	afterEach( () => {
+		multiCommand.destroy();
+
+		return editor.destroy();
+	} );
+
+	describe( 'isEnabled', () => {
+		it( 'is always falsy when no child commands are registered', () => {
+			expect( multiCommand.isEnabled ).to.false;
+
+			multiCommand.refresh();
+
+			expect( multiCommand.isEnabled ).to.false;
+		} );
+
+		it( 'is set to true if one of registered commands is true', () => {
+			expect( multiCommand.isEnabled ).to.false;
+
+			const commandA = new Command( editor );
+			const commandB = new Command( editor );
+
+			multiCommand.registerChildCommand( commandA );
+			multiCommand.registerChildCommand( commandB );
+
+			expect( multiCommand.isEnabled ).to.false;
+
+			commandA.isEnabled = true;
+
+			expect( multiCommand.isEnabled ).to.be.true;
+
+			commandA.isEnabled = false;
+
+			expect( multiCommand.isEnabled ).to.be.false;
+
+			commandB.isEnabled = true;
+
+			expect( multiCommand.isEnabled ).to.be.true;
+		} );
+	} );
+
+	describe( 'execute()', () => {
+		it( 'does not call any command if all are disabled', () => {
+			const commandA = new Command( editor );
+			const commandB = new Command( editor );
+
+			multiCommand.registerChildCommand( commandA );
+			multiCommand.registerChildCommand( commandB );
+
+			const spyA = sinon.spy( commandA, 'execute' );
+			const spyB = sinon.spy( commandB, 'execute' );
+
+			multiCommand.execute();
+
+			sinon.assert.notCalled( spyA );
+			sinon.assert.notCalled( spyB );
+		} );
+
+		it( 'executes enabled command', () => {
+			const commandA = new Command( editor );
+			const commandB = new Command( editor );
+			const commandC = new Command( editor );
+
+			multiCommand.registerChildCommand( commandA );
+			multiCommand.registerChildCommand( commandB );
+			multiCommand.registerChildCommand( commandC );
+
+			const spyA = sinon.spy( commandA, 'execute' );
+			const spyB = sinon.spy( commandB, 'execute' );
+			const spyC = sinon.spy( commandC, 'execute' );
+
+			commandC.isEnabled = true;
+
+			multiCommand.execute();
+
+			sinon.assert.notCalled( spyA );
+			sinon.assert.notCalled( spyB );
+			sinon.assert.calledOnce( spyC );
+		} );
+
+		it( 'executes first registered command if many are enabled', () => {
+			const commandA = new Command( editor );
+			const commandB = new Command( editor );
+			const commandC = new Command( editor );
+
+			multiCommand.registerChildCommand( commandA );
+			multiCommand.registerChildCommand( commandB );
+			multiCommand.registerChildCommand( commandC );
+
+			const spyA = sinon.spy( commandA, 'execute' );
+			const spyB = sinon.spy( commandB, 'execute' );
+			const spyC = sinon.spy( commandC, 'execute' );
+
+			commandC.isEnabled = true;
+			commandB.isEnabled = true;
+
+			multiCommand.execute();
+
+			sinon.assert.notCalled( spyA );
+			sinon.assert.calledOnce( spyB );
+			sinon.assert.notCalled( spyC );
+		} );
+	} );
+} );

+ 3 - 3
packages/ckeditor5-core/tests/pendingactions.js

@@ -5,7 +5,7 @@
 
 import VirtualTestEditor from './_utils/virtualtesteditor';
 import PendingActions from '../src/pendingactions';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 let editor, pendingActions;
 
@@ -69,9 +69,9 @@ describe( 'PendingActions', () => {
 		} );
 
 		it( 'should throw an error when invalid message is given', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				pendingActions.add( {} );
-			} ).to.throw( CKEditorError, /^pendingactions-add-invalid-message/ );
+			}, /^pendingactions-add-invalid-message/, editor );
 		} );
 
 		it( 'should fire add event with added item', () => {

+ 13 - 15
packages/ckeditor5-core/tests/plugincollection.js

@@ -9,8 +9,8 @@ import testUtils from '../tests/_utils/utils';
 import Editor from '../src/editor/editor';
 import PluginCollection from '../src/plugincollection';
 import Plugin from '../src/plugin';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import log from '@ckeditor/ckeditor5-utils/src/log';
+import { expectToThrowCKEditorError, assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 let editor, availablePlugins;
 let PluginA, PluginB, PluginC, PluginD, PluginE, PluginF, PluginG, PluginH, PluginI, PluginJ, PluginK, PluginX, PluginFoo, AnotherPluginFoo;
@@ -269,8 +269,7 @@ describe( 'PluginCollection', () => {
 					throw new Error( 'Test error: this promise should not be resolved successfully' );
 				} )
 				.catch( err => {
-					expect( err ).to.be.an.instanceof( CKEditorError );
-					expect( err.message ).to.match( /^plugincollection-plugin-not-found/ );
+					assertCKEditorError( err, /^plugincollection-plugin-not-found/, editor );
 
 					sinon.assert.calledOnce( logSpy );
 					expect( logSpy.args[ 0 ][ 0 ] ).to.match( /^plugincollection-plugin-not-found:/ );
@@ -344,13 +343,12 @@ describe( 'PluginCollection', () => {
 			const plugins = new PluginCollection( editor, availablePlugins );
 
 			return plugins.init( [ PluginA, PluginB, PluginC, PluginD ], [ PluginA, PluginB ] )
-				// Throw here, so if by any chance plugins.init() was resolved correctly catch() will be stil executed.
+				// Throw here, so if by any chance plugins.init() was resolved correctly catch() will be still executed.
 				.then( () => {
 					throw new Error( 'Test error: this promise should not be resolved successfully' );
 				} )
 				.catch( err => {
-					expect( err ).to.be.an.instanceof( CKEditorError );
-					expect( err.message ).to.match( /^plugincollection-required/ );
+					assertCKEditorError( err, /^plugincollection-required/, editor );
 
 					expect( logSpy.calledTwice ).to.equal( true );
 				} );
@@ -453,9 +451,9 @@ describe( 'PluginCollection', () => {
 			const plugins = new PluginCollection( editor, availablePlugins );
 
 			return plugins.init( [] ).then( () => {
-				expect( () => plugins.get( 'foo' ) )
-					.to.throw( CKEditorError, /^plugincollection-plugin-not-loaded:/ )
-					.with.deep.property( 'data', { plugin: 'foo' } );
+				expectToThrowCKEditorError( () => plugins.get( 'foo' ),
+					/^plugincollection-plugin-not-loaded:/, editor, { plugin: 'foo' }
+				);
 			} );
 		} );
 
@@ -466,9 +464,8 @@ describe( 'PluginCollection', () => {
 			const plugins = new PluginCollection( editor, availablePlugins );
 
 			return plugins.init( [] ).then( () => {
-				expect( () => plugins.get( SomePlugin ) )
-					.to.throw( CKEditorError, /^plugincollection-plugin-not-loaded:/ )
-					.with.deep.property( 'data', { plugin: 'foo' } );
+				expectToThrowCKEditorError( () => plugins.get( SomePlugin ),
+					/^plugincollection-plugin-not-loaded:/, editor, { plugin: 'foo' } );
 			} );
 		} );
 
@@ -478,9 +475,10 @@ describe( 'PluginCollection', () => {
 			const plugins = new PluginCollection( editor, availablePlugins );
 
 			return plugins.init( [] ).then( () => {
-				expect( () => plugins.get( SomePlugin ) )
-					.to.throw( CKEditorError, /^plugincollection-plugin-not-loaded:/ )
-					.with.deep.property( 'data', { plugin: 'SomePlugin' } );
+				expectToThrowCKEditorError( () => plugins.get( SomePlugin ),
+					/^plugincollection-plugin-not-loaded:/,
+					editor, { plugin: 'SomePlugin' }
+				);
 			} );
 		} );
 	} );