8
0
Szymon Kupś 9 лет назад
Родитель
Сommit
4546ac6678

+ 12 - 0
packages/ckeditor5-engine/tests/_utils-tests/model.js

@@ -47,6 +47,12 @@ describe( 'model test utils', () => {
 			sinon.assert.calledOnce( stringifySpy );
 			sinon.assert.calledOnce( stringifySpy );
 			sinon.assert.calledWithExactly( stringifySpy, root, document.selection );
 			sinon.assert.calledWithExactly( stringifySpy, root, document.selection );
 		} );
 		} );
+
+		it( 'should throw an error when passing invalid document', () => {
+			expect( () => {
+				getData( { invalid: 'document' } );
+			} ).to.throw( TypeError, 'Document needs to be an instance of engine.model.Document.' );
+		} );
 	} );
 	} );
 
 
 	describe( 'setData', () => {
 	describe( 'setData', () => {
@@ -75,6 +81,12 @@ describe( 'model test utils', () => {
 			const args = parseSpy.firstCall.args;
 			const args = parseSpy.firstCall.args;
 			expect( args[ 0 ] ).to.equal( data );
 			expect( args[ 0 ] ).to.equal( data );
 		} );
 		} );
+
+		it( 'should throw an error when passing invalid document', () => {
+			expect( () => {
+				setData( { invalid: 'document' } );
+			} ).to.throw( TypeError, 'Document needs to be an instance of engine.model.Document.' );
+		} );
 	} );
 	} );
 
 
 	describe( 'stringify', () => {
 	describe( 'stringify', () => {

+ 12 - 0
packages/ckeditor5-engine/tests/_utils-tests/view.js

@@ -68,6 +68,12 @@ describe( 'view test utils', () => {
 				expect( stringifyOptions ).to.have.property( 'showPriority' ).that.equals( false );
 				expect( stringifyOptions ).to.have.property( 'showPriority' ).that.equals( false );
 				expect( stringifyOptions ).to.have.property( 'ignoreRoot' ).that.equals( true );
 				expect( stringifyOptions ).to.have.property( 'ignoreRoot' ).that.equals( true );
 			} );
 			} );
+
+			it( 'should throw an error when passing invalid document', () => {
+				expect( () => {
+					getData( { invalid: 'document' } );
+				} ).to.throw( TypeError, 'Document needs to be an instance of engine.view.Document.' );
+			} );
 		} );
 		} );
 
 
 		describe( 'setData', () => {
 		describe( 'setData', () => {
@@ -101,6 +107,12 @@ describe( 'view test utils', () => {
 				expect( args[ 1 ] ).to.be.an( 'object' );
 				expect( args[ 1 ] ).to.be.an( 'object' );
 				expect( args[ 1 ].rootElement ).to.equal( viewDocument.getRoot() );
 				expect( args[ 1 ].rootElement ).to.equal( viewDocument.getRoot() );
 			} );
 			} );
+
+			it( 'should throw an error when passing invalid document', () => {
+				expect( () => {
+					setData( { invalid: 'document' } );
+				} ).to.throw( TypeError, 'Document needs to be an instance of engine.view.Document.' );
+			} );
 		} );
 		} );
 	} );
 	} );
 
 

+ 8 - 0
packages/ckeditor5-engine/tests/_utils/model.js

@@ -27,6 +27,10 @@ import Document from '/ckeditor5/engine/model/document.js';
  * @returns {String} The stringified data.
  * @returns {String} The stringified data.
  */
  */
 export function getData( document, options = {} ) {
 export function getData( document, options = {} ) {
+	if ( !( document instanceof Document ) ) {
+		throw new TypeError( 'Document needs to be an instance of engine.model.Document.' );
+	}
+
 	const withoutSelection = !!options.withoutSelection;
 	const withoutSelection = !!options.withoutSelection;
 	const rootName = options.rootName || 'main';
 	const rootName = options.rootName || 'main';
 	const root = document.getRoot( rootName );
 	const root = document.getRoot( rootName );
@@ -47,6 +51,10 @@ getData._stringify = stringify;
  * used.
  * used.
  */
  */
 export function setData( document, data, options = {} ) {
 export function setData( document, data, options = {} ) {
+	if ( !( document instanceof Document ) ) {
+		throw new TypeError( 'Document needs to be an instance of engine.model.Document.' );
+	}
+
 	setData._parse( data, {
 	setData._parse( data, {
 		document: document,
 		document: document,
 		rootName: options.rootName
 		rootName: options.rootName

+ 9 - 0
packages/ckeditor5-engine/tests/_utils/view.js

@@ -5,6 +5,7 @@
 
 
 'use strict';
 'use strict';
 
 
+import Document from '/ckeditor5/engine/view/document.js';
 import ViewDocumentFragment from '/ckeditor5/engine/view/documentfragment.js';
 import ViewDocumentFragment from '/ckeditor5/engine/view/documentfragment.js';
 import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
 import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
 import ViewElement from '/ckeditor5/engine/view/element.js';
 import ViewElement from '/ckeditor5/engine/view/element.js';
@@ -36,6 +37,10 @@ const TEXT_RANGE_END_TOKEN = '}';
  * @returns {String} The stringified data.
  * @returns {String} The stringified data.
  */
  */
 export function getData( document, options = {} ) {
 export function getData( document, options = {} ) {
+	if ( !( document instanceof Document ) ) {
+		throw new TypeError( 'Document needs to be an instance of engine.view.Document.' );
+	}
+
 	const withoutSelection = !!options.withoutSelection;
 	const withoutSelection = !!options.withoutSelection;
 	const rootName = options.rootName || 'main';
 	const rootName = options.rootName || 'main';
 	const root = document.getRoot( rootName );
 	const root = document.getRoot( rootName );
@@ -63,6 +68,10 @@ getData._stringify = stringify;
  * used.
  * used.
  */
  */
 export function setData( document, data, options = {} ) {
 export function setData( document, data, options = {} ) {
+	if ( !( document instanceof Document ) ) {
+		throw new TypeError( 'Document needs to be an instance of engine.view.Document.' );
+	}
+
 	const rootName = options.rootName || 'main';
 	const rootName = options.rootName || 'main';
 	const root = document.getRoot( rootName );
 	const root = document.getRoot( rootName );
 	const result = setData._parse( data, { rootElement: root } );
 	const result = setData._parse( data, { rootElement: root } );