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

Aligned test with engine changes.

Oskar Wróbel 8 лет назад
Родитель
Сommit
803c7fbf76

+ 16 - 15
packages/ckeditor5-link/tests/findlinkrange.js

@@ -4,23 +4,24 @@
  */
 
 import findLinkRange from '../src/findlinkrange';
-import Document from '@ckeditor/ckeditor5-engine/src/model/document';
+import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'findLinkRange', () => {
-	let document, root;
+	let model, document, root;
 
 	beforeEach( () => {
-		document = new Document();
+		model = new Model();
+		document = model.document;
 		root = document.createRoot();
-		document.schema.allow( { name: '$text', inside: '$root' } );
-		document.schema.registerItem( 'p', '$block' );
+		model.schema.allow( { name: '$text', inside: '$root' } );
+		model.schema.registerItem( 'p', '$block' );
 	} );
 
 	it( 'should find link range searching from the center of the link #1', () => {
-		setData( document, '<$text linkHref="url">foobar</$text>' );
+		setData( model, '<$text linkHref="url">foobar</$text>' );
 
 		const startPosition = new Position( root, [ 3 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -30,7 +31,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range searching from the center of the link #2', () => {
-		setData( document, 'abc <$text linkHref="url">foobar</$text> abc' );
+		setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
 
 		const startPosition = new Position( root, [ 7 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -40,7 +41,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range searching from the beginning of the link #1', () => {
-		setData( document, '<$text linkHref="url">foobar</$text>' );
+		setData( model, '<$text linkHref="url">foobar</$text>' );
 
 		const startPosition = new Position( root, [ 0 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -50,7 +51,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range searching from the beginning of the link #2', () => {
-		setData( document, 'abc <$text linkHref="url">foobar</$text> abc' );
+		setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
 
 		const startPosition = new Position( root, [ 4 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -60,7 +61,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range searching from the end of the link #1', () => {
-		setData( document, '<$text linkHref="url">foobar</$text>' );
+		setData( model, '<$text linkHref="url">foobar</$text>' );
 
 		const startPosition = new Position( root, [ 6 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -70,7 +71,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range searching from the end of the link #2', () => {
-		setData( document, 'abc <$text linkHref="url">foobar</$text> abc' );
+		setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
 
 		const startPosition = new Position( root, [ 10 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -80,7 +81,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range when link stick to other link searching from the center of the link', () => {
-		setData( document, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
+		setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
 
 		const startPosition = new Position( root, [ 6 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -90,7 +91,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range when link stick to other link searching from the beginning of the link', () => {
-		setData( document, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
+		setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
 
 		const startPosition = new Position( root, [ 3 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -100,7 +101,7 @@ describe( 'findLinkRange', () => {
 	} );
 
 	it( 'should find link range when link stick to other link searching from the end of the link', () => {
-		setData( document, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
+		setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
 
 		const startPosition = new Position( root, [ 9 ] );
 		const result = findLinkRange( startPosition, 'url' );
@@ -111,7 +112,7 @@ describe( 'findLinkRange', () => {
 
 	it( 'should find link range only inside current parent', () => {
 		setData(
-			document,
+			model,
 			'<p><$text linkHref="url">foobar</$text></p>' +
 			'<p><$text linkHref="url">foobar</$text></p>' +
 			'<p><$text linkHref="url">foobar</$text></p>'

+ 25 - 25
packages/ckeditor5-link/tests/link.js

@@ -81,7 +81,7 @@ describe( 'Link', () => {
 		} );
 
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when text fragment is selected', () => {
-			setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[o]o</paragraph>' );
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
 			linkFeature._showPanel();
@@ -96,7 +96,7 @@ describe( 'Link', () => {
 		} );
 
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the selection when selection is collapsed', () => {
-			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
 			linkFeature._showPanel();
@@ -113,7 +113,7 @@ describe( 'Link', () => {
 		it( 'should add #formView to the #_balloon and attach the #_balloon to the link element when collapsed selection is inside ' +
 			'that link',
 		() => {
-			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 			const linkElement = editorElement.querySelector( 'a' );
 
 			linkFeature._showPanel();
@@ -173,7 +173,7 @@ describe( 'Link', () => {
 		} );
 
 		it( 'should disable #formView elements when link and unlink commands are disabled', () => {
-			setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[o]o</paragraph>' );
 
 			linkFeature._showPanel();
 
@@ -196,17 +196,17 @@ describe( 'Link', () => {
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/53
 		it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => {
-			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 			linkFeature._showPanel();
 			expect( formView.unlinkButtonView.isVisible ).to.be.false;
 
-			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 			linkFeature._showPanel();
 			expect( formView.unlinkButtonView.isVisible ).to.be.true;
 
-			setModelData( editor.document, '<paragraph><$text linkHref="url">[fo]o</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">[fo]o</$text></paragraph>' );
 
 			linkFeature._showPanel();
 			expect( formView.unlinkButtonView.isVisible ).to.be.true;
@@ -214,7 +214,7 @@ describe( 'Link', () => {
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/78
 		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (selected link)', () => {
-			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+			setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 			// Mock some leftover value **in DOM**, e.g. after previous editing.
 			formView.urlInputView.inputView.element.value = 'leftover';
@@ -225,7 +225,7 @@ describe( 'Link', () => {
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/123
 		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (no link selected)', () => {
-			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+			setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 			linkFeature._showPanel();
 			expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
@@ -235,7 +235,7 @@ describe( 'Link', () => {
 			it( 'should not duplicate #render listeners', () => {
 				const viewDocument = editor.editing.view;
 
-				setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 
@@ -252,7 +252,7 @@ describe( 'Link', () => {
 			it( 'updates the position of the panel – editing a link, then the selection remains in the link upon #render', () => {
 				const viewDocument = editor.editing.view;
 
-				setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 				linkFeature._showPanel();
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
@@ -274,7 +274,7 @@ describe( 'Link', () => {
 			it( 'updates the position of the panel – creating a new link, then the selection moved upon #render', () => {
 				const viewDocument = editor.editing.view;
 
-				setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 				linkFeature._showPanel();
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
@@ -296,7 +296,7 @@ describe( 'Link', () => {
 			it( 'hides of the panel – editing a link, then the selection moved out of the link upon #render', () => {
 				const viewDocument = editor.editing.view;
 
-				setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
+				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
 
 				linkFeature._showPanel();
 
@@ -319,7 +319,7 @@ describe( 'Link', () => {
 				const viewDocument = editor.editing.view;
 
 				setModelData(
-					editor.document,
+					editor.model,
 					'<paragraph><$text linkHref="url">f[]oo</$text>bar<$text linkHref="url">b[]az</$text></paragraph>'
 				);
 
@@ -343,7 +343,7 @@ describe( 'Link', () => {
 			it( 'hides the panel – editing a link, then the selection expands upon #render', () => {
 				const viewDocument = editor.editing.view;
 
-				setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
+				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 				linkFeature._showPanel();
 
@@ -596,69 +596,69 @@ describe( 'Link', () => {
 
 			beforeEach( () => {
 				observer = editor.editing.view.getObserver( ClickObserver );
-				editor.document.schema.allow( { name: '$text', inside: '$root' } );
+				editor.model.schema.allow( { name: '$text', inside: '$root' } );
 
 				spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
 			} );
 
 			it( 'should open with not selected formView when collapsed selection is inside link element', () => {
-				setModelData( editor.document, '<$text linkHref="url">fo[]o</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">fo[]o</$text>' );
 
 				observer.fire( 'click', { target: document.body } );
 				sinon.assert.calledWithExactly( spy );
 			} );
 
 			it( 'should open when selection exclusively encloses a LinkElement (#1)', () => {
-				setModelData( editor.document, '[<$text linkHref="url">foo</$text>]' );
+				setModelData( editor.model, '[<$text linkHref="url">foo</$text>]' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.calledWithExactly( spy );
 			} );
 
 			it( 'should open when selection exclusively encloses a LinkElement (#2)', () => {
-				setModelData( editor.document, '<$text linkHref="url">[foo]</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">[foo]</$text>' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.calledWithExactly( spy );
 			} );
 
 			it( 'should not open when selection is not inside link element', () => {
-				setModelData( editor.document, '[]' );
+				setModelData( editor.model, '[]' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 			} );
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#1)', () => {
-				setModelData( editor.document, '<$text linkHref="url">f[o]o</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">f[o]o</$text>' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 			} );
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#2)', () => {
-				setModelData( editor.document, '<$text linkHref="url">[fo]o</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">[fo]o</$text>' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 			} );
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#3)', () => {
-				setModelData( editor.document, '<$text linkHref="url">f[oo]</$text>' );
+				setModelData( editor.model, '<$text linkHref="url">f[oo]</$text>' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 			} );
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#4)', () => {
-				setModelData( editor.document, 'ba[r<$text linkHref="url">foo]</$text>' );
+				setModelData( editor.model, 'ba[r<$text linkHref="url">foo]</$text>' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );
 			} );
 
 			it( 'should not open when selection is non-collapsed and doesn\'t enclose a LinkElement (#5)', () => {
-				setModelData( editor.document, 'ba[r<$text linkHref="url">foo</$text>]' );
+				setModelData( editor.model, 'ba[r<$text linkHref="url">foo</$text>]' );
 
 				observer.fire( 'click', { target: {} } );
 				sinon.assert.notCalled( spy );

+ 42 - 42
packages/ckeditor5-link/tests/linkcommand.js

@@ -8,22 +8,22 @@ import LinkCommand from '../src/linkcommand';
 import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'LinkCommand', () => {
-	let editor, document, command;
+	let editor, model, command;
 
 	beforeEach( () => {
 		return ModelTestEditor.create()
 			.then( newEditor => {
 				editor = newEditor;
-				document = editor.document;
+				model = editor.model;
 				command = new LinkCommand( editor );
 
 				// Allow text in $root.
-				document.schema.allow( { name: '$text', inside: '$root' } );
+				model.schema.allow( { name: '$text', inside: '$root' } );
 
 				// Allow text with `linkHref` attribute in paragraph.
-				document.schema.registerItem( 'p', '$block' );
-				document.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
-				document.schema.allow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
+				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
 			} );
 	} );
 
@@ -36,30 +36,30 @@ describe( 'LinkCommand', () => {
 		// refresh() uses `isAttributeAllowedInSelection` helper which is fully tested in his own test.
 
 		beforeEach( () => {
-			document.schema.registerItem( 'x', '$block' );
-			document.schema.disallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
+			model.schema.registerItem( 'x', '$block' );
+			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
 		} );
 
 		describe( 'when selection is collapsed', () => {
 			it( 'should be true if characters with the attribute can be placed at caret position', () => {
-				setData( document, '<p>f[]oo</p>' );
+				setData( model, '<p>f[]oo</p>' );
 				expect( command.isEnabled ).to.be.true;
 			} );
 
 			it( 'should be false if characters with the attribute cannot be placed at caret position', () => {
-				setData( document, '<x>fo[]o</x>' );
+				setData( model, '<x>fo[]o</x>' );
 				expect( command.isEnabled ).to.be.false;
 			} );
 		} );
 
 		describe( 'when selection is not collapsed', () => {
 			it( 'should be true if there is at least one node in selection that can have the attribute', () => {
-				setData( document, '<p>[foo]</p>' );
+				setData( model, '<p>[foo]</p>' );
 				expect( command.isEnabled ).to.be.true;
 			} );
 
 			it( 'should be false if there are no nodes in selection that can have the attribute', () => {
-				setData( document, '<x>[foo]</x>' );
+				setData( model, '<x>[foo]</x>' );
 				expect( command.isEnabled ).to.be.false;
 			} );
 		} );
@@ -68,13 +68,13 @@ describe( 'LinkCommand', () => {
 	describe( 'value', () => {
 		describe( 'collapsed selection', () => {
 			it( 'should be equal attribute value when selection is placed inside element with `linkHref` attribute', () => {
-				setData( document, '<$text linkHref="url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="url">foo[]bar</$text>' );
 
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should be undefined when selection is placed inside element without `linkHref` attribute', () => {
-				setData( document, '<$text bold="true">foo[]bar</$text>' );
+				setData( model, '<$text bold="true">foo[]bar</$text>' );
 
 				expect( command.value ).to.be.undefined;
 			} );
@@ -82,13 +82,13 @@ describe( 'LinkCommand', () => {
 
 		describe( 'non-collapsed selection', () => {
 			it( 'should be equal attribute value when selection contains only elements with `linkHref` attribute', () => {
-				setData( document, 'fo[<$text linkHref="url">ob</$text>]ar' );
+				setData( model, 'fo[<$text linkHref="url">ob</$text>]ar' );
 
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should be undefined when selection contains not only elements with `linkHref` attribute', () => {
-				setData( document, 'f[o<$text linkHref="url">ob</$text>]ar' );
+				setData( model, 'f[o<$text linkHref="url">ob</$text>]ar' );
 
 				expect( command.value ).to.be.undefined;
 			} );
@@ -98,25 +98,25 @@ describe( 'LinkCommand', () => {
 	describe( 'execute()', () => {
 		describe( 'non-collapsed selection', () => {
 			it( 'should set `linkHref` attribute to selected text', () => {
-				setData( document, 'f[ooba]r' );
+				setData( model, 'f[ooba]r' );
 
 				expect( command.value ).to.be.undefined;
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
+				expect( getData( model ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should set `linkHref` attribute to selected text when text already has attributes', () => {
-				setData( document, 'f[o<$text bold="true">oba]r</$text>' );
+				setData( model, 'f[o<$text bold="true">oba]r</$text>' );
 
 				expect( command.value ).to.be.undefined;
 
 				command.execute( 'url' );
 
 				expect( command.value ).to.equal( 'url' );
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'f[<$text linkHref="url">o</$text>' +
 					'<$text bold="true" linkHref="url">oba</$text>]' +
 					'<$text bold="true">r</$text>'
@@ -124,24 +124,24 @@ describe( 'LinkCommand', () => {
 			} );
 
 			it( 'should overwrite existing `linkHref` attribute when selected text wraps text with `linkHref` attribute', () => {
-				setData( document, 'f[o<$text linkHref="other url">o</$text>ba]r' );
+				setData( model, 'f[o<$text linkHref="other url">o</$text>ba]r' );
 
 				expect( command.value ).to.be.undefined;
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
+				expect( getData( model ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should split text and overwrite attribute value when selection is inside text with `linkHref` attribute', () => {
-				setData( document, 'f<$text linkHref="other url">o[ob]a</$text>r' );
+				setData( model, 'f<$text linkHref="other url">o[ob]a</$text>r' );
 
 				expect( command.value ).to.equal( 'other url' );
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'f' +
 					'<$text linkHref="other url">o</$text>' +
 					'[<$text linkHref="url">ob</$text>]' +
@@ -154,51 +154,51 @@ describe( 'LinkCommand', () => {
 			it( 'should overwrite `linkHref` attribute of selected text only, ' +
 				'when selection start inside text with `linkHref` attribute',
 			() => {
-				setData( document, 'f<$text linkHref="other url">o[o</$text>ba]r' );
+				setData( model, 'f<$text linkHref="other url">o[o</$text>ba]r' );
 
 				expect( command.value ).to.equal( 'other url' );
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( 'f<$text linkHref="other url">o</$text>[<$text linkHref="url">oba</$text>]r' );
+				expect( getData( model ) ).to.equal( 'f<$text linkHref="other url">o</$text>[<$text linkHref="url">oba</$text>]r' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should overwrite `linkHref` attribute of selected text only, when selection end inside text with `linkHref` ' +
 				'attribute', () => {
-				setData( document, 'f[o<$text linkHref="other url">ob]a</$text>r' );
+				setData( model, 'f[o<$text linkHref="other url">ob]a</$text>r' );
 
 				expect( command.value ).to.be.undefined;
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">oob</$text>]<$text linkHref="other url">a</$text>r' );
+				expect( getData( model ) ).to.equal( 'f[<$text linkHref="url">oob</$text>]<$text linkHref="other url">a</$text>r' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should set `linkHref` attribute to selected text when text is split by $block element', () => {
-				setData( document, '<p>f[oo</p><p>ba]r</p>' );
+				setData( model, '<p>f[oo</p><p>ba]r</p>' );
 
 				expect( command.value ).to.be.undefined;
 
 				command.execute( 'url' );
 
-				expect( getData( document ) )
+				expect( getData( model ) )
 					.to.equal( '<p>f[<$text linkHref="url">oo</$text></p><p><$text linkHref="url">ba</$text>]r</p>' );
 				expect( command.value ).to.equal( 'url' );
 			} );
 
 			it( 'should set `linkHref` attribute only to allowed elements and omit disallowed', () => {
 				// Disallow text in img.
-				document.schema.registerItem( 'img', '$inline' );
+				model.schema.registerItem( 'img', '$inline' );
 
-				setData( document, '<p>f[oo<img></img>ba]r</p>' );
+				setData( model, '<p>f[oo<img></img>ba]r</p>' );
 
 				expect( command.value ).to.be.undefined;
 
 				command.execute( 'url' );
 
-				expect( getData( document ) )
+				expect( getData( model ) )
 					.to.equal( '<p>f[<$text linkHref="url">oo</$text><img></img><$text linkHref="url">ba</$text>]r</p>' );
 				expect( command.value ).to.equal( 'url' );
 			} );
@@ -206,38 +206,38 @@ describe( 'LinkCommand', () => {
 
 		describe( 'collapsed selection', () => {
 			it( 'should insert text with `linkHref` attribute, text data equal to href and select new link', () => {
-				setData( document, 'foo[]bar' );
+				setData( model, 'foo[]bar' );
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
+				expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
 
 			it( 'should insert text with `linkHref` attribute, and selection attributes', () => {
-				setData( document, '<$text bold="true">foo[]bar</$text>', {
+				setData( model, '<$text bold="true">foo[]bar</$text>', {
 					selectionAttributes: { bold: true }
 				} );
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( '<$text bold="true">foo[<$text linkHref="url">url</$text>]bar</$text>' );
+				expect( getData( model ) ).to.equal( '<$text bold="true">foo[<$text linkHref="url">url</$text>]bar</$text>' );
 			} );
 
 			it( 'should update `linkHref` attribute and select whole link when selection is inside text with `linkHref` attribute', () => {
-				setData( document, '<$text linkHref="other url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="other url">foo[]bar</$text>' );
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( '[<$text linkHref="url">foobar</$text>]' );
+				expect( getData( model ) ).to.equal( '[<$text linkHref="url">foobar</$text>]' );
 			} );
 
 			it( 'should not insert text with `linkHref` attribute when is not allowed in parent', () => {
-				document.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
-				setData( document, '<p>foo[]bar</p>' );
+				model.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
+				setData( model, '<p>foo[]bar</p>' );
 
 				command.execute( 'url' );
 
-				expect( getData( document ) ).to.equal( '<p>foo[]bar</p>' );
+				expect( getData( model ) ).to.equal( '<p>foo[]bar</p>' );
 			} );
 		} );
 	} );

+ 13 - 14
packages/ckeditor5-link/tests/linkengine.js

@@ -16,7 +16,7 @@ import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils
 import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
 
 describe( 'LinkEngine', () => {
-	let editor, doc;
+	let editor, model;
 
 	beforeEach( () => {
 		return VirtualTestEditor
@@ -25,8 +25,7 @@ describe( 'LinkEngine', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-
-				doc = editor.document;
+				model = editor.model;
 			} );
 	} );
 
@@ -35,9 +34,9 @@ describe( 'LinkEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( doc.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$root' } ) ).to.be.false;
-		expect( doc.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$block' } ) ).to.be.true;
-		expect( doc.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$root' } ) ).to.be.false;
+		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$block' } ) ).to.be.true;
+		expect( model.schema.check( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } ) ).to.be.true;
 	} );
 
 	describe( 'command', () => {
@@ -58,7 +57,7 @@ describe( 'LinkEngine', () => {
 		it( 'should convert `<a href="url">` to `linkHref="url"` attribute', () => {
 			editor.setData( '<p><a href="url">foo</a>bar</p>' );
 
-			expect( getModelData( doc, { withoutSelection: true } ) )
+			expect( getModelData( model, { withoutSelection: true } ) )
 				.to.equal( '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 			expect( editor.getData() ).to.equal( '<p><a href="url">foo</a>bar</p>' );
@@ -70,7 +69,7 @@ describe( 'LinkEngine', () => {
 
 			editor.setData( '<a href="url">foo</a>bar' );
 
-			expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
 
 			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
 		} );
@@ -79,7 +78,7 @@ describe( 'LinkEngine', () => {
 		it( 'should not pick up `<a name="foo">`', () => {
 			editor.setData( '<p><a name="foo">foo</a>bar</p>' );
 
-			expect( getModelData( doc, { withoutSelection: true } ) )
+			expect( getModelData( model, { withoutSelection: true } ) )
 				.to.equal( '<paragraph>foobar</paragraph>' );
 		} );
 
@@ -87,7 +86,7 @@ describe( 'LinkEngine', () => {
 		it( 'should pick up `<a href="">`', () => {
 			editor.setData( '<p><a href="">foo</a>bar</p>' );
 
-			expect( getModelData( doc, { withoutSelection: true } ) )
+			expect( getModelData( model, { withoutSelection: true } ) )
 				.to.equal( '<paragraph><$text linkHref="">foo</$text>bar</paragraph>' );
 
 			expect( editor.getData() ).to.equal( '<p><a href="">foo</a>bar</p>' );
@@ -96,26 +95,26 @@ describe( 'LinkEngine', () => {
 
 	describe( 'editing pipeline conversion', () => {
 		it( 'should convert attribute', () => {
-			setModelData( doc, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
+			setModelData( model, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><a href="url">foo</a>bar</p>' );
 		} );
 
 		it( 'should convert to `LinkElement` instance', () => {
-			setModelData( doc, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
+			setModelData( model, '<paragraph><$text linkHref="url">foo</$text>bar</paragraph>' );
 
 			expect( editor.editing.view.getRoot().getChild( 0 ).getChild( 0 ) ).to.be.instanceof( LinkElement );
 		} );
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/121
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
-			editor.document.schema.allow( { name: '$inline', attributes: [ 'foo' ], inside: '$block' } );
+			model.schema.allow( { name: '$inline', attributes: [ 'foo' ], inside: '$block' } );
 
 			buildModelConverter().for( editor.data.modelToView )
 				.fromAttribute( 'foo' )
 				.toElement( 'f' );
 
-			setModelData( doc,
+			setModelData( model,
 				'<paragraph>' +
 					'<$text linkHref="url">a</$text><$text foo="true" linkHref="url">b</$text><$text linkHref="url">c</$text>' +
 				'</paragraph>' );

+ 32 - 31
packages/ckeditor5-link/tests/unlinkcommand.js

@@ -11,21 +11,22 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 testUtils.createSinonSandbox();
 
 describe( 'UnlinkCommand', () => {
-	let editor, document, command;
+	let editor, model, document, command;
 
 	beforeEach( () => {
 		return ModelTestEditor.create()
 			.then( newEditor => {
 				editor = newEditor;
-				document = editor.document;
+				model = editor.model;
+				document = model.document;
 				command = new UnlinkCommand( editor );
 
 				// Allow text in $root.
-				document.schema.allow( { name: '$text', inside: '$root' } );
+				model.schema.allow( { name: '$text', inside: '$root' } );
 
 				// Allow text with `linkHref` attribute in paragraph.
-				document.schema.registerItem( 'p', '$block' );
-				document.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
+				model.schema.registerItem( 'p', '$block' );
+				model.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
 			} );
 	} );
 
@@ -35,7 +36,7 @@ describe( 'UnlinkCommand', () => {
 
 	describe( 'isEnabled', () => {
 		it( 'should be true when selection has `linkHref` attribute', () => {
-			document.enqueueChanges( () => {
+			model.change( () => {
 				document.selection.setAttribute( 'linkHref', 'value' );
 			} );
 
@@ -43,7 +44,7 @@ describe( 'UnlinkCommand', () => {
 		} );
 
 		it( 'should be false when selection doesn\'t have `linkHref` attribute', () => {
-			document.enqueueChanges( () => {
+			model.change( () => {
 				document.selection.removeAttribute( 'linkHref' );
 			} );
 
@@ -54,19 +55,19 @@ describe( 'UnlinkCommand', () => {
 	describe( 'execute()', () => {
 		describe( 'non-collapsed selection', () => {
 			it( 'should remove `linkHref` attribute from selected text', () => {
-				setData( document, '<$text linkHref="url">f[ooba]r</$text>' );
+				setData( model, '<$text linkHref="url">f[ooba]r</$text>' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal( '<$text linkHref="url">f</$text>[ooba]<$text linkHref="url">r</$text>' );
+				expect( getData( model ) ).to.equal( '<$text linkHref="url">f</$text>[ooba]<$text linkHref="url">r</$text>' );
 			} );
 
 			it( 'should remove `linkHref` attribute from selected text and do not modified other attributes', () => {
-				setData( document, '<$text bold="true" linkHref="url">f[ooba]r</$text>' );
+				setData( model, '<$text bold="true" linkHref="url">f[ooba]r</$text>' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'<$text bold="true" linkHref="url">f</$text>' +
 					'[<$text bold="true">ooba</$text>]' +
 					'<$text bold="true" linkHref="url">r</$text>'
@@ -74,15 +75,15 @@ describe( 'UnlinkCommand', () => {
 			} );
 
 			it( 'should remove `linkHref` attribute from selected text when attributes have different value', () => {
-				setData( document, '[<$text linkHref="url">foo</$text><$text linkHref="other url">bar</$text>]' );
+				setData( model, '[<$text linkHref="url">foo</$text><$text linkHref="other url">bar</$text>]' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal( '[foobar]' );
+				expect( getData( model ) ).to.equal( '[foobar]' );
 			} );
 
 			it( 'should remove `linkHref` attribute from selection', () => {
-				setData( document, '<$text linkHref="url">f[ooba]r</$text>' );
+				setData( model, '<$text linkHref="url">f[ooba]r</$text>' );
 
 				command.execute();
 
@@ -92,17 +93,17 @@ describe( 'UnlinkCommand', () => {
 
 		describe( 'collapsed selection', () => {
 			it( 'should remove `linkHref` attribute from selection siblings with the same attribute value', () => {
-				setData( document, '<$text linkHref="url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="url">foo[]bar</$text>' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal( 'foo[]bar' );
+				expect( getData( model ) ).to.equal( 'foo[]bar' );
 			} );
 
 			it( 'should remove `linkHref` attribute from selection siblings with the same attribute value and do not modify ' +
 				'other attributes', () => {
 				setData(
-					document,
+					model,
 					'<$text linkHref="other url">fo</$text>' +
 					'<$text linkHref="url">o[]b</$text>' +
 					'<$text linkHref="other url">ar</$text>'
@@ -110,7 +111,7 @@ describe( 'UnlinkCommand', () => {
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'<$text linkHref="other url">fo</$text>' +
 					'o[]b' +
 					'<$text linkHref="other url">ar</$text>'
@@ -120,7 +121,7 @@ describe( 'UnlinkCommand', () => {
 			it( 'should do nothing with nodes with the same `linkHref` value when there is a node with different value `linkHref` ' +
 				'attribute between', () => {
 				setData(
-					document,
+					model,
 					'<$text linkHref="same url">f</$text>' +
 					'<$text linkHref="other url">o</$text>' +
 					'<$text linkHref="same url">o[]b</$text>' +
@@ -130,7 +131,7 @@ describe( 'UnlinkCommand', () => {
 
 				command.execute();
 
-				expect( getData( document ) )
+				expect( getData( model ) )
 					.to.equal(
 						'<$text linkHref="same url">f</$text>' +
 						'<$text linkHref="other url">o</$text>' +
@@ -144,7 +145,7 @@ describe( 'UnlinkCommand', () => {
 				'and do nothing with other attributes',
 			() => {
 				setData(
-					document,
+					model,
 					'<$text linkHref="url">f</$text>' +
 					'<$text bold="true" linkHref="url">o</$text>' +
 					'<$text linkHref="url">o[]b</$text>' +
@@ -154,7 +155,7 @@ describe( 'UnlinkCommand', () => {
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'f' +
 					'<$text bold="true">o</$text>' +
 					'o[]b' +
@@ -165,7 +166,7 @@ describe( 'UnlinkCommand', () => {
 
 			it( 'should remove `linkHref` attribute from selection siblings only in the same parent as selection parent', () => {
 				setData(
-					document,
+					model,
 					'<p><$text linkHref="url">bar</$text></p>' +
 					'<p><$text linkHref="url">fo[]o</$text></p>' +
 					'<p><$text linkHref="url">bar</$text></p>'
@@ -173,7 +174,7 @@ describe( 'UnlinkCommand', () => {
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal(
+				expect( getData( model ) ).to.equal(
 					'<p><$text linkHref="url">bar</$text></p>' +
 					'<p>fo[]o</p>' +
 					'<p><$text linkHref="url">bar</$text></p>'
@@ -181,33 +182,33 @@ describe( 'UnlinkCommand', () => {
 			} );
 
 			it( 'should remove `linkHref` attribute from selection siblings when selection is at the end of link', () => {
-				setData( document, '<$text linkHref="url">foobar</$text>[]' );
+				setData( model, '<$text linkHref="url">foobar</$text>[]' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal( 'foobar[]' );
+				expect( getData( model ) ).to.equal( 'foobar[]' );
 			} );
 
 			it( 'should remove `linkHref` attribute from selection siblings when selection is at the beginning of link', () => {
-				setData( document, '[]<$text linkHref="url">foobar</$text>' );
+				setData( model, '[]<$text linkHref="url">foobar</$text>' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal( '[]foobar' );
+				expect( getData( model ) ).to.equal( '[]foobar' );
 			} );
 
 			it( 'should remove `linkHref` attribute from selection siblings on the left side when selection is between two elements with ' +
 				'different `linkHref` attributes',
 			() => {
-				setData( document, '<$text linkHref="url">foo</$text>[]<$text linkHref="other url">bar</$text>' );
+				setData( model, '<$text linkHref="url">foo</$text>[]<$text linkHref="other url">bar</$text>' );
 
 				command.execute();
 
-				expect( getData( document ) ).to.equal( 'foo[]<$text linkHref="other url">bar</$text>' );
+				expect( getData( model ) ).to.equal( 'foo[]<$text linkHref="other url">bar</$text>' );
 			} );
 
 			it( 'should remove `linkHref` attribute from selection', () => {
-				setData( document, '<$text linkHref="url">foo[]bar</$text>' );
+				setData( model, '<$text linkHref="url">foo[]bar</$text>' );
 
 				command.execute();