8
0
Pārlūkot izejas kodu

Aligned operation tests with engine changes.

Oskar Wróbel 8 gadi atpakaļ
vecāks
revīzija
7b14364940

+ 1 - 1
packages/ckeditor5-engine/src/model/operation/markeroperation.js

@@ -146,7 +146,7 @@ export default class MarkerOperation extends Operation {
 			json.name,
 			json.oldRange ? Range.fromJSON( json.oldRange, document ) : null,
 			json.newRange ? Range.fromJSON( json.newRange, document ) : null,
-			document.markers,
+			document.model.markers,
 			json.baseVersion
 		);
 	}

+ 88 - 68
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -3,7 +3,8 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../src/model/document';
+import Model from '../../src/model/model';
+import Batch from '../../src/model/batch';
 import Element from '../../src/model/element';
 import Text from '../../src/model/text';
 import Range from '../../src/model/range';
@@ -26,13 +27,14 @@ import log from '@ckeditor/ckeditor5-utils/src/log';
 testUtils.createSinonSandbox();
 
 describe( 'DocumentSelection', () => {
-	let doc, root, selection, liveRange, range;
+	let model, doc, root, selection, liveRange, range;
 
 	const fooStoreAttrKey = DocumentSelection._getStoreAttributeKey( 'foo' );
 	const abcStoreAttrKey = DocumentSelection._getStoreAttributeKey( 'abc' );
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 		root.appendChildren( [
 			new Element( 'p' ),
@@ -44,17 +46,17 @@ describe( 'DocumentSelection', () => {
 			new Element( 'p', [], new Text( 'foobar' ) )
 		] );
 		selection = doc.selection;
-		doc.schema.registerItem( 'p', '$block' );
+		model.schema.registerItem( 'p', '$block' );
 
-		doc.schema.registerItem( 'widget' );
-		doc.schema.objects.add( 'widget' );
+		model.schema.registerItem( 'widget' );
+		model.schema.objects.add( 'widget' );
 
 		liveRange = new LiveRange( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
 		range = new Range( new Position( root, [ 2 ] ), new Position( root, [ 2, 2 ] ) );
 	} );
 
 	afterEach( () => {
-		doc.destroy();
+		model.destroy();
 		liveRange.detach();
 	} );
 
@@ -69,7 +71,8 @@ describe( 'DocumentSelection', () => {
 		} );
 
 		it( 'should be set to the beginning of the doc if there is no editable element', () => {
-			doc = new Document();
+			model = new Model();
+			doc = model.document;
 			root = doc.createRoot();
 			root.insertChildren( 0, new Text( 'foobar' ) );
 			selection = doc.selection;
@@ -84,14 +87,15 @@ describe( 'DocumentSelection', () => {
 		} );
 
 		it( 'should skip element when you can not put selection', () => {
-			doc = new Document();
+			model = new Model();
+			doc = model.document;
 			root = doc.createRoot();
 			root.insertChildren( 0, [
 				new Element( 'img' ),
 				new Element( 'p', [], new Text( 'foobar' ) )
 			] );
-			doc.schema.registerItem( 'img' );
-			doc.schema.registerItem( 'p', '$block' );
+			model.schema.registerItem( 'img' );
+			model.schema.registerItem( 'p', '$block' );
 			selection = doc.selection;
 
 			const ranges = Array.from( selection.getRanges() );
@@ -356,16 +360,16 @@ describe( 'DocumentSelection', () => {
 
 		// See #630.
 		it( 'should refresh attributes – integration test for #630', () => {
-			doc.schema.allow( { name: '$text', inside: '$root' } );
+			model.schema.allow( { name: '$text', inside: '$root' } );
 
-			setData( doc, 'f<$text italic="true">[o</$text><$text bold="true">ob]a</$text>r' );
+			setData( model, 'f<$text italic="true">[o</$text><$text bold="true">ob]a</$text>r' );
 
 			selection.setRanges( [ Range.createFromPositionAndShift( selection.getLastRange().end, 0 ) ] );
 
 			expect( selection.getAttribute( 'bold' ) ).to.equal( true );
 			expect( selection.hasAttribute( 'italic' ) ).to.equal( false );
 
-			expect( getData( doc ) )
+			expect( getData( model ) )
 				.to.equal( 'f<$text italic="true">o</$text><$text bold="true">ob[]a</$text>r' );
 		} );
 	} );
@@ -433,7 +437,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new InsertOperation(
 						new Position( root, [ 0, 1 ] ),
 						'xyz',
@@ -453,7 +457,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new InsertOperation(
 						new Position( root, [ 1, 0 ] ),
 						'xyz',
@@ -475,7 +479,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new MoveOperation(
 						new Position( root, [ 0, 0 ] ),
 						2,
@@ -496,7 +500,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new MoveOperation(
 						new Position( root, [ 2 ] ),
 						2,
@@ -517,7 +521,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new MoveOperation(
 						new Position( root, [ 1, 0 ] ),
 						2,
@@ -538,7 +542,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new MoveOperation(
 						new Position( root, [ 1, 3 ] ),
 						2,
@@ -559,7 +563,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.directChange ).to.be.false;
 				} );
 
-				const batch = doc.batch();
+				const batch = new Batch();
 				const splitDelta = new SplitDelta();
 
 				const insertOperation = new InsertOperation(
@@ -580,8 +584,8 @@ describe( 'DocumentSelection', () => {
 				splitDelta.addOperation( insertOperation );
 				splitDelta.addOperation( moveOperation );
 
-				doc.applyOperation( insertOperation );
-				doc.applyOperation( moveOperation );
+				model.applyOperation( insertOperation );
+				model.applyOperation( moveOperation );
 
 				const range = selection.getFirstRange();
 
@@ -601,7 +605,7 @@ describe( 'DocumentSelection', () => {
 					expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
 				} );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new AttributeOperation(
 						new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
 						'foo',
@@ -621,7 +625,7 @@ describe( 'DocumentSelection', () => {
 				const spyAttribute = sinon.spy();
 				selection.on( 'change:attribute', spyAttribute );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new AttributeOperation(
 						new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
 						'foo',
@@ -642,7 +646,7 @@ describe( 'DocumentSelection', () => {
 				const spyAttribute = sinon.spy();
 				selection.on( 'change:attribute', spyAttribute );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new AttributeOperation(
 						new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
 						'foo',
@@ -661,7 +665,7 @@ describe( 'DocumentSelection', () => {
 			it( 'fix selection range if it ends up in graveyard #1', () => {
 				selection.setCollapsedAt( new Position( root, [ 1, 3 ] ) );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new RemoveOperation(
 						new Position( root, [ 1, 2 ] ),
 						2,
@@ -676,7 +680,7 @@ describe( 'DocumentSelection', () => {
 			it( 'fix selection range if it ends up in graveyard #2', () => {
 				selection.setRanges( [ new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 1, 4 ] ) ) ] );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new RemoveOperation(
 						new Position( root, [ 1, 2 ] ),
 						2,
@@ -691,7 +695,7 @@ describe( 'DocumentSelection', () => {
 			it( 'fix selection range if it ends up in graveyard #3', () => {
 				selection.setRanges( [ new Range( new Position( root, [ 1, 1 ] ), new Position( root, [ 1, 2 ] ) ) ] );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new RemoveOperation(
 						new Position( root, [ 1 ] ),
 						2,
@@ -704,7 +708,7 @@ describe( 'DocumentSelection', () => {
 			} );
 
 			it( 'fix selection range if it ends up in graveyard #4 - whole content removed', () => {
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new RemoveOperation(
 						new Position( root, [ 0 ] ),
 						3,
@@ -715,7 +719,7 @@ describe( 'DocumentSelection', () => {
 
 				expect( selection.getFirstPosition().path ).to.deep.equal( [ 0 ] );
 
-				doc.applyOperation( wrapInDelta(
+				model.applyOperation( wrapInDelta(
 					new InsertOperation(
 						new Position( root, [ 0 ] ),
 						new Element( 'p' ),
@@ -937,50 +941,50 @@ describe( 'DocumentSelection', () => {
 		// #986
 		describe( 'are not inherited from the inside of object elements', () => {
 			beforeEach( () => {
-				doc.schema.registerItem( 'image' );
-				doc.schema.allow( { name: 'image', inside: '$root' } );
-				doc.schema.allow( { name: 'image', inside: '$block' } );
-				doc.schema.allow( { name: '$inline', inside: 'image' } );
-				doc.schema.objects.add( 'image' );
-
-				doc.schema.registerItem( 'caption' );
-				doc.schema.allow( { name: '$inline', inside: 'caption' } );
-				doc.schema.allow( { name: 'caption', inside: 'image' } );
-				doc.schema.allow( { name: '$text', attributes: 'bold', inside: 'caption' } );
+				model.schema.registerItem( 'image' );
+				model.schema.allow( { name: 'image', inside: '$root' } );
+				model.schema.allow( { name: 'image', inside: '$block' } );
+				model.schema.allow( { name: '$inline', inside: 'image' } );
+				model.schema.objects.add( 'image' );
+
+				model.schema.registerItem( 'caption' );
+				model.schema.allow( { name: '$inline', inside: 'caption' } );
+				model.schema.allow( { name: 'caption', inside: 'image' } );
+				model.schema.allow( { name: '$text', attributes: 'bold', inside: 'caption' } );
 			} );
 
 			it( 'ignores attributes inside an object if selection contains that object', () => {
-				setData( doc, '<p>[<image><$text bold="true">Caption for the image.</$text></image>]</p>' );
+				setData( model, '<p>[<image><$text bold="true">Caption for the image.</$text></image>]</p>' );
 
 				expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
 			} );
 
 			it( 'ignores attributes inside an object if selection contains that object (deeper structure)', () => {
-				setData( doc, '<p>[<image><caption><$text bold="true">Caption for the image.</$text></caption></image>]</p>' );
+				setData( model, '<p>[<image><caption><$text bold="true">Caption for the image.</$text></caption></image>]</p>' );
 
 				expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
 			} );
 
 			it( 'ignores attributes inside an object if selection contains that object (block level)', () => {
-				setData( doc, '<p>foo</p>[<image><$text bold="true">Caption for the image.</$text></image>]<p>foo</p>' );
+				setData( model, '<p>foo</p>[<image><$text bold="true">Caption for the image.</$text></image>]<p>foo</p>' );
 
 				expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
 			} );
 
 			it( 'reads attributes from text even if the selection contains an object', () => {
-				setData( doc, '<p>x<$text bold="true">[bar</$text><image></image>foo]</p>' );
+				setData( model, '<p>x<$text bold="true">[bar</$text><image></image>foo]</p>' );
 
 				expect( selection.getAttribute( 'bold' ) ).to.equal( true );
 			} );
 
 			it( 'reads attributes when the entire selection inside an object', () => {
-				setData( doc, '<p><image><caption><$text bold="true">[bar]</$text></caption></image></p>' );
+				setData( model, '<p><image><caption><$text bold="true">[bar]</$text></caption></image></p>' );
 
 				expect( selection.getAttribute( 'bold' ) ).to.equal( true );
 			} );
 
 			it( 'stops reading attributes if selection starts with an object', () => {
-				setData( doc, '<p>[<image></image><$text bold="true">bar]</$text></p>' );
+				setData( model, '<p>[<image></image><$text bold="true">bar]</$text></p>' );
 
 				expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
 			} );
@@ -1012,7 +1016,9 @@ describe( 'DocumentSelection', () => {
 					batchTypes.set( batch, batch.type );
 				} );
 
-				doc.batch().insertText( 'x', rangeInEmptyP.start );
+				model.change( writer => {
+					writer.insertText( 'x', rangeInEmptyP.start );
+				} );
 
 				expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
 				expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
@@ -1024,7 +1030,9 @@ describe( 'DocumentSelection', () => {
 				selection.setRanges( [ rangeInEmptyP ] );
 				selection.setAttribute( 'foo', 'bar' );
 
-				doc.batch().move( Range.createOn( fullP.getChild( 0 ) ), rangeInEmptyP.start );
+				model.change( writer => {
+					writer.move( Range.createOn( fullP.getChild( 0 ) ), rangeInEmptyP.start );
+				} );
 
 				expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
 			} );
@@ -1036,8 +1044,10 @@ describe( 'DocumentSelection', () => {
 				emptyP.setAttribute( fooStoreAttrKey, 'bar' );
 				emptyP2.setAttribute( fooStoreAttrKey, 'bar' );
 
-				// <emptyP>{}<emptyP2>
-				doc.batch().merge( Position.createAfter( emptyP ) );
+				model.change( writer => {
+					// <emptyP>{}<emptyP2>
+					writer.merge( Position.createAfter( emptyP ) );
+				} );
 
 				expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
 				expect( emptyP.parent ).to.equal( root ); // Just to be sure we're checking the right element.
@@ -1048,35 +1058,39 @@ describe( 'DocumentSelection', () => {
 
 				selection.setRanges( [ rangeInFullP ] );
 
-				doc.batch().insertText( 'x', rangeInEmptyP.start );
+				model.change( writer => {
+					writer.insertText( 'x', rangeInEmptyP.start );
+				} );
 
 				expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
 			} );
 
 			it( 'are removed only once in case of multi-op deltas', () => {
+				let spy;
 				const emptyP2 = new Element( 'p', null, 'x' );
 				root.appendChildren( emptyP2 );
 
 				emptyP.setAttribute( fooStoreAttrKey, 'bar' );
 				emptyP2.setAttribute( fooStoreAttrKey, 'bar' );
 
-				const batch = doc.batch();
-				const spy = sinon.spy( batch, 'removeAttribute' );
+				model.change( writer => {
+					spy = sinon.spy( writer, 'removeAttribute' );
 
-				// <emptyP>{}<emptyP2>
-				batch.merge( Position.createAfter( emptyP ) );
+					// <emptyP>{}<emptyP2>
+					writer.merge( Position.createAfter( emptyP ) );
+				} );
 
 				expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
 
 				expect( spy.calledOnce ).to.be.true;
 			} );
 
-			it( 'uses document enqueue changes to clear attributes', () => {
+			it( 'uses model change to clear attributes', () => {
 				selection.setRanges( [ rangeInEmptyP ] );
 				selection.setAttribute( 'foo', 'bar' );
 
-				doc.enqueueChanges( () => {
-					doc.batch().insertText( 'x', rangeInEmptyP.start );
+				model.change( writer => {
+					writer.insertText( 'x', rangeInEmptyP.start );
 
 					// `emptyP` still has the attribute, because attribute clearing is in enqueued block.
 					expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.true;
@@ -1096,8 +1110,10 @@ describe( 'DocumentSelection', () => {
 				expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.true;
 				expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
 
-				// <emptyP>{}<emptyP2>
-				doc.batch().merge( Position.createAfter( emptyP ) );
+				model.change( writer => {
+					// <emptyP>{}<emptyP2>
+					writer.merge( Position.createAfter( emptyP ) );
+				} );
 
 				expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
 				expect( emptyP.parent ).to.equal( root ); // Just to be sure we're checking the right element.
@@ -1107,12 +1123,14 @@ describe( 'DocumentSelection', () => {
 				selection.setRanges( [ rangeInEmptyP ] );
 				selection.setAttribute( 'foo', 'bar' );
 
-				sinon.spy( doc, 'enqueueChanges' );
+				model.enqueueChange( 'transparent', writer => {
+					sinon.spy( model, 'enqueueChange' );
 
-				doc.batch( 'transparent' ).insertText( 'x', rangeInEmptyP.start );
+					writer.insertText( 'x', rangeInEmptyP.start );
 
-				expect( doc.enqueueChanges.called ).to.be.false;
-				expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
+					expect( model.enqueueChange.called ).to.be.false;
+					expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
+				} );
 			} );
 
 			// Rename and some other deltas don't specify range in doc#change event.
@@ -1121,11 +1139,13 @@ describe( 'DocumentSelection', () => {
 				selection.setRanges( [ rangeInEmptyP ] );
 				selection.setAttribute( 'foo', 'bar' );
 
-				sinon.spy( doc, 'enqueueChanges' );
+				sinon.spy( model, 'enqueueChange' );
 
-				doc.batch().rename( emptyP, 'pnew' );
+				model.change( writer => {
+					writer.rename( emptyP, 'pnew' );
+				} );
 
-				expect( doc.enqueueChanges.called ).to.be.false;
+				expect( model.enqueueChange.called ).to.be.false;
 				expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
 			} );
 		} );

+ 4 - 2
packages/ckeditor5-engine/tests/model/liveposition.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../src/model/document';
+import Model from '../../src/model/model';
 import DocumentFragment from '../../src/model/documentfragment';
 import Element from '../../src/model/element';
 import Text from '../../src/model/text';
@@ -16,7 +16,9 @@ describe( 'LivePosition', () => {
 	let doc, root, ul, p, li1, li2;
 
 	before( () => {
-		doc = new Document();
+		const model = new Model();
+
+		doc = model.document;
 		root = doc.createRoot();
 
 		li1 = new Element( 'li', [], new Text( 'abcdef' ) );

+ 66 - 41
packages/ckeditor5-engine/tests/model/liverange.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../src/model/document';
+import Model from '../../src/model/model';
 import Element from '../../src/model/element';
 import Position from '../../src/model/position';
 import LiveRange from '../../src/model/liverange';
@@ -12,10 +12,11 @@ import Text from '../../src/model/text';
 import { stringify, setData } from '../../src/dev-utils/model';
 
 describe( 'LiveRange', () => {
-	let doc, root, ul, p;
+	let model, doc, root, ul, p;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 
 		const lis = [
@@ -429,11 +430,11 @@ describe( 'LiveRange', () => {
 			let live;
 
 			beforeEach( () => {
-				doc.schema.registerItem( 'p', '$block' );
-				doc.schema.registerItem( 'w' );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.registerItem( 'w' );
 
-				doc.schema.allow( { name: 'p', inside: 'w' } );
-				doc.schema.allow( { name: 'w', inside: '$root' } );
+				model.schema.allow( { name: 'p', inside: 'w' } );
+				model.schema.allow( { name: 'w', inside: '$root' } );
 			} );
 
 			afterEach( () => {
@@ -441,67 +442,79 @@ describe( 'LiveRange', () => {
 			} );
 
 			it( 'is inside the wrapped range', () => {
-				setData( doc, '<p>x</p><p>[a]</p><p>x</p>' );
+				setData( model, '<p>x</p><p>[a]</p><p>x</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				// [<p>a</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) ), 'w' );
+				model.change( writer => {
+					// [<p>a</p>]
+					writer.wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) ), 'w' );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>x</p><w><p>[a]</p></w><p>x</p>' );
 			} );
 
 			it( 'its start is intersecting with the wrapped range', () => {
-				setData( doc, '<p>a[b</p><p>x</p><p>c]d</p>' );
+				setData( model, '<p>a[b</p><p>x</p><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				// [<p>ab</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ), 'w' );
+				model.change( writer => {
+					// [<p>ab</p>]
+					writer.wrap( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ), 'w' );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<w><p>a[b</p></w><p>x</p><p>c]d</p>' );
 			} );
 
 			it( 'its end is intersecting with the wrapped range', () => {
-				setData( doc, '<p>a[b</p><p>x</p><p>c]d</p>' );
+				setData( model, '<p>a[b</p><p>x</p><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				// [<p>cd</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 2 ] ), new Position( root, [ 3 ] ) ), 'w' );
+				model.change( writer => {
+					// [<p>cd</p>]
+					writer.wrap( new Range( new Position( root, [ 2 ] ), new Position( root, [ 3 ] ) ), 'w' );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>x</p><w><p>c]d</p></w>' );
 			} );
 
 			it( 'its start is intersecting with the wrapped range (multilpe elements)', () => {
-				setData( doc, '<p>a[b</p><p>x</p><p>c]d</p>' );
+				setData( model, '<p>a[b</p><p>x</p><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				// [<p>ab</p><p>x</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ), 'w' );
+				model.change( writer => {
+					// [<p>ab</p><p>x</p>]
+					writer.wrap( new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ), 'w' );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<w><p>a[b</p><p>x</p></w><p>c]d</p>' );
 			} );
 
 			it( 'its end is intersecting with the wrapped range (multiple elements)', () => {
-				setData( doc, '<p>a[b</p><p>x</p><p>c]d</p>' );
+				setData( model, '<p>a[b</p><p>x</p><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				// [<p>x</p><p>cd</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) ), 'w' );
+				model.change( writer => {
+					// [<p>x</p><p>cd</p>]
+					writer.wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) ), 'w' );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><w><p>x</p><p>c]d</p></w>' );
 			} );
 
 			it( 'contains element to wrap', () => {
-				setData( doc, '<p>a[b</p><p>x</p><p>c]d</p>' );
+				setData( model, '<p>a[b</p><p>x</p><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				// [<p>x</p>]
-				doc.batch().wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) ), 'w' );
+				model.change( writer => {
+					// [<p>x</p>]
+					writer.wrap( new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) ), 'w' );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><w><p>x</p></w><p>c]d</p>' );
 			} );
@@ -513,11 +526,11 @@ describe( 'LiveRange', () => {
 			let live;
 
 			beforeEach( () => {
-				doc.schema.registerItem( 'p', '$block' );
-				doc.schema.registerItem( 'w' );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.registerItem( 'w' );
 
-				doc.schema.allow( { name: 'p', inside: 'w' } );
-				doc.schema.allow( { name: 'w', inside: '$root' } );
+				model.schema.allow( { name: 'p', inside: 'w' } );
+				model.schema.allow( { name: 'w', inside: '$root' } );
 			} );
 
 			afterEach( () => {
@@ -525,61 +538,73 @@ describe( 'LiveRange', () => {
 			} );
 
 			it( 'is inside the wrapper to remove', () => {
-				setData( doc, '<p>x</p><w><p>[a]</p></w><p>x</p>' );
+				setData( model, '<p>x</p><w><p>[a]</p></w><p>x</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				doc.batch().unwrap( root.getChild( 1 ) );
+				model.change( writer => {
+					writer.unwrap( root.getChild( 1 ) );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>x</p><p>[a]</p><p>x</p>' );
 			} );
 
 			it( 'its start is intersecting with the wrapper to remove', () => {
-				setData( doc, '<w><p>a[b</p></w><p>c]d</p>' );
+				setData( model, '<w><p>a[b</p></w><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				doc.batch().unwrap( root.getChild( 0 ) );
+				model.change( writer => {
+					writer.unwrap( root.getChild( 0 ) );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>c]d</p>' );
 			} );
 
 			it( 'its end is intersecting with the wrapper to remove', () => {
-				setData( doc, '<p>a[b</p><w><p>c]d</p></w>' );
+				setData( model, '<p>a[b</p><w><p>c]d</p></w>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				doc.batch().unwrap( root.getChild( 1 ) );
+				model.change( writer => {
+					writer.unwrap( root.getChild( 1 ) );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>c]d</p>' );
 			} );
 
 			it( 'its start is intersecting with the wrapper to remove (multiple elements)', () => {
-				setData( doc, '<w><p>a[b</p><p>x</p></w><p>c]d</p>' );
+				setData( model, '<w><p>a[b</p><p>x</p></w><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				doc.batch().unwrap( root.getChild( 0 ) );
+				model.change( writer => {
+					writer.unwrap( root.getChild( 0 ) );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>x</p><p>c]d</p>' );
 			} );
 
 			it( 'its end is intersecting with the wrapper to remove (multiple elements)', () => {
-				setData( doc, '<p>a[b</p><w><p>x</p><p>c]d</p></w>' );
+				setData( model, '<p>a[b</p><w><p>x</p><p>c]d</p></w>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				doc.batch().unwrap( root.getChild( 1 ) );
+				model.change( writer => {
+					writer.unwrap( root.getChild( 1 ) );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>x</p><p>c]d</p>' );
 			} );
 
 			it( 'contains wrapped element', () => {
-				setData( doc, '<p>a[b</p><w><p>x</p></w><p>c]d</p>' );
+				setData( model, '<p>a[b</p><w><p>x</p></w><p>c]d</p>' );
 
 				live = new LiveRange( doc.selection.getFirstPosition(), doc.selection.getLastPosition() );
 
-				doc.batch().unwrap( root.getChild( 1 ) );
+				model.change( writer => {
+					writer.unwrap( root.getChild( 1 ) );
+				} );
 
 				expect( stringify( root, live ) ).to.equal( '<p>a[b</p><p>x</p><p>c]d</p>' );
 			} );

+ 13 - 10
packages/ckeditor5-engine/tests/model/markercollection.js

@@ -7,14 +7,16 @@ import MarkerCollection from '../../src/model/markercollection';
 import Position from '../../src/model/position';
 import Range from '../../src/model/range';
 import Text from '../../src/model/text';
-import Document from '../../src/model/document';
+import Model from '../../src/model/model';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 describe( 'MarkerCollection', () => {
 	let markers, range, range2, doc, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		const model = new Model();
+
+		doc = model.document;
 		markers = new MarkerCollection();
 
 		root = doc.createRoot();
@@ -207,10 +209,11 @@ describe( 'MarkerCollection', () => {
 } );
 
 describe( 'Marker', () => {
-	let doc, root;
+	let model, doc, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 	} );
 
@@ -218,14 +221,14 @@ describe( 'Marker', () => {
 		root.appendChildren( new Text( 'foo' ) );
 
 		const range = Range.createFromParentsAndOffsets( root, 1, root, 2 );
-		const marker = doc.markers.set( 'name', range );
+		const marker = model.markers.set( 'name', range );
 
 		expect( marker.getRange().isEqual( range ) ).to.be.true;
 		expect( marker.getStart().isEqual( range.start ) ).to.be.true;
 		expect( marker.getEnd().isEqual( range.end ) ).to.be.true;
 
-		doc.enqueueChanges( () => {
-			doc.batch().insertText( 'abc', root );
+		model.change( writer => {
+			writer.insertText( 'abc', root );
 		} );
 
 		const updatedRange = Range.createFromParentsAndOffsets( root, 4, root, 5 );
@@ -237,9 +240,9 @@ describe( 'Marker', () => {
 
 	it( 'should throw when using the API if marker was removed from markers collection', () => {
 		const range = Range.createFromParentsAndOffsets( root, 1, root, 2 );
-		const marker = doc.markers.set( 'name', range );
+		const marker = model.markers.set( 'name', range );
 
-		doc.markers.remove( 'name' );
+		model.markers.remove( 'name' );
 
 		expect( () => {
 			marker.getRange();
@@ -256,7 +259,7 @@ describe( 'Marker', () => {
 
 	it( 'should delegate events from live range', () => {
 		const range = Range.createFromParentsAndOffsets( root, 1, root, 2 );
-		const marker = doc.markers.set( 'name', range );
+		const marker = model.markers.set( 'name', range );
 
 		const eventRange = sinon.spy();
 		const eventContent = sinon.spy();

+ 4 - 2
packages/ckeditor5-engine/tests/model/node.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../src/model/document';
+import Model from '../../src/model/model';
 import DocumentFragment from '../../src/model/documentfragment';
 import Node from '../../src/model/node';
 import Element from '../../src/model/element';
@@ -17,6 +17,8 @@ describe( 'Node', () => {
 		textBA, textR, img;
 
 	beforeEach( () => {
+		const model = new Model();
+
 		node = new Node();
 
 		one = new Element( 'one' );
@@ -26,7 +28,7 @@ describe( 'Node', () => {
 		textR = two.getChild( 2 );
 		three = new Element( 'three' );
 
-		doc = new Document();
+		doc = model.document;
 		root = doc.createRoot();
 		root.appendChildren( [ one, two, three ] );
 	} );

+ 24 - 23
packages/ckeditor5-engine/tests/model/operation/attributeoperation.js

@@ -3,7 +3,8 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
+import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
 import Text from '../../../src/model/text';
 import AttributeOperation from '../../../src/model/operation/attributeoperation';
@@ -14,10 +15,11 @@ import count from '@ckeditor/ckeditor5-utils/src/count';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'AttributeOperation', () => {
-	let doc, root;
+	let model, doc, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 	} );
 
@@ -73,8 +75,7 @@ describe( 'AttributeOperation', () => {
 		} );
 
 		it( 'should return false when attribute is applied on detached items', () => {
-			const docFrag = doc.batch().createDocumentFragment();
-			doc.batch().appendText( 'abc', null, docFrag );
+			const docFrag = new DocumentFragment( [ new Text( 'abc' ) ] );
 
 			const op = new AttributeOperation(
 				Range.createIn( docFrag ),
@@ -91,7 +92,7 @@ describe( 'AttributeOperation', () => {
 	it( 'should insert attribute to the set of nodes', () => {
 		root.insertChildren( 0, new Text( 'bar' ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 				'isNew',
@@ -112,7 +113,7 @@ describe( 'AttributeOperation', () => {
 	it( 'should add attribute to the existing attributes', () => {
 		root.insertChildren( 0, new Text( 'x', { foo: true, bar: true } ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 				'isNew',
@@ -133,7 +134,7 @@ describe( 'AttributeOperation', () => {
 	it( 'should change attribute to the set of nodes', () => {
 		root.insertChildren( 0, new Text( 'bar', { isNew: false } ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 				'isNew',
@@ -154,7 +155,7 @@ describe( 'AttributeOperation', () => {
 	it( 'should change attribute in the middle of existing attributes', () => {
 		root.insertChildren( 0, new Text( 'x', { foo: true, x: 1, bar: true } ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 				'x',
@@ -175,7 +176,7 @@ describe( 'AttributeOperation', () => {
 	it( 'should remove attribute', () => {
 		root.insertChildren( 0, new Text( 'x', { foo: true, x: true, bar: true } ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 				'x',
@@ -196,7 +197,7 @@ describe( 'AttributeOperation', () => {
 		root.insertChildren( 0, new Text( 'x', { foo: [ 'bar', 'xyz' ] } ) );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta(
+			model.applyOperation( wrapInDelta(
 				new AttributeOperation(
 					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					'foo',
@@ -234,8 +235,8 @@ describe( 'AttributeOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 3 );
@@ -248,7 +249,7 @@ describe( 'AttributeOperation', () => {
 
 		root.insertChildren( 0, [ eleA, eleB ] );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) ),
 				'foo',
@@ -269,7 +270,7 @@ describe( 'AttributeOperation', () => {
 
 		root.insertChildren( 0, [ eleA, eleB ] );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 0, 3 ] ), new Position( root, [ 1, 0 ] ) ),
 				'foo',
@@ -295,8 +296,8 @@ describe( 'AttributeOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 3 );
@@ -317,8 +318,8 @@ describe( 'AttributeOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 3 );
@@ -330,7 +331,7 @@ describe( 'AttributeOperation', () => {
 		root.insertChildren( 0, new Text( 'x' ) );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta(
+			model.applyOperation( wrapInDelta(
 				new AttributeOperation(
 					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					'foo',
@@ -346,7 +347,7 @@ describe( 'AttributeOperation', () => {
 		root.insertChildren( 0, new Text( 'x', { x: 1 } ) );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta(
+			model.applyOperation( wrapInDelta(
 				new AttributeOperation(
 					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					'x',
@@ -384,7 +385,7 @@ describe( 'AttributeOperation', () => {
 		root.insertChildren( 0, new Text( 'abc', attrA ) );
 		root.insertChildren( 1, new Text( 'xyz', attrB ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new AttributeOperation(
 				new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) ),
 				'foo',
@@ -402,7 +403,7 @@ describe( 'AttributeOperation', () => {
 		root.insertChildren( 0, new Text( 'x', { foo: true } ) );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta(
+			model.applyOperation( wrapInDelta(
 				new AttributeOperation(
 					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					'foo',

+ 12 - 11
packages/ckeditor5-engine/tests/model/operation/detachoperation.js

@@ -3,22 +3,22 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import DetachOperation from '../../../src/model/operation/detachoperation';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Position from '../../../src/model/position';
+import DocumentFragment from '../../../src/model/documentfragment';
+import Element from '../../../src/model/element';
 
 describe( 'DetachOperation', () => {
-	let doc, batch, docFrag, element;
+	let model, doc, docFrag, element;
 
 	beforeEach( () => {
-		doc = new Document();
-		batch = doc.batch();
-
-		docFrag = batch.createDocumentFragment();
-		element = batch.createElement( 'element' );
-		batch.append( element, docFrag );
+		model = new Model();
+		doc = model.document;
+		element = new Element( 'element' );
+		docFrag = new DocumentFragment( [ element ] );
 	} );
 
 	it( 'should have type equal to detach', () => {
@@ -30,15 +30,16 @@ describe( 'DetachOperation', () => {
 	it( 'should remove given element from parent', () => {
 		const op = new DetachOperation( Position.createBefore( element ), 1, doc.version );
 
-		doc.applyOperation( wrapInDelta( op ) );
+		model.applyOperation( wrapInDelta( op ) );
 
 		expect( docFrag.childCount ).to.equal( 0 );
 	} );
 
 	it( 'should throw when is executed on element from document', () => {
 		const root = doc.createRoot();
-		const element = batch.createElement( 'element' );
-		batch.append( element, root );
+		const element = new Element( 'element' );
+
+		root.appendChildren( [ element ] );
 
 		const op = new DetachOperation( Position.createBefore( element ), 1, doc.version );
 

+ 17 - 15
packages/ckeditor5-engine/tests/model/operation/insertoperation.js

@@ -3,9 +3,10 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import NodeList from '../../../src/model/nodelist';
 import Element from '../../../src/model/element';
+import DocumentFragment from '../../../src/model/documentfragment';
 import InsertOperation from '../../../src/model/operation/insertoperation';
 import RemoveOperation from '../../../src/model/operation/removeoperation';
 import Position from '../../../src/model/position';
@@ -13,10 +14,11 @@ import Text from '../../../src/model/text';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'InsertOperation', () => {
-	let doc, root;
+	let model, doc, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 	} );
 
@@ -31,7 +33,7 @@ describe( 'InsertOperation', () => {
 	} );
 
 	it( 'should insert text node', () => {
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new InsertOperation(
 				new Position( root, [ 0 ] ),
 				new Text( 'x' ),
@@ -45,7 +47,7 @@ describe( 'InsertOperation', () => {
 	} );
 
 	it( 'should insert element', () => {
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new InsertOperation(
 				new Position( root, [ 0 ] ),
 				new Element( 'p' ),
@@ -59,7 +61,7 @@ describe( 'InsertOperation', () => {
 	} );
 
 	it( 'should insert set of nodes', () => {
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new InsertOperation(
 				new Position( root, [ 0 ] ),
 				[ 'bar', new Element( 'p' ), 'foo' ],
@@ -78,7 +80,7 @@ describe( 'InsertOperation', () => {
 	it( 'should insert between existing nodes', () => {
 		root.insertChildren( 0, new Text( 'xy' ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new InsertOperation(
 				new Position( root, [ 1 ] ),
 				'bar',
@@ -92,7 +94,7 @@ describe( 'InsertOperation', () => {
 	} );
 
 	it( 'should insert text', () => {
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new InsertOperation(
 				new Position( root, [ 0 ] ),
 				[ 'foo', new Text( 'x' ), 'bar' ],
@@ -130,11 +132,11 @@ describe( 'InsertOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( operation ) );
 
 		expect( doc.version ).to.equal( 1 );
 
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 0 );
@@ -149,11 +151,11 @@ describe( 'InsertOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( operation ) );
 
 		expect( doc.version ).to.equal( 1 );
 
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 0 );
@@ -190,11 +192,11 @@ describe( 'InsertOperation', () => {
 		const element = new Element( 'p', { key: 'value' } );
 
 		const op = new InsertOperation( new Position( root, [ 0 ] ), element, doc.version );
-		doc.applyOperation( wrapInDelta( op ) );
+		model.applyOperation( wrapInDelta( op ) );
 
 		const text = new Text( 'text' );
 		const op2 = new InsertOperation( new Position( root, [ 0, 0 ] ), text, doc.version );
-		doc.applyOperation( wrapInDelta( op2 ) );
+		model.applyOperation( wrapInDelta( op2 ) );
 
 		expect( op.nodes.getNode( 0 ) ).not.to.equal( element );
 		expect( op.nodes.getNode( 0 ).name ).to.equal( 'p' );
@@ -218,7 +220,7 @@ describe( 'InsertOperation', () => {
 		} );
 
 		it( 'should return false when element is inserted to document fragment', () => {
-			const docFrag = doc.batch().createDocumentFragment();
+			const docFrag = new DocumentFragment();
 
 			const op = new InsertOperation(
 				new Position( docFrag, [ 0 ] ),

+ 42 - 41
packages/ckeditor5-engine/tests/model/operation/markeroperation.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import Text from '../../../src/model/text';
 import Range from '../../../src/model/range';
 import MarkerOperation from '../../../src/model/operation/markeroperation';
@@ -14,22 +14,23 @@ function matchRange( range ) {
 }
 
 describe( 'MarkerOperation', () => {
-	let doc, root, range;
+	let model, doc, root, range;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 		root.appendChildren( new Text( 'foo' ) );
 		range = Range.createFromParentsAndOffsets( root, 0, root, 0 );
 	} );
 
 	it( 'should have property type equal to "marker"', () => {
-		const op = new MarkerOperation( 'name', null, range, doc.markers, 0 );
+		const op = new MarkerOperation( 'name', null, range, model.markers, 0 );
 		expect( op.type ).to.equal( 'marker' );
 	} );
 
 	it( 'should add marker to document marker collection', () => {
-		sinon.spy( doc.markers, 'set' );
+		sinon.spy( model.markers, 'set' );
 		sinon.spy( doc, 'fire' );
 
 		doc.on( 'change', ( evt, type, changes ) => {
@@ -38,42 +39,42 @@ describe( 'MarkerOperation', () => {
 			expect( changes.type ).to.equal( 'set' );
 		} );
 
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', null, range, model.markers, doc.version )
 		) );
 
 		expect( doc.version ).to.equal( 1 );
-		expect( doc.markers.set.calledWith( 'name', matchRange( range ) ) );
-		expect( doc.markers.get( 'name' ).getRange().isEqual( range ) ).to.be.true;
+		expect( model.markers.set.calledWith( 'name', matchRange( range ) ) );
+		expect( model.markers.get( 'name' ).getRange().isEqual( range ) ).to.be.true;
 		expect( doc.fire.called ).to.be.true;
 	} );
 
 	it( 'should update marker in document marker collection', () => {
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', null, range, model.markers, doc.version )
 		) );
 
 		const range2 = Range.createFromParentsAndOffsets( root, 0, root, 3 );
 
-		sinon.spy( doc.markers, 'set' );
+		sinon.spy( model.markers, 'set' );
 		sinon.spy( doc, 'fire' );
 
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range2, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', range, range2, model.markers, doc.version )
 		) );
 
 		expect( doc.version ).to.equal( 2 );
-		expect( doc.markers.set.calledWith( 'name', matchRange( range2 ) ) );
-		expect( doc.markers.get( 'name' ).getRange().isEqual( range2 ) ).to.be.true;
+		expect( model.markers.set.calledWith( 'name', matchRange( range2 ) ) );
+		expect( model.markers.get( 'name' ).getRange().isEqual( range2 ) ).to.be.true;
 		expect( doc.fire.called ).to.be.true;
 	} );
 
 	it( 'should remove marker from document marker collection', () => {
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', null, range, model.markers, doc.version )
 		) );
 
-		sinon.spy( doc.markers, 'remove' );
+		sinon.spy( model.markers, 'remove' );
 		sinon.spy( doc, 'fire' );
 
 		doc.on( 'change', ( evt, type, changes ) => {
@@ -82,19 +83,19 @@ describe( 'MarkerOperation', () => {
 			expect( changes.type ).to.equal( 'remove' );
 		} );
 
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, null, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', range, null, model.markers, doc.version )
 		) );
 
 		expect( doc.version ).to.equal( 2 );
-		expect( doc.markers.remove.calledWith( 'name' ) );
-		expect( doc.markers.get( 'name' ) ).to.be.null;
+		expect( model.markers.remove.calledWith( 'name' ) );
+		expect( model.markers.get( 'name' ) ).to.be.null;
 		expect( doc.fire.called ).to.be.true;
 	} );
 
 	it( 'should fire document change event but not document markers remove event if removing non-existing range', () => {
 		sinon.spy( doc, 'fire' );
-		sinon.spy( doc.markers, 'fire' );
+		sinon.spy( model.markers, 'fire' );
 
 		doc.on( 'change', ( evt, type, changes ) => {
 			expect( type ).to.equal( 'marker' );
@@ -102,19 +103,19 @@ describe( 'MarkerOperation', () => {
 			expect( changes.type ).to.equal( 'remove' );
 		} );
 
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, null, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', null, null, model.markers, doc.version )
 		) );
 
 		expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
-		expect( doc.markers.fire.notCalled ).to.be.true;
+		expect( model.markers.fire.notCalled ).to.be.true;
 	} );
 
 	it( 'should fire document change event but not document markers set event if newRange is same as current marker range', () => {
-		doc.markers.set( 'name', range );
+		model.markers.set( 'name', range );
 
 		sinon.spy( doc, 'fire' );
-		sinon.spy( doc.markers, 'fire' );
+		sinon.spy( model.markers, 'fire' );
 
 		doc.on( 'change', ( evt, type, changes ) => {
 			expect( type ).to.equal( 'marker' );
@@ -122,21 +123,21 @@ describe( 'MarkerOperation', () => {
 			expect( changes.type ).to.equal( 'set' );
 		} );
 
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range, doc.markers, doc.version )
+		model.applyOperation( wrapInDelta(
+			new MarkerOperation( 'name', range, range, model.markers, doc.version )
 		) );
 
 		expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
-		expect( doc.markers.fire.notCalled ).to.be.true;
+		expect( model.markers.fire.notCalled ).to.be.true;
 	} );
 
 	it( 'should return MarkerOperation with swapped ranges as reverse operation', () => {
 		const range2 = Range.createFromParentsAndOffsets( root, 0, root, 3 );
 
-		const op1 = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
+		const op1 = new MarkerOperation( 'name', null, range, model.markers, doc.version );
 		const reversed1 = op1.getReversed();
 
-		const op2 = new MarkerOperation( 'name', range, range2, doc.markers, doc.version );
+		const op2 = new MarkerOperation( 'name', range, range2, model.markers, doc.version );
 		const reversed2 = op2.getReversed();
 
 		expect( reversed1 ).to.be.an.instanceof( MarkerOperation );
@@ -154,7 +155,7 @@ describe( 'MarkerOperation', () => {
 	} );
 
 	it( 'should create a MarkerOperation with the same parameters when cloned', () => {
-		const op = new MarkerOperation( 'name', null, range, doc.markers, 0 );
+		const op = new MarkerOperation( 'name', null, range, model.markers, 0 );
 		const clone = op.clone();
 
 		expect( clone ).to.be.an.instanceof( MarkerOperation );
@@ -163,19 +164,19 @@ describe( 'MarkerOperation', () => {
 
 	describe( 'isDocumentOperation', () => {
 		it( 'should return true when new marker range is added to the document', () => {
-			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
+			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version );
 
 			expect( op.isDocumentOperation ).to.true;
 		} );
 
 		it( 'should return false when marker range is removed from the document', () => {
-			const op = new MarkerOperation( 'name', range, null, doc.markers, doc.version );
+			const op = new MarkerOperation( 'name', range, null, model.markers, doc.version );
 
 			expect( op.isDocumentOperation ).to.true;
 		} );
 
 		it( 'should return true when non-existing marker range is removed from the document', () => {
-			const op = new MarkerOperation( 'name', null, null, doc.markers, doc.version );
+			const op = new MarkerOperation( 'name', null, null, model.markers, doc.version );
 
 			expect( op.isDocumentOperation ).to.true;
 		} );
@@ -183,7 +184,7 @@ describe( 'MarkerOperation', () => {
 
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
-			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
+			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version );
 			const serialized = jsonParseStringify( op );
 
 			expect( serialized ).to.deep.equal( {
@@ -198,7 +199,7 @@ describe( 'MarkerOperation', () => {
 
 	describe( 'fromJSON', () => {
 		it( 'should create proper MarkerOperation from json object #1', () => {
-			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
+			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version );
 
 			const serialized = jsonParseStringify( op );
 			const deserialized = MarkerOperation.fromJSON( serialized, doc );
@@ -208,7 +209,7 @@ describe( 'MarkerOperation', () => {
 
 		it( 'should create proper MarkerOperation from json object #2', () => {
 			// Gotta love 100% CC.
-			const op = new MarkerOperation( 'name', range, null, doc.markers, doc.version );
+			const op = new MarkerOperation( 'name', range, null, model.markers, doc.version );
 
 			const serialized = jsonParseStringify( op );
 			const deserialized = MarkerOperation.fromJSON( serialized, doc );

+ 17 - 17
packages/ckeditor5-engine/tests/model/operation/moveoperation.js

@@ -3,19 +3,21 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import MoveOperation from '../../../src/model/operation/moveoperation';
 import Position from '../../../src/model/position';
+import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
 import Text from '../../../src/model/text';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'MoveOperation', () => {
-	let doc, root;
+	let model, doc, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 	} );
 
@@ -47,7 +49,7 @@ describe( 'MoveOperation', () => {
 
 		root.insertChildren( 0, [ p1, p2 ] );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new MoveOperation(
 				new Position( root, [ 0, 0 ] ),
 				1,
@@ -68,7 +70,7 @@ describe( 'MoveOperation', () => {
 	it( 'should move position of children in one node backward', () => {
 		root.insertChildren( 0, new Text( 'xbarx' ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new MoveOperation(
 				new Position( root, [ 2 ] ),
 				2,
@@ -85,7 +87,7 @@ describe( 'MoveOperation', () => {
 	it( 'should move position of children in one node forward', () => {
 		root.insertChildren( 0, new Text( 'xbarx' ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new MoveOperation(
 				new Position( root, [ 1 ] ),
 				2,
@@ -132,7 +134,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		doc.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( operation ) );
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.maxOffset ).to.equal( 2 );
@@ -140,7 +142,7 @@ describe( 'MoveOperation', () => {
 		expect( p2.maxOffset ).to.equal( 1 );
 		expect( p2.getChild( 0 ).name ).to.equal( 'x' );
 
-		doc.applyOperation( wrapInDelta( operation.getReversed() ) );
+		model.applyOperation( wrapInDelta( operation.getReversed() ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 2 );
@@ -159,7 +161,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		expect( () => doc.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-nodes-do-not-exist/ );
+		expect( () => model.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-nodes-do-not-exist/ );
 	} );
 
 	it( 'should throw an error if target or source parent-element specified by position does not exist', () => {
@@ -176,7 +178,7 @@ describe( 'MoveOperation', () => {
 
 		root.removeChildren( 1 );
 
-		expect( () => doc.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-position-invalid/ );
+		expect( () => model.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-position-invalid/ );
 	} );
 
 	it( 'should throw an error if operation tries to move a range between the beginning and the end of that range', () => {
@@ -189,7 +191,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		expect( () => doc.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-range-into-itself/ );
+		expect( () => model.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-range-into-itself/ );
 	} );
 
 	it( 'should throw an error if operation tries to move a range into a sub-tree of a node that is in that range', () => {
@@ -203,7 +205,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		expect( () => doc.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-node-into-itself/ );
+		expect( () => model.applyOperation( wrapInDelta( operation ) ) ).to.throw( CKEditorError, /move-operation-node-into-itself/ );
 	} );
 
 	it( 'should not throw an error if operation move a range into a sibling', () => {
@@ -219,7 +221,7 @@ describe( 'MoveOperation', () => {
 
 		expect(
 			() => {
-				doc.applyOperation( wrapInDelta( operation ) );
+				model.applyOperation( wrapInDelta( operation ) );
 			}
 		).not.to.throw();
 
@@ -242,7 +244,7 @@ describe( 'MoveOperation', () => {
 
 		expect(
 			() => {
-				doc.applyOperation( wrapInDelta( operation ) );
+				model.applyOperation( wrapInDelta( operation ) );
 			}
 		).not.to.throw();
 	} );
@@ -280,9 +282,7 @@ describe( 'MoveOperation', () => {
 		} );
 
 		it( 'should return false when operation is executed on detached items', () => {
-			const docFrag = doc.batch().createDocumentFragment();
-
-			doc.batch().appendText( 'abc', null, docFrag );
+			const docFrag = new DocumentFragment( [ new Text( 'abc' ) ] );
 
 			const op = new MoveOperation(
 				new Position( docFrag, [ 0 ] ),

+ 5 - 4
packages/ckeditor5-engine/tests/model/operation/nooperation.js

@@ -3,20 +3,21 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import NoOperation from '../../../src/model/operation/nooperation';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'NoOperation', () => {
-	let noop, doc;
+	let model, noop, doc;
 
 	beforeEach( () => {
 		noop = new NoOperation( 0 );
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 	} );
 
 	it( 'should not throw an error when applied', () => {
-		expect( () => doc.applyOperation( wrapInDelta( noop ) ) ).to.not.throw( Error );
+		expect( () => model.applyOperation( wrapInDelta( noop ) ) ).to.not.throw( Error );
 	} );
 
 	it( 'should return empty object when executed', () => {

+ 4 - 4
packages/ckeditor5-engine/tests/model/operation/operationfactory.js

@@ -3,22 +3,22 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import NoOperation from '../../../src/model/operation/nooperation';
 import OperationFactory from '../../../src/model/operation/operationfactory';
 
 describe( 'OperationFactory', () => {
-	let doc;
+	let model;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
 	} );
 
 	it( 'should create operation from JSON', () => {
 		const operation = OperationFactory.fromJSON( {
 			__className: 'engine.model.operation.NoOperation',
 			baseVersion: 0
-		}, doc );
+		}, model.doc );
 
 		expect( operation ).to.instanceof( NoOperation );
 		expect( operation.baseVersion ).to.equal( 0 );

+ 9 - 7
packages/ckeditor5-engine/tests/model/operation/reinsertoperation.js

@@ -3,21 +3,23 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import ReinsertOperation from '../../../src/model/operation/reinsertoperation';
 import RemoveOperation from '../../../src/model/operation/removeoperation';
 import MoveOperation from '../../../src/model/operation/moveoperation';
 import Position from '../../../src/model/position';
+import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
 import Text from '../../../src/model/text';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'ReinsertOperation', () => {
-	let doc, root, graveyard, operation, graveyardPosition, rootPosition;
+	let model, doc, root, graveyard, operation, graveyardPosition, rootPosition;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 		graveyard = doc.graveyard;
 
@@ -87,13 +89,13 @@ describe( 'ReinsertOperation', () => {
 
 		graveyard.insertChildren( 0, new Text( 'xx' ) );
 
-		doc.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( operation ) );
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.maxOffset ).to.equal( 2 );
 		expect( graveyard.maxOffset ).to.equal( 0 );
 
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 0 );
@@ -105,7 +107,7 @@ describe( 'ReinsertOperation', () => {
 	} );
 
 	it( 'should throw when target position is not in the document', () => {
-		const docFrag = doc.batch().createDocumentFragment();
+		const docFrag = new DocumentFragment();
 
 		operation = new ReinsertOperation(
 			graveyardPosition,
@@ -120,7 +122,7 @@ describe( 'ReinsertOperation', () => {
 	} );
 
 	it( 'should throw when source position is not in the document', () => {
-		const docFrag = doc.batch().createDocumentFragment();
+		const docFrag = new DocumentFragment();
 
 		operation = new ReinsertOperation(
 			Position.createAt( docFrag ),

+ 13 - 12
packages/ckeditor5-engine/tests/model/operation/removeoperation.js

@@ -3,21 +3,23 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import ReinsertOperation from '../../../src/model/operation/reinsertoperation';
 import RemoveOperation from '../../../src/model/operation/removeoperation';
 import MoveOperation from '../../../src/model/operation/moveoperation';
 import Position from '../../../src/model/position';
-import Text from '../../../src/model/text';
+import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
+import Text from '../../../src/model/text';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'RemoveOperation', () => {
-	let doc, root, graveyard;
+	let model, doc, root, graveyard;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 		graveyard = doc.graveyard;
 	} );
@@ -58,7 +60,7 @@ describe( 'RemoveOperation', () => {
 	it( 'should be able to remove set of nodes and append them to graveyard root', () => {
 		root.insertChildren( 0, new Text( 'fozbar' ) );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new RemoveOperation(
 				new Position( root, [ 2 ] ),
 				2,
@@ -115,12 +117,12 @@ describe( 'RemoveOperation', () => {
 
 		root.insertChildren( 0, new Text( 'bar' ) );
 
-		doc.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( operation ) );
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.maxOffset ).to.equal( 0 );
 
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.maxOffset ).to.equal( 3 );
@@ -133,7 +135,7 @@ describe( 'RemoveOperation', () => {
 		const position = new Position( doc.graveyard, [ 2 ] );
 		const operation = new RemoveOperation( position, 1, new Position( doc.graveyard, [ 0 ] ), 0 );
 
-		doc.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( operation ) );
 
 		expect( doc.graveyard.childCount ).to.equal( 3 );
 		expect( doc.graveyard.getChild( 0 ).name ).to.equal( 'z' );
@@ -142,11 +144,10 @@ describe( 'RemoveOperation', () => {
 	} );
 
 	it( 'should throw when is executed on detached item', () => {
-		const batch = doc.batch();
-		const docFrag = batch.createDocumentFragment();
-		const item = batch.createElement( 'foo' );
+		const docFrag = new DocumentFragment();
+		const item = new Element( 'foo' );
 
-		batch.append( item, docFrag );
+		docFrag.appendChildren( [ item ] );
 
 		const op = new RemoveOperation(
 			new Position( docFrag, [ 0 ] ),

+ 12 - 14
packages/ckeditor5-engine/tests/model/operation/renameoperation.js

@@ -3,7 +3,8 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
+import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
 import RenameOperation from '../../../src/model/operation/renameoperation';
 import Position from '../../../src/model/position';
@@ -14,10 +15,11 @@ describe( 'RenameOperation', () => {
 	const oldName = 'oldName';
 	const newName = 'newName';
 
-	let doc, root, element, position;
+	let model, doc, root, element, position;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 
 		element = new Element( oldName );
@@ -35,7 +37,7 @@ describe( 'RenameOperation', () => {
 	it( 'should change name of given element', () => {
 		const op = new RenameOperation( position, oldName, newName, doc.version );
 
-		doc.applyOperation( wrapInDelta( op ) );
+		model.applyOperation( wrapInDelta( op ) );
 
 		expect( element.name ).to.equal( newName );
 	} );
@@ -55,8 +57,8 @@ describe( 'RenameOperation', () => {
 		const op = new RenameOperation( position, oldName, newName, doc.version );
 		const reverse = op.getReversed();
 
-		doc.applyOperation( wrapInDelta( op ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( op ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( element.name ).to.equal( oldName );
@@ -66,7 +68,7 @@ describe( 'RenameOperation', () => {
 		const op = new RenameOperation( Position.createAt( root, 'end' ), oldName, newName, doc.version );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta( op ) );
+			model.applyOperation( wrapInDelta( op ) );
 		} ).to.throw( CKEditorError, /rename-operation-wrong-position/ );
 	} );
 
@@ -74,7 +76,7 @@ describe( 'RenameOperation', () => {
 		const op = new RenameOperation( position, 'foo', newName, doc.version );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta( op ) );
+			model.applyOperation( wrapInDelta( op ) );
 		} ).to.throw( CKEditorError, /rename-operation-wrong-name/ );
 	} );
 
@@ -96,7 +98,7 @@ describe( 'RenameOperation', () => {
 		const op = new RenameOperation( position, oldName, oldName, doc.version );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta( op ) );
+			model.applyOperation( wrapInDelta( op ) );
 		} ).to.not.throw();
 	} );
 
@@ -108,11 +110,7 @@ describe( 'RenameOperation', () => {
 		} );
 
 		it( 'should be false when target item is not in the document', () => {
-			const batch = doc.batch();
-			const docFrag = batch.createDocumentFragment();
-
-			batch.appendElement( 'element', null, docFrag );
-
+			const docFrag = new DocumentFragment( [ new Element( 'element' ) ] );
 			const op = new RenameOperation( Position.createAt( docFrag ), oldName, newName, doc.version );
 
 			expect( op.isDocumentOperation ).to.false;

+ 17 - 15
packages/ckeditor5-engine/tests/model/operation/rootattributeoperation.js

@@ -3,16 +3,18 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
+import Element from '../../../src/model/element';
 import RootAttributeOperation from '../../../src/model/operation/rootattributeoperation';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
 
 describe( 'RootAttributeOperation', () => {
-	let doc, root;
+	let model, doc, root;
 
 	beforeEach( () => {
-		doc = new Document();
+		model = new Model();
+		doc = model.document;
 		root = doc.createRoot();
 	} );
 
@@ -68,7 +70,7 @@ describe( 'RootAttributeOperation', () => {
 		} );
 
 		it( 'should be false when root is not in the document', () => {
-			const element = doc.batch().createElement( 'element' );
+			const element = new Element( 'element' );
 
 			const operation = new RootAttributeOperation(
 				element,
@@ -83,7 +85,7 @@ describe( 'RootAttributeOperation', () => {
 	} );
 
 	it( 'should add attribute on the root element', () => {
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new RootAttributeOperation(
 				root,
 				'isNew',
@@ -100,7 +102,7 @@ describe( 'RootAttributeOperation', () => {
 	it( 'should change attribute on the root element', () => {
 		root.setAttribute( 'isNew', false );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new RootAttributeOperation(
 				root,
 				'isNew',
@@ -117,7 +119,7 @@ describe( 'RootAttributeOperation', () => {
 	it( 'should remove attribute from the root element', () => {
 		root.setAttribute( 'x', true );
 
-		doc.applyOperation( wrapInDelta(
+		model.applyOperation( wrapInDelta(
 			new RootAttributeOperation(
 				root,
 				'x',
@@ -154,8 +156,8 @@ describe( 'RootAttributeOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.hasAttribute( 'x' ) ).to.be.false;
@@ -174,8 +176,8 @@ describe( 'RootAttributeOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.getAttribute( 'isNew' ) ).to.be.false;
@@ -194,8 +196,8 @@ describe( 'RootAttributeOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		doc.applyOperation( wrapInDelta( operation ) );
-		doc.applyOperation( wrapInDelta( reverse ) );
+		model.applyOperation( wrapInDelta( operation ) );
+		model.applyOperation( wrapInDelta( reverse ) );
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.getAttribute( 'foo' ) ).to.be.true;
@@ -203,7 +205,7 @@ describe( 'RootAttributeOperation', () => {
 
 	it( 'should throw an error when one try to remove and the attribute does not exists', () => {
 		expect( () => {
-			doc.applyOperation( wrapInDelta(
+			model.applyOperation( wrapInDelta(
 				new RootAttributeOperation(
 					root,
 					'foo',
@@ -219,7 +221,7 @@ describe( 'RootAttributeOperation', () => {
 		root.setAttribute( 'x', 1 );
 
 		expect( () => {
-			doc.applyOperation( wrapInDelta(
+			model.applyOperation( wrapInDelta(
 				new RootAttributeOperation(
 					root,
 					'x',

+ 4 - 2
packages/ckeditor5-engine/tests/model/operation/transform.js

@@ -5,7 +5,7 @@
 
 import transform from '../../../src/model/operation/transform';
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import RootElement from '../../../src/model/rootelement';
 import Node from '../../../src/model/node';
 import Position from '../../../src/model/position';
@@ -24,7 +24,9 @@ describe( 'transform', () => {
 	let doc, root, op, nodeA, nodeB, expected, baseVersion;
 
 	beforeEach( () => {
-		doc = new Document();
+		const model = new Model();
+
+		doc = model.document;
 		root = doc.createRoot();
 
 		nodeA = new Node();

+ 7 - 6
packages/ckeditor5-engine/tests/model/operation/utils.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import Document from '../../../src/model/document';
+import Model from '../../../src/model/model';
 import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
 import Text from '../../../src/model/text';
@@ -15,12 +15,13 @@ import { getData } from '../../../src/dev-utils/model';
 
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
-let doc, root;
+let model, doc, root;
 
-describe( 'writer utils', () => {
+describe( 'Operation utils', () => {
 	beforeEach( () => {
-		doc = new Document();
-		doc.schema.allow( { name: '$text', inside: '$root' } );
+		model = new Model();
+		doc = model.document;
+		model.schema.allow( { name: '$text', inside: '$root' } );
 
 		root = doc.createRoot();
 
@@ -204,5 +205,5 @@ describe( 'normalizeNodes', () => {
 } );
 
 function expectData( html ) {
-	expect( getData( doc, { withoutSelection: true } ) ).to.equal( html );
+	expect( getData( model, { withoutSelection: true } ) ).to.equal( html );
 }