8
0
Piotrek Koszuliński 8 лет назад
Родитель
Сommit
ee817be05d

+ 22 - 31
packages/ckeditor5-core/src/command/toggleattributecommand.js

@@ -7,7 +7,7 @@
  * @module core/command/toggleattributecommand
  */
 
-import Command from './command';
+import Command from '../command';
 import getSchemaValidRanges from './helpers/getschemavalidranges';
 import isAttributeAllowedInSelection from './helpers/isattributeallowedinselection';
 
@@ -17,10 +17,11 @@ import isAttributeAllowedInSelection from './helpers/isattributeallowedinselecti
  * to decide which nodes (if any) should be changed, and applies or removes attributes from them.
  *
  * The command checks {@link module:engine/model/document~Document#schema} to decide if it should be enabled.
+ *
+ * @extends module:core/command~Command
  */
 export default class ToggleAttributeCommand extends Command {
 	/**
-	 * @see module:core/command/command~Command
 	 * @param {module:core/editor/editor~Editor} editor
 	 * @param {String} attributeKey Attribute that will be set by the command.
 	 */
@@ -30,43 +31,29 @@ export default class ToggleAttributeCommand extends Command {
 		/**
 		 * Attribute that will be set by the command.
 		 *
+		 * @readonly
 		 * @member {String}
 		 */
 		this.attributeKey = attributeKey;
 
 		/**
-		 * Flag indicating whether command is active. For collapsed selection it means that typed characters will have
+		 * Flag indicating whether the command is active. For collapsed selection it means that typed characters will have
 		 * the command's attribute set. For range selection it means that all nodes inside have the attribute applied.
 		 *
 		 * @observable
+		 * @readonly
 		 * @member {Boolean} #value
 		 */
-		this.set( 'value', false );
-
-		this.listenTo( editor.document, 'changesDone', () => {
-			this.refreshValue();
-			this.refreshState();
-		} );
 	}
 
 	/**
-	 * Updates command's {@link #value value} based on the current selection.
+	 * Updates command's {@link #value} based on the current selection.
 	 */
-	refreshValue() {
-		this.value = this.editor.document.selection.hasAttribute( this.attributeKey );
-	}
+	refresh() {
+		const doc = this.editor.document;
 
-	/**
-	 * Checks if {@link module:engine/model/document~Document#schema} allows to create attribute in
-	 * {@link module:engine/model/document~Document#selection}.
-	 *
-	 * @private
-	 * @returns {Boolean}
-	 */
-	_checkEnabled() {
-		const document = this.editor.document;
-
-		return isAttributeAllowedInSelection( this.attributeKey, document.selection, document.schema );
+		this.value = doc.selection.hasAttribute( this.attributeKey );
+		this.isEnabled = isAttributeAllowedInSelection( this.attributeKey, doc.selection, doc.schema );
 	}
 
 	/**
@@ -84,19 +71,23 @@ export default class ToggleAttributeCommand extends Command {
 	 *
 	 * If the command is disabled (`isEnabled == false`) when it is executed, nothing will happen.
 	 *
-	 * @private
+	 * @fires execute
 	 * @param {Object} [options] Options of command.
 	 * @param {Boolean} [options.forceValue] If set it will force command behavior. If `true`, command will apply attribute,
 	 * otherwise command will remove attribute. If not set, command will look for it's current value to decide what it should do.
 	 * @param {module:engine/model/batch~Batch} [options.batch] Batch to group undo steps.
 	 */
-	_doExecute( options = {} ) {
-		const document = this.editor.document;
-		const selection = document.selection;
+	execute( options = {} ) {
+		if ( !this.isEnabled ) {
+			return;
+		}
+
+		const doc = this.editor.document;
+		const selection = doc.selection;
 		const value = ( options.forceValue === undefined ) ? !this.value : options.forceValue;
 
 		// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges.
-		document.enqueueChanges( () => {
+		doc.enqueueChanges( () => {
 			if ( selection.isCollapsed ) {
 				if ( value ) {
 					selection.setAttribute( this.attributeKey, true );
@@ -104,10 +95,10 @@ export default class ToggleAttributeCommand extends Command {
 					selection.removeAttribute( this.attributeKey );
 				}
 			} else {
-				const ranges = getSchemaValidRanges( this.attributeKey, selection.getRanges(), document.schema );
+				const ranges = getSchemaValidRanges( this.attributeKey, selection.getRanges(), doc.schema );
 
 				// Keep it as one undo step.
-				const batch = options.batch || document.batch();
+				const batch = options.batch || doc.batch();
 
 				for ( const range of ranges ) {
 					if ( value ) {

+ 2 - 11
packages/ckeditor5-core/src/commandcollection.js

@@ -43,7 +43,7 @@ export default class CommandCollection {
 	 * @returns {module:core/command~CommandInterface}
 	 */
 	get( commandName ) {
-		this._commands.get( commandName );
+		return this._commands.get( commandName );
 	}
 
 	/**
@@ -93,16 +93,7 @@ export default class CommandCollection {
 	}
 
 	/**
-	 * Refreshes all commands.
-	 */
-	refreshAll() {
-		for ( const command of this.commands() ) {
-			command.refresh();
-		}
-	}
-
-	/**
-	 * Destroys the collection and all its commands.
+	 * Destroys all collection commands.
 	 */
 	destroy() {
 		for ( const command of this.commands() ) {

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

@@ -9,7 +9,7 @@
 
 import Config from '@ckeditor/ckeditor5-utils/src/config';
 import PluginCollection from '../plugincollection';
-import CommandCollection from './commandcollection';
+import CommandCollection from '../commandcollection';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 import DataController from '@ckeditor/ckeditor5-engine/src/controller/datacontroller';
 import Document from '@ckeditor/ckeditor5-engine/src/model/document';

+ 88 - 0
packages/ckeditor5-core/tests/command.js

@@ -0,0 +1,88 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import Command from '../src/command';
+import ModelTestEditor from './_utils/modeltesteditor';
+
+class SomeCommand extends Command {
+	execute() {}
+
+	refresh() {}
+}
+
+describe( 'Command', () => {
+	let editor, command;
+
+	beforeEach( () => {
+		return ModelTestEditor
+			.create()
+			.then( newEditor => {
+				editor = newEditor;
+				command = new SomeCommand( editor );
+			} );
+	} );
+
+	afterEach( () => {
+		command.destroy();
+
+		return editor.destroy();
+	} );
+
+	describe( 'constructor()', () => {
+		it( 'sets the editor property', () => {
+			expect( command.editor ).to.equal( editor );
+		} );
+
+		it( 'sets the state properties', () => {
+			expect( command.value ).to.be.null;
+			expect( command.isEnabled ).to.be.false;
+		} );
+
+		it( 'adds a listener which refreshed the command on editor.document#changesDone', () => {
+			sinon.spy( command, 'refresh' );
+
+			editor.document.fire( 'changesDone' );
+
+			expect( command.refresh.calledOnce ).to.be.true;
+		} );
+	} );
+
+	describe( 'value', () => {
+		it( 'fires change event', () => {
+			const spy = sinon.spy();
+
+			command.on( 'change:value', spy );
+
+			command.value = 1;
+
+			expect( spy.calledOnce ).to.be.true;
+		} );
+	} );
+
+	describe( 'isEnabled', () => {
+		it( 'fires change event', () => {
+			const spy = sinon.spy();
+
+			command.on( 'change:isEnabled', spy );
+
+			command.isEnabled = true;
+
+			expect( spy.calledOnce ).to.be.true;
+		} );
+	} );
+
+	describe( 'execute()', () => {
+		it( 'is decorated', () => {
+			const spy = sinon.spy();
+
+			command.on( 'execute', spy );
+
+			command.execute( 1, 2 );
+
+			expect( spy.calledOnce ).to.be.true;
+			expect( spy.args[ 0 ][ 1 ] ).to.deep.equal( [ 1, 2 ] );
+		} );
+	} );
+} );

+ 58 - 66
packages/ckeditor5-core/tests/command/toggleattributecommand.js

@@ -44,21 +44,15 @@ describe( 'ToggleAttributeCommand', () => {
 	} );
 
 	describe( 'value', () => {
-		// https://github.com/ckeditor/ckeditor5-core/issues/50
-		it( 'should be updated on document#changesDone', () => {
-			const spy = sinon.spy( command, 'refreshValue' );
-
-			modelDoc.fire( 'changesDone' );
-			sinon.assert.calledOnce( spy );
-		} );
-
-		it( 'should be set to true or false basing on selection attribute', () => {
+		it( 'is true when selection has the attribute', () => {
 			modelDoc.enqueueChanges( () => {
 				modelDoc.selection.setAttribute( attrKey, true );
 			} );
 
 			expect( command.value ).to.be.true;
+		} );
 
+		it( 'is false when selection does not have the attribute', () => {
 			modelDoc.enqueueChanges( () => {
 				modelDoc.selection.removeAttribute( attrKey );
 			} );
@@ -67,23 +61,57 @@ describe( 'ToggleAttributeCommand', () => {
 		} );
 	} );
 
-	describe( 'state', () => {
-		// https://github.com/ckeditor/ckeditor5-core/issues/50
-		it( 'should be updated on document#changesDone', () => {
-			const spy = sinon.spy( command, 'refreshState' );
+	describe( 'isEnabled', () => {
+		// This test doesn't tests every possible case.
+		// Method `refresh()` uses `isAttributeAllowedInSelection` helper which is fully tested in his own test.
+
+		beforeEach( () => {
+			modelDoc.schema.registerItem( 'x', '$block' );
+			modelDoc.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
+		} );
+
+		describe( 'when selection is collapsed', () => {
+			it( 'should return true if characters with the attribute can be placed at caret position', () => {
+				setData( modelDoc, '<p>f[]oo</p>' );
+				expect( command.isEnabled ).to.be.true;
+			} );
+
+			it( 'should return false if characters with the attribute cannot be placed at caret position', () => {
+				setData( modelDoc, '<x>fo[]o</x>' );
+				expect( command.isEnabled ).to.be.false;
+			} );
+		} );
+
+		describe( 'when selection is not collapsed', () => {
+			it( 'should return true if there is at least one node in selection that can have the attribute', () => {
+				setData( modelDoc, '<p>[foo]</p>' );
+				expect( command.isEnabled ).to.be.true;
+			} );
 
-			modelDoc.fire( 'changesDone' );
-			sinon.assert.calledOnce( spy );
+			it( 'should return false if there are no nodes in selection that can have the attribute', () => {
+				setData( modelDoc, '<x>[foo]</x>' );
+				expect( command.isEnabled ).to.be.false;
+			} );
 		} );
 	} );
 
-	describe( '_doExecute', () => {
+	describe( 'execute()', () => {
+		it( 'should do nothing if the command is disabled', () => {
+			setData( modelDoc, '<p>fo[ob]ar</p>' );
+
+			command.isEnabled = false;
+
+			command.execute();
+
+			expect( getData( modelDoc ) ).to.equal( '<p>fo[ob]ar</p>' );
+		} );
+
 		it( 'should add attribute on selected nodes if the command value was false', () => {
 			setData( modelDoc, '<p>a[bc<$text bold="true">fo]obar</$text>xyz</p>' );
 
 			expect( command.value ).to.be.false;
 
-			command._doExecute();
+			command.execute();
 
 			expect( command.value ).to.be.true;
 			expect( getData( modelDoc ) ).to.equal( '<p>a[<$text bold="true">bcfo]obar</$text>xyz</p>' );
@@ -94,7 +122,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 			expect( command.value ).to.be.true;
 
-			command._doExecute();
+			command.execute();
 
 			expect( getData( modelDoc ) ).to.equal( '<p>abc[foo]<$text bold="true">bar</$text>xyz</p>' );
 			expect( command.value ).to.be.false;
@@ -105,7 +133,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 			expect( command.value ).to.be.true;
 
-			command._doExecute( { forceValue: true } );
+			command.execute( { forceValue: true } );
 
 			expect( command.value ).to.be.true;
 			expect( getData( modelDoc ) ).to.equal( '<p>abc<$text bold="true">foob[arx</$text>]yz</p>' );
@@ -114,7 +142,7 @@ describe( 'ToggleAttributeCommand', () => {
 		it( 'should remove attribute on selected nodes if execute parameter was set to false', () => {
 			setData( modelDoc, '<p>a[bc<$text bold="true">fo]obar</$text>xyz</p>' );
 
-			command._doExecute( { forceValue: false } );
+			command.execute( { forceValue: false } );
 
 			expect( command.value ).to.be.false;
 			expect( getData( modelDoc ) ).to.equal( '<p>a[bcfo]<$text bold="true">obar</$text>xyz</p>' );
@@ -125,12 +153,12 @@ describe( 'ToggleAttributeCommand', () => {
 
 			expect( command.value ).to.be.false;
 
-			command._doExecute();
+			command.execute();
 
 			expect( command.value ).to.be.true;
 			expect( modelDoc.selection.hasAttribute( 'bold' ) ).to.be.true;
 
-			command._doExecute();
+			command.execute();
 
 			expect( command.value ).to.be.false;
 			expect( modelDoc.selection.hasAttribute( 'bold' ) ).to.be.false;
@@ -139,7 +167,7 @@ describe( 'ToggleAttributeCommand', () => {
 		it( 'should not store attribute change on selection if selection is collapsed in non-empty parent', () => {
 			setData( modelDoc, '<p>a[]bc<$text bold="true">foobar</$text>xyz</p>' );
 
-			command._doExecute();
+			command.execute();
 
 			// It should not save that bold was executed at position ( root, [ 0, 1 ] ).
 
@@ -159,7 +187,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 			expect( command.value ).to.be.false;
 
-			command._doExecute();
+			command.execute();
 
 			expect( command.value ).to.be.true;
 			expect( modelDoc.selection.hasAttribute( 'bold' ) ).to.be.true;
@@ -180,7 +208,7 @@ describe( 'ToggleAttributeCommand', () => {
 			// Attribute should be restored.
 			expect( command.value ).to.be.true;
 
-			command._doExecute();
+			command.execute();
 
 			expect( command.value ).to.be.false;
 			expect( modelDoc.selection.hasAttribute( 'bold' ) ).to.be.false;
@@ -192,7 +220,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 			expect( command.isEnabled ).to.be.true;
 
-			command._doExecute();
+			command.execute();
 
 			expect( getData( modelDoc ) )
 				.to.equal( '<p>ab[<$text bold="true">c</$text><img></img><$text bold="true">foobarxy</$text><img></img>]z</p>' );
@@ -204,7 +232,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 			expect( batch.deltas.length ).to.equal( 0 );
 
-			command._doExecute( { batch } );
+			command.execute( { batch } );
 
 			expect( batch.deltas.length ).to.equal( 1 );
 			expect( getData( modelDoc ) ).to.equal( '<p>a[<$text bold="true">bcfo]obar</$text>xyz</p>' );
@@ -222,7 +250,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 				modelDoc.on( 'changesDone', spy );
 
-				command._doExecute();
+				command.execute();
 
 				expect( spy.calledOnce ).to.be.true;
 			} );
@@ -232,7 +260,7 @@ describe( 'ToggleAttributeCommand', () => {
 
 				modelDoc.on( 'changesDone', spy );
 
-				command._doExecute();
+				command.execute();
 
 				expect( spy.calledOnce ).to.be.true;
 			} );
@@ -242,46 +270,10 @@ describe( 'ToggleAttributeCommand', () => {
 
 				modelDoc.on( 'changesDone', spy );
 
-				command._doExecute();
+				command.execute();
 
 				expect( spy.calledOnce ).to.be.true;
 			} );
 		} );
 	} );
-
-	describe( '_checkEnabled', () => {
-		describe( '_checkEnabled', () => {
-			// This test doesn't tests every possible case.
-			// Method `_checkEnabled` uses `isAttributeAllowedInSelection` helper which is fully tested in his own test.
-
-			beforeEach( () => {
-				modelDoc.schema.registerItem( 'x', '$block' );
-				modelDoc.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
-			} );
-
-			describe( 'when selection is collapsed', () => {
-				it( 'should return true if characters with the attribute can be placed at caret position', () => {
-					setData( modelDoc, '<p>f[]oo</p>' );
-					expect( command._checkEnabled() ).to.be.true;
-				} );
-
-				it( 'should return false if characters with the attribute cannot be placed at caret position', () => {
-					setData( modelDoc, '<x>fo[]o</x>' );
-					expect( command._checkEnabled() ).to.be.false;
-				} );
-			} );
-
-			describe( 'when selection is not collapsed', () => {
-				it( 'should return true if there is at least one node in selection that can have the attribute', () => {
-					setData( modelDoc, '<p>[foo]</p>' );
-					expect( command._checkEnabled() ).to.be.true;
-				} );
-
-				it( 'should return false if there are no nodes in selection that can have the attribute', () => {
-					setData( modelDoc, '<x>[foo]</x>' );
-					expect( command._checkEnabled() ).to.be.false;
-				} );
-			} );
-		} );
-	} );
 } );

+ 138 - 0
packages/ckeditor5-core/tests/commandcollection.js

@@ -0,0 +1,138 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import CommandCollection from '../src/commandcollection';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import Command from '../src/command';
+import ModelTestEditor from './_utils/modeltesteditor';
+
+class SomeCommand extends Command {
+	execute() {}
+}
+
+describe( 'CommandCollection', () => {
+	let collection, editor;
+
+	beforeEach( () => {
+		collection = new CommandCollection();
+
+		return ModelTestEditor
+			.create()
+			.then( newEditor => {
+				editor = newEditor;
+			} );
+	} );
+
+	afterEach( () => {
+		collection.destroy();
+
+		return editor.destroy();
+	} );
+
+	describe( 'add() and get()', () => {
+		it( 'adds and retrieves a command', () => {
+			const command = new SomeCommand( editor );
+
+			collection.add( 'foo', command );
+
+			expect( collection.get( 'foo' ) ).to.equal( command );
+		} );
+	} );
+
+	describe( 'execute()', () => {
+		it( 'executes given method with given attributes', () => {
+			const command = new SomeCommand( editor );
+
+			sinon.spy( command, 'execute' );
+
+			collection.add( 'foo', command );
+
+			collection.execute( 'foo', 1, 2 );
+
+			expect( command.execute.calledOnce ).to.be.true;
+			expect( command.execute.args[ 0 ] ).to.deep.equal( [ 1, 2 ] );
+		} );
+
+		it( 'throws an error if command does not exist', () => {
+			expect( () => {
+				collection.execute( 'foo' );
+			} ).to.throw( CKEditorError, /^commandcollection-command-not-found:/ );
+		} );
+	} );
+
+	describe( 'names()', () => {
+		it( 'returns iterator', () => {
+			const names = collection.names();
+
+			expect( names.next ).to.be.a.function;
+		} );
+
+		it( 'returns iterator of command names', () => {
+			collection.add( 'foo', new SomeCommand( editor ) );
+			collection.add( 'bar', new SomeCommand( editor ) );
+
+			expect( Array.from( collection.names() ) ).to.have.members( [ 'foo', 'bar' ] );
+		} );
+	} );
+
+	describe( 'commands()', () => {
+		it( 'returns iterator', () => {
+			const commands = collection.commands();
+
+			expect( commands.next ).to.be.a.function;
+		} );
+
+		it( 'returns iterator of commands', () => {
+			const c1 = new SomeCommand( editor );
+			const c2 = new SomeCommand( editor );
+
+			collection.add( 'foo', c1 );
+			collection.add( 'bar', c2 );
+
+			const commandArray = Array.from( collection.commands() );
+
+			expect( commandArray ).to.have.length( 2 );
+			expect( commandArray ).to.have.members( [ c1, c2 ] );
+		} );
+	} );
+
+	describe( 'iterator', () => {
+		it( 'exists', () => {
+			expect( collection ).to.have.property( Symbol.iterator );
+		} );
+
+		it( 'returns iterator of [ name, command ]', () => {
+			const c1 = new SomeCommand( editor );
+			const c2 = new SomeCommand( editor );
+
+			collection.add( 'foo', c1 );
+			collection.add( 'bar', c2 );
+
+			const collectionArray = Array.from( collection );
+
+			expect( collectionArray ).to.have.length( 2 );
+			expect( collectionArray.map( pair => pair[ 0 ] ) ).to.have.members( [ 'foo', 'bar' ] );
+			expect( collectionArray.map( pair => pair[ 1 ] ) ).to.have.members( [ c1, c2 ] );
+		} );
+	} );
+
+	describe( 'commands()', () => {
+		it( 'returns iterator of commands', () => {
+			const c1 = new SomeCommand( editor );
+			const c2 = new SomeCommand( editor );
+
+			sinon.spy( c1, 'destroy' );
+			sinon.spy( c2, 'destroy' );
+
+			collection.add( 'foo', c1 );
+			collection.add( 'bar', c2 );
+
+			collection.destroy();
+
+			expect( c1.destroy.calledOnce ).to.be.true;
+			expect( c2.destroy.calledOnce ).to.be.true;
+		} );
+	} );
+} );

+ 0 - 74
packages/ckeditor5-core/tests/editor/editor-base.js

@@ -1,74 +0,0 @@
-/**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import Editor from '../../src/editor/editor';
-import Command from '../../src/command/command';
-import Locale from '@ckeditor/ckeditor5-utils/src/locale';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-
-describe( 'Editor', () => {
-	describe( 'locale', () => {
-		it( 'is instantiated and t() is exposed', () => {
-			const editor = new Editor();
-
-			expect( editor.locale ).to.be.instanceof( Locale );
-			expect( editor.t ).to.equal( editor.locale.t );
-		} );
-
-		it( 'is configured with the config.lang', () => {
-			const editor = new Editor( { lang: 'pl' } );
-
-			expect( editor.locale.lang ).to.equal( 'pl' );
-		} );
-	} );
-
-	describe( 'destroy', () => {
-		it( 'should fire "destroy"', () => {
-			const editor = new Editor();
-			const spy = sinon.spy();
-
-			editor.on( 'destroy', spy );
-
-			return editor.destroy().then( () => {
-				expect( spy.calledOnce ).to.be.true;
-			} );
-		} );
-
-		it( 'should destroy all components it initialized', () => {
-			const editor = new Editor();
-
-			const spy1 = sinon.spy( editor.data, 'destroy' );
-			const spy2 = sinon.spy( editor.document, 'destroy' );
-
-			return editor.destroy()
-				.then( () => {
-					expect( spy1.calledOnce ).to.be.true;
-					expect( spy2.calledOnce ).to.be.true;
-				} );
-		} );
-	} );
-
-	describe( 'execute', () => {
-		it( 'should execute specified command', () => {
-			const editor = new Editor();
-
-			const command = new Command( editor );
-			sinon.spy( command, '_execute' );
-
-			editor.commands.set( 'commandName', command );
-			editor.execute( 'commandName' );
-
-			expect( command._execute.calledOnce ).to.be.true;
-		} );
-
-		it( 'should throw an error if specified command has not been added', () => {
-			const editor = new Editor();
-
-			expect( () => {
-				editor.execute( 'command' );
-			} ).to.throw( CKEditorError, /^editor-command-not-found:/ );
-		} );
-	} );
-} );

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

@@ -9,6 +9,10 @@ import Editor from '../../src/editor/editor';
 import Plugin from '../../src/plugin';
 import Config from '@ckeditor/ckeditor5-utils/src/config';
 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';
 
 class PluginA extends Plugin {
 	constructor( editor ) {
@@ -98,7 +102,7 @@ describe( 'Editor', () => {
 			const editor = new Editor();
 
 			expect( editor.config ).to.be.an.instanceof( Config );
-			expect( editor.commands ).to.be.an.instanceof( Map );
+			expect( editor.commands ).to.be.an.instanceof( CommandCollection );
 
 			expect( editor.plugins ).to.be.an.instanceof( PluginCollection );
 			expect( getPlugins( editor ) ).to.be.empty;
@@ -139,7 +143,74 @@ describe( 'Editor', () => {
 		} );
 	} );
 
-	describe( 'create', () => {
+	describe( 'locale', () => {
+		it( 'is instantiated and t() is exposed', () => {
+			const editor = new Editor();
+
+			expect( editor.locale ).to.be.instanceof( Locale );
+			expect( editor.t ).to.equal( editor.locale.t );
+		} );
+
+		it( 'is configured with the config.lang', () => {
+			const editor = new Editor( { lang: 'pl' } );
+
+			expect( editor.locale.lang ).to.equal( 'pl' );
+		} );
+	} );
+
+	describe( 'destroy()', () => {
+		it( 'should fire "destroy"', () => {
+			const editor = new Editor();
+			const spy = sinon.spy();
+
+			editor.on( 'destroy', spy );
+
+			return editor.destroy().then( () => {
+				expect( spy.calledOnce ).to.be.true;
+			} );
+		} );
+
+		it( 'should destroy all components it initialized', () => {
+			const editor = new Editor();
+
+			const spy1 = sinon.spy( editor.data, 'destroy' );
+			const spy2 = sinon.spy( editor.document, 'destroy' );
+
+			return editor.destroy()
+				.then( () => {
+					expect( spy1.calledOnce ).to.be.true;
+					expect( spy2.calledOnce ).to.be.true;
+				} );
+		} );
+	} );
+
+	describe( 'execute()', () => {
+		it( 'should execute specified command', () => {
+			class SomeCommand extends Command {
+				execute() {}
+			}
+
+			const editor = new Editor();
+
+			const command = new SomeCommand( editor );
+			sinon.spy( command, 'execute' );
+
+			editor.commands.add( 'someCommand', command );
+			editor.execute( 'someCommand' );
+
+			expect( command.execute.calledOnce ).to.be.true;
+		} );
+
+		it( 'should throw an error if specified command has not been added', () => {
+			const editor = new Editor();
+
+			expect( () => {
+				editor.execute( 'command' );
+			} ).to.throw( CKEditorError, /^commandcollection-command-not-found:/ );
+		} );
+	} );
+
+	describe( 'create()', () => {
 		it( 'should return a promise that resolves properly', () => {
 			const promise = Editor.create();
 
@@ -179,7 +250,7 @@ describe( 'Editor', () => {
 		} );
 	} );
 
-	describe( 'initPlugins', () => {
+	describe( 'initPlugins()', () => {
 		it( 'should load plugins', () => {
 			const editor = new Editor( {
 				plugins: [ PluginA, PluginB ]