From 588a0657eadd81870ec129d911672b36d2cd1f89 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Mon, 1 Jul 2019 12:31:35 +0200 Subject: [PATCH 1/6] Tests: overload ignoreStyle, so it accepts functions. --- tests/plugins/widget/_helpers/tools.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index ede46dc2dd2..63690f6a12f 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -18,6 +18,7 @@ var widgetTestsTools = ( function() { // // @param config.newData // @param config.newWidgetPattern + // @param {Boolean/function} [config.ignoreStyle=false] function addTests( tcs, config ) { var editor, editorBot, @@ -32,7 +33,10 @@ var widgetTestsTools = ( function() { loaded: function( evt ) { editor = evt.editor; - initialData = fixHtml( editor.getData(), config.ignoreStyle ); + var ignoreStyle = config.ignoreStyle; + ignoreStyle = typeof ignoreStyle === 'function' ? ignoreStyle( this ) : ignoreStyle; + + initialData = fixHtml( editor.getData(), ignoreStyle ); editor.dataProcessor.writer.sortAttributes = true; }, From 85bc7324889f0a7cfefba824c92ca938d2e21ab1 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Mon, 1 Jul 2019 12:31:56 +0200 Subject: [PATCH 2/6] Tests: use isSupportedEnvironment property in ignoreStyle option. --- tests/plugins/mathjax/mathjax-mock.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/plugins/mathjax/mathjax-mock.js b/tests/plugins/mathjax/mathjax-mock.js index 3dfb294bd9e..0d324757cca 100644 --- a/tests/plugins/mathjax/mathjax-mock.js +++ b/tests/plugins/mathjax/mathjax-mock.js @@ -169,7 +169,7 @@ [ 'info', 'equation', '2 + 2 = 4' ] ], newWidgetPattern: /\\\(2 \+ 2 = 4\\\)<\/span>/, - ignoreStyle: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ? true : false + ignoreStyle: isSupportedEnvironment } ); tools.addTests( tcs, { @@ -188,7 +188,7 @@ [ 'info', 'equation', '2 + 2 = 4' ] ], newWidgetPattern: /\\\(2 \+ 2 = 4\\\)<\/span>/, - ignoreStyle: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ? true : false + ignoreStyle: isSupportedEnvironment } ); tools.addTests( tcs, { @@ -204,8 +204,12 @@ [ 'info', 'equation', '2 + 2 = 4' ] ], newWidgetPattern: /\\\(2 \+ 2 = 4\\\)<\/span>/, - ignoreStyle: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ? true : false + ignoreStyle: isSupportedEnvironment } ); bender.test( tcs ); + + function isSupportedEnvironment( editor ) { + return !editor.plugins.mathjax.isSupportedEnvironment(); + } } )(); From d2ea469ed7330951c2c6cc726198f1301183ab4d Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Mon, 8 Jul 2019 12:12:36 +0200 Subject: [PATCH 3/6] Adjust API docs type. --- tests/plugins/widget/_helpers/tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index 63690f6a12f..6748eb20017 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -18,7 +18,7 @@ var widgetTestsTools = ( function() { // // @param config.newData // @param config.newWidgetPattern - // @param {Boolean/function} [config.ignoreStyle=false] + // @param {Boolean/Function} [config.ignoreStyle=false] function addTests( tcs, config ) { var editor, editorBot, From 81b59420366fd16c93b1919e4fc00c07db261103 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Mon, 8 Jul 2019 12:14:55 +0200 Subject: [PATCH 4/6] Tests: rename variable. --- tests/plugins/widget/_helpers/tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index 6748eb20017..7950e9095de 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -34,7 +34,7 @@ var widgetTestsTools = ( function() { editor = evt.editor; var ignoreStyle = config.ignoreStyle; - ignoreStyle = typeof ignoreStyle === 'function' ? ignoreStyle( this ) : ignoreStyle; + ignoreStyle = typeof ignoreStyle === 'function' ? ignoreStyle( editor ) : ignoreStyle; initialData = fixHtml( editor.getData(), ignoreStyle ); From 01a798d33001880df8419ff350078b0f1ce32475 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Mon, 8 Jul 2019 12:15:24 +0200 Subject: [PATCH 5/6] Tests: rename function. --- tests/plugins/mathjax/mathjax-mock.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/plugins/mathjax/mathjax-mock.js b/tests/plugins/mathjax/mathjax-mock.js index 0d324757cca..40aeb60587a 100644 --- a/tests/plugins/mathjax/mathjax-mock.js +++ b/tests/plugins/mathjax/mathjax-mock.js @@ -169,7 +169,7 @@ [ 'info', 'equation', '2 + 2 = 4' ] ], newWidgetPattern: /\\\(2 \+ 2 = 4\\\)<\/span>/, - ignoreStyle: isSupportedEnvironment + ignoreStyle: shouldIgnoreStyle } ); tools.addTests( tcs, { @@ -188,7 +188,7 @@ [ 'info', 'equation', '2 + 2 = 4' ] ], newWidgetPattern: /\\\(2 \+ 2 = 4\\\)<\/span>/, - ignoreStyle: isSupportedEnvironment + ignoreStyle: shouldIgnoreStyle } ); tools.addTests( tcs, { @@ -204,12 +204,12 @@ [ 'info', 'equation', '2 + 2 = 4' ] ], newWidgetPattern: /\\\(2 \+ 2 = 4\\\)<\/span>/, - ignoreStyle: isSupportedEnvironment + ignoreStyle: shouldIgnoreStyle } ); bender.test( tcs ); - function isSupportedEnvironment( editor ) { + function shouldIgnoreStyle( editor ) { return !editor.plugins.mathjax.isSupportedEnvironment(); } } )(); From 3438f40d5bc052364ac57d18dd1c3f4261714d32 Mon Sep 17 00:00:00 2001 From: Kajetan Litwinowicz Date: Mon, 8 Jul 2019 13:40:05 +0200 Subject: [PATCH 6/6] Move detecting type of ignoreStyle into fixHtml. --- tests/plugins/widget/_helpers/tools.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index 7950e9095de..5061e46c23d 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -33,10 +33,7 @@ var widgetTestsTools = ( function() { loaded: function( evt ) { editor = evt.editor; - var ignoreStyle = config.ignoreStyle; - ignoreStyle = typeof ignoreStyle === 'function' ? ignoreStyle( editor ) : ignoreStyle; - - initialData = fixHtml( editor.getData(), ignoreStyle ); + initialData = fixHtml( editor.getData(), config.ignoreStyle, editor ); editor.dataProcessor.writer.sortAttributes = true; }, @@ -73,7 +70,7 @@ var widgetTestsTools = ( function() { // Wait & ensure async. wait( function() { editor.setMode( 'source', function() { - sourceModeData = fixHtml( editor.getData(), config.ignoreStyle ); + sourceModeData = fixHtml( editor.getData(), config.ignoreStyle, editor ); editor.setMode( 'wysiwyg', function() { resume( function() { @@ -137,7 +134,7 @@ var widgetTestsTools = ( function() { var instances = bender.tools.objToArray( editor.widgets.instances ); assert.areSame( config.initialInstancesNumber, instances.length, 'instances number ' + msg ); - checkData && assert.areSame( initialData, fixHtml( editor.getData(), config.ignoreStyle ), 'data ' + msg ); + checkData && assert.areSame( initialData, fixHtml( editor.getData(), config.ignoreStyle, editor ), 'data ' + msg ); var editable = editor.editable(); for ( var i = 0; i < instances.length; ++i ) @@ -151,12 +148,15 @@ var widgetTestsTools = ( function() { return CKEDITOR.tools.object.keys( classesObj ).sort(); } - function fixHtml( html, ignoreStyle ) { + function fixHtml( html, ignoreStyle, editor ) { // Because IE modify style attribute we should fix it or totally ignore style attribute. html = html.replace( /style="([^"]*)"/g, function( styleStr ) { + ignoreStyle = typeof ignoreStyle === 'function' ? ignoreStyle( editor ) : ignoreStyle; + // If there are too many problems with styles just ignore them. - if ( ignoreStyle ) + if ( ignoreStyle ) { return ''; + } // If it is only the matter of spacers and semicolons fix attributes. var style = styleStr.substr( 7, styleStr.length - 8 );