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

Added parameter validation for getData().

Oskar Wrobel 9 лет назад
Родитель
Сommit
f04fb50286

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

@@ -12,6 +12,7 @@ import Element from '/ckeditor5/engine/model/element.js';
 import Text from '/ckeditor5/engine/model/text.js';
 import Text from '/ckeditor5/engine/model/text.js';
 import Range from '/ckeditor5/engine/model/range.js';
 import Range from '/ckeditor5/engine/model/range.js';
 import Position from '/ckeditor5/engine/model/position.js';
 import Position from '/ckeditor5/engine/model/position.js';
+import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 
 
 describe( 'model test utils', () => {
 describe( 'model test utils', () => {
 	let document, root, selection, sandbox;
 	let document, root, selection, sandbox;
@@ -47,6 +48,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( { foo: 'bar' } );
+			} ).to.throw( CKEditorError, /model-getData-invalid-document/ );
+		} );
 	} );
 	} );
 
 
 	describe( 'setData', () => {
 	describe( 'setData', () => {

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

@@ -14,6 +14,7 @@ import Element from '/ckeditor5/engine/model/element.js';
 import DocumentFragment from '/ckeditor5/engine/model/documentfragment.js';
 import DocumentFragment from '/ckeditor5/engine/model/documentfragment.js';
 import Selection from '/ckeditor5/engine/model/selection.js';
 import Selection from '/ckeditor5/engine/model/selection.js';
 import Document from '/ckeditor5/engine/model/document.js';
 import Document from '/ckeditor5/engine/model/document.js';
+import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 
 
 /**
 /**
  * Writes the contents of the {@link engine.model.Document Document} to an HTML-like string.
  * Writes the contents of the {@link engine.model.Document Document} to an HTML-like string.
@@ -27,6 +28,13 @@ 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 CKEditorError(
+			'model-getData-invalid-document: document needs to be an instance of Document class',
+			{ 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 );