Skip to content
Permalink
Browse files

Merge pull request #333 from cksource/t/16938

T/16938 Extract common PFW tests loop.
  • Loading branch information...
Comandeer committed Apr 6, 2017
2 parents 79b1506 + 11ba9cd commit c896eaa1c024e339cea8a43542768053e007e87e
@@ -1,14 +1,27 @@
/* global assertWordFilter,Q */
/* bender-include: _helpers/pfwTools.js */
/* global assertWordFilter,Q,console */
/* exported createTestCase */

// @param {boolean} [compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than
// what will appear in the editor after all transformations and filtering.
function createTestCase( fixtureName, wordVersion, browser, tickets, compareRawData, customFilters ) {
/**
* Creates a single test case based on the options provided. It uses files located in `../_fixtures/` directory to build
* a proper assertions. The input file should be located in `../fixtures/options.name/options.wordVersion/options.browser.html`,
* and the expected output in `../_fixtures/options.name/expected.html`. If the expected output is different for the given
* browser (`options.browser`) than in the most cases the separate file can be used - it should be located
* under `../_fixtures/options.name/options.wordVersion/expected_options.browser.html`.
*
* @param {Object} options
* @param {String} options.name Fixture name.
* @param {String} options.wordVersion Fixture word version.
* @param {String} options.browser Browser name.
* @param {Boolean} [options.compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than
* what will appear in the editor after all transformations and filtering.
* @param {Array} [options.customFilters] Array of custom filters (like [ pfwTools.filters.font ]) which will be used during assertions.
* @returns {Function}
*/
function createTestCase( options ) {
return function() {
var inputPath = [ tickets ? '_fixtures/Tickets' : '_fixtures', fixtureName, wordVersion, browser ].join( '/' ) + '.html',
outputPath = [ tickets ? '_fixtures/Tickets' : '_fixtures', fixtureName, '/expected.html' ].join( '/' ),
specialCasePath = [ tickets ? '_fixtures/Tickets' : '_fixtures', fixtureName, wordVersion, 'expected_' + browser ].join( '/' ) + '.html',
var inputPath = [ '_fixtures', options.name, options.wordVersion, options.browser ].join( '/' ) + '.html',
outputPath = [ '_fixtures', options.name, '/expected.html' ].join( '/' ),
specialCasePath = [ '_fixtures', options.name, options.wordVersion, 'expected_' + options.browser ].join( '/' ) + '.html',
deCasher = '?' + Math.random().toString( 36 ).replace( /^../, '' ), // Used to trick the browser into not caching the html files.
editor = this.editor,
load = function( path ) {
@@ -32,9 +45,8 @@ function createTestCase( fixtureName, wordVersion, browser, tickets, compareRawD
// If browser-customized expected result was found, use it. Otherwise go with the regular expected.
expectedValue = values[ 2 ] !== null ? values[ 2 ] : values[ 1 ];

// null means that fixture file was not found - skipping test.
if ( inputFixture === null ) {
// null means that fixture file was not found - skipping test.

resume( function() {
assert.ignore();
} );
@@ -43,25 +55,27 @@ function createTestCase( fixtureName, wordVersion, browser, tickets, compareRawD

var nbspListener = editor.once( 'paste', function( evt ) {
// Clipboard strips white spaces from pasted content if those are not encoded.
// This is **needed only for non-IE/Edge fixtures**, as these browsers doesn't encode nbsp char on
// it's own.
if ( CKEDITOR.env.ie &&
CKEDITOR.tools.array.indexOf( [ 'chrome', 'firefox', 'safari' ], browser ) !== -1 ) {
evt.data.dataValue = evt.data.dataValue.replace( / /g, ' ' );
// This is **needed only for non-IE/Edge fixtures**, as these browsers doesn't encode nbsp char on it's own.
if ( CKEDITOR.env.ie && CKEDITOR.tools.array.indexOf( [ 'chrome', 'firefox', 'safari' ], options.browser ) !== -1 ) {
var encodedData;
/* jshint ignore:start */
encodedData = evt.data.dataValue.replace( / /g, ' ' );
/* jshint ignore:end */
evt.data.dataValue = encodedData;
}
}, null, null, 5 );

assert.isNotNull( expectedValue, '"expected.html" missing.' );

assertWordFilter( editor, compareRawData )( inputFixture, expectedValue )
assertWordFilter( editor, options.compareRawData )( inputFixture, expectedValue )
.then( function( values ) {
resume( function() {
nbspListener.removeListener();

assert.beautified.html( values[ 0 ], values[ 1 ], {
fixStyles: true,
sortAttributes: true,
customFilters: customFilters
customFilters: options.customFilters
} );
} );
}, function( err ) {
@@ -0,0 +1,64 @@
/* global createTestCase */
/* exported createTestSuite */

/**
* Creates a test suite based on the options provided. The test suite then should be passed to `bender.test` to run tests.
*
* @param {Object} options
* @param {Array} options.browsers Array of browser names.
* @param {Array} options.wordVersions Array of word version names.
* @param {Object} options.tests Object containing tests to be generated. It contains key - value pairs, where key is name of the test file and value
* is an array of wordVersions name for which tests should be generated or a boolean indicating: true - generate for all versions, false - for none.
* @param {Array} [options.testData] Test data object (may contain e.g. information about ignored tests). All created tests will be added into testData object.
* @param {Array} [options.customFilters] Array of custom filters (like [ pfwTools.filters.font ]) which will be used during assertions.
* @param {Boolean} [options.compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than
* what will appear in the editor after all transformations and filtering.
* @param {Boolean} [options.ignoreAll=false] Whenever to ignore all tests.
* @returns {Object} Test data object which should be passed to `bender.test` function.
*/
function createTestSuite( options ) {
options = CKEDITOR.tools.extend( options, {
browsers: [],
wordVersions: [],
tests: [],
testData: { _should: { ignore: {} } },
ignoreAll: false,
compareRawData: false,
customFilters: null
} );

var testData = options.testData,
testsKeys = CKEDITOR.tools.objectKeys( options.tests ),
wordVersion, testKey, testName, i, j, k;

if ( testsKeys.length ) {
for ( i = 0; i < testsKeys.length; i++ ) {
for ( j = 0; j < options.browsers.length; j++ ) {
for ( k = 0; k < options.wordVersions.length; k++ ) {

wordVersion = options.wordVersions[ k ];
testKey = testsKeys[ i ];

if ( options.tests[ testKey ] === true || CKEDITOR.tools.indexOf( options.tests[ testKey ], wordVersion ) !== -1 ) {

testName = [ 'test', testKey, wordVersion, options.browsers[ j ] ].join( ' ' );

if ( options.ignoreAll ) {
testData._should.ignore[ testName ] = true;
}

testData[ testName ] = createTestCase( {
name: testKey,
wordVersion: wordVersion,
browser: options.browsers[ j ],
compareRawData: options.compareRawData,
customFilters: options.customFilters
} );
}
}
}
}
}

return testData;
}
@@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global createTestSuite */

( function() {
'use strict';
@@ -16,32 +17,21 @@
}
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie8',
'ie11',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
tests = {
tests: {
'Config_remove_font_styles': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
testData[ [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' ) ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, true );
}
}
}
}

bender.test( testData );
compareRawData: true
} ) );
} )();
@@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase,pfwTools */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global pfwTools,createTestSuite */

( function() {
'use strict';
@@ -13,18 +14,19 @@
config: pfwTools.defaultConfig
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie8',
'ie11',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
tests = {
tests: {
'Bold': true,
'Colors': true,
'Custom_list_markers': true,
@@ -45,28 +47,9 @@
'Table_alignment': true,
'Table_vertical_alignment': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {
_should: {
ignore: {}
}
};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
var testName = [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' );

if ( CKEDITOR.env.ie && CKEDITOR.env.version <= 11 ) {
testData._should.ignore[ testName ] = true;
}

testData[ testName ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, false, [ pfwTools.filters.span ] );
}
}
}
}

bender.test( testData );
customFilters: [
pfwTools.filters.span
],
ignoreAll: CKEDITOR.env.ie && CKEDITOR.env.version <= 11
} ) );
} )();
@@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global pfwTools,createTestCase */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global pfwTools,createTestSuite */

( function() {
'use strict';
@@ -15,39 +16,26 @@
}
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'ie8',
'ie11',
'edge',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
// To test only particular word versions set the key value to an array in the form: [ 'word2007', 'word2013' ].
tests = {
tests: {
'Unordered_list_multiple': true,
'White_space': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {
_should: {
ignore: {}
}
};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
testData[ [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' ) ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, true, [ pfwTools.filters.font ] );
}
}
}
}

bender.test( testData );
customFilters: [
pfwTools.filters.font
],
compareRawData: true
} ) );
} )();
@@ -3,8 +3,9 @@
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
/* jshint ignore:end */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
/* global createTestCase,pfwTools */
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
/* global pfwTools,createTestSuite */

( function() {
'use strict';
@@ -13,42 +14,22 @@
config: pfwTools.defaultConfig
};

var browsers = [
bender.test( createTestSuite( {
browsers: [
'chrome',
'firefox',
'safari'
],
wordVersions = [
wordVersions: [
'word2007',
'word2013'
],
tests = {
tests: {
'InlineStyles': true
},
keys = CKEDITOR.tools.objectKeys( tests ),
testData = {
_should: {
ignore: {
'InlineStyles': true
}
}
};

for ( var i = 0; i < keys.length; i++ ) {
for ( var j = 0; j < wordVersions.length; j++ ) {
for ( var k = 0; k < browsers.length; k++ ) {
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
var testName = [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' );

if ( CKEDITOR.env.ie ) {
testData._should.ignore[ testName ] = true;
}

testData[ testName ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, false, [ pfwTools.filters.style ] );
}
}
}
}

bender.test( testData );
customFilters: [
pfwTools.filters.style
],
ignoreAll: CKEDITOR.env.ie
} ) );
} )();
Oops, something went wrong.

0 comments on commit c896eaa

Please sign in to comment.
You can’t perform that action at this time.