瀏覽代碼

Fourth batch of changes aligning schema use to the new API.

Piotrek Koszuliński 8 年之前
父節點
當前提交
79c69f0b02
共有 2 個文件被更改,包括 32 次插入13 次删除
  1. 18 8
      packages/ckeditor5-paragraph/tests/paragraph.js
  2. 14 5
      packages/ckeditor5-paragraph/tests/paragraphcommand.js

+ 18 - 8
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -168,7 +168,14 @@ describe( 'Paragraph feature', () => {
 			} );
 
 			it( 'should not fail when text is not allowed in paragraph', () => {
-				model.schema.disallow( { name: '$text', inside: [ '$root', 'paragraph' ] } );
+				model.schema.on( 'checkChild', ( evt, args ) => {
+					const rule = model.schema.getRule( args[ 1 ] );
+
+					if ( args[ 0 ].matchEnd( '$root paragraph' ) && rule.name == '$text' ) {
+						evt.stop();
+						evt.return = false;
+					}
+				} );
 
 				const modelFragment = editor.data.parse( 'foo' );
 
@@ -213,13 +220,9 @@ describe( 'Paragraph feature', () => {
 					model.schema.register( 'blockQuote', { allowIn: '$root' } );
 					model.schema.extend( '$block', { allowIn: 'blockQuote' } );
 
-					buildModelConverter().for( editor.editing.modelToView, editor.data.modelToView )
-						.fromElement( 'blockQuote' )
-						.toElement( 'blockQuote' );
-
-					buildViewConverter().for( editor.data.viewToModel ).fromElement( 'blockQuote' ).toElement( 'blockQuote' );
+					buildViewConverter().for( editor.data.viewToModel ).fromElement( 'blockquote' ).toElement( 'blockQuote' );
 
-					const modelFragment = editor.data.parse( '<blockQuote>foo<b>bar</b>bom</blockQuote>' );
+					const modelFragment = editor.data.parse( '<blockquote>foo<b>bar</b>bom</blockquote>' );
 
 					expect( stringifyModel( modelFragment ) )
 						.to.equal( '<blockQuote><paragraph>foo<$text bold="true">bar</$text>bom</paragraph></blockQuote>' );
@@ -431,7 +434,14 @@ describe( 'Paragraph feature', () => {
 		} );
 
 		it( 'should not fix root which does not allow paragraph', () => {
-			model.schema.xdisallow( 'paragraph', { allowIn: '$root' } );
+			model.schema.on( 'checkChild', ( evt, args ) => {
+				const rule = model.schema.getRule( args[ 1 ] );
+
+				if ( args[ 0 ].matchEnd( '$root' ) && rule.name == 'paragraph' ) {
+					evt.stop();
+					evt.return = false;
+				}
+			} );
 
 			model.change( writer => {
 				writer.remove( ModelRange.createIn( root ) );

+ 14 - 5
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -102,12 +102,21 @@ describe( 'ParagraphCommand', () => {
 
 		// https://github.com/ckeditor/ckeditor5-paragraph/issues/24
 		it( 'should not rename blocks which cannot become paragraphs (paragraph is not allowed in their parent)', () => {
-			model.schema.register( 'restricted' );
-			model.schema.extend( 'restricted', { allowIn: '$root' } );
-			model.schema.xdisallow( 'paragraph', { allowIn: 'restricted' } );
+			model.schema.register( 'restricted', { allowIn: '$root' } );
 
-			model.schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
-			model.schema.extend( 'fooBlock', { allowIn: 'restricted' } );
+			model.schema.register( 'fooBlock', {
+				inheritAllFrom: '$block',
+				allowIn: 'restricted'
+			} );
+
+			model.schema.on( 'checkChild', ( evt, args ) => {
+				const rule = model.schema.getRule( args[ 1 ] );
+
+				if ( args[ 0 ].matchEnd( 'restricted' ) && rule.name == 'paragraph' ) {
+					evt.stop();
+					evt.return = false;
+				}
+			} );
 
 			setData(
 				model,