Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing config.ignoreStyle to widgetTools.addTests as function type #3230

Merged
merged 6 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions tests/plugins/mathjax/mathjax-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
[ 'info', 'equation', '2 + 2 = 4' ]
],
newWidgetPattern: /<span class="math-tex">\\\(2 \+ 2 = 4\\\)<\/span>/,
ignoreStyle: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ? true : false
ignoreStyle: shouldIgnoreStyle
} );

tools.addTests( tcs, {
Expand All @@ -188,7 +188,7 @@
[ 'info', 'equation', '2 + 2 = 4' ]
],
newWidgetPattern: /<span class="mjx">\\\(2 \+ 2 = 4\\\)<\/span>/,
ignoreStyle: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ? true : false
ignoreStyle: shouldIgnoreStyle
} );

tools.addTests( tcs, {
Expand All @@ -204,8 +204,12 @@
[ 'info', 'equation', '2 + 2 = 4' ]
],
newWidgetPattern: /<span class="math-tex">\\\(2 \+ 2 = 4\\\)<\/span>/,
ignoreStyle: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ? true : false
ignoreStyle: shouldIgnoreStyle
} );

bender.test( tcs );

function shouldIgnoreStyle( editor ) {
return !editor.plugins.mathjax.isSupportedEnvironment();
}
} )();
14 changes: 9 additions & 5 deletions tests/plugins/widget/_helpers/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,7 +33,7 @@ var widgetTestsTools = ( function() {
loaded: function( evt ) {
editor = evt.editor;

initialData = fixHtml( editor.getData(), config.ignoreStyle );
initialData = fixHtml( editor.getData(), config.ignoreStyle, editor );

editor.dataProcessor.writer.sortAttributes = true;
},
Expand Down Expand Up @@ -69,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() {
Expand Down Expand Up @@ -133,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 )
Expand All @@ -147,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 );
Expand Down