Skip to content

Commit c896eaa

Browse files
authored
Merge pull request #333 from cksource/t/16938
T/16938 Extract common PFW tests loop.
2 parents 79b1506 + 11ba9cd commit c896eaa

File tree

15 files changed

+388
-475
lines changed

15 files changed

+388
-475
lines changed

tests/plugins/pastefromword/generated/_helpers/createTestCase.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
/* global assertWordFilter,Q */
2-
/* bender-include: _helpers/pfwTools.js */
1+
/* global assertWordFilter,Q,console */
32
/* exported createTestCase */
43

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

48+
// null means that fixture file was not found - skipping test.
3549
if ( inputFixture === null ) {
36-
// null means that fixture file was not found - skipping test.
37-
3850
resume( function() {
3951
assert.ignore();
4052
} );
@@ -43,25 +55,27 @@ function createTestCase( fixtureName, wordVersion, browser, tickets, compareRawD
4355

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

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

56-
assertWordFilter( editor, compareRawData )( inputFixture, expectedValue )
70+
assertWordFilter( editor, options.compareRawData )( inputFixture, expectedValue )
5771
.then( function( values ) {
5872
resume( function() {
5973
nbspListener.removeListener();
6074

6175
assert.beautified.html( values[ 0 ], values[ 1 ], {
6276
fixStyles: true,
6377
sortAttributes: true,
64-
customFilters: customFilters
78+
customFilters: options.customFilters
6579
} );
6680
} );
6781
}, function( err ) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* global createTestCase */
2+
/* exported createTestSuite */
3+
4+
/**
5+
* Creates a test suite based on the options provided. The test suite then should be passed to `bender.test` to run tests.
6+
*
7+
* @param {Object} options
8+
* @param {Array} options.browsers Array of browser names.
9+
* @param {Array} options.wordVersions Array of word version names.
10+
* @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
11+
* is an array of wordVersions name for which tests should be generated or a boolean indicating: true - generate for all versions, false - for none.
12+
* @param {Array} [options.testData] Test data object (may contain e.g. information about ignored tests). All created tests will be added into testData object.
13+
* @param {Array} [options.customFilters] Array of custom filters (like [ pfwTools.filters.font ]) which will be used during assertions.
14+
* @param {Boolean} [options.compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than
15+
* what will appear in the editor after all transformations and filtering.
16+
* @param {Boolean} [options.ignoreAll=false] Whenever to ignore all tests.
17+
* @returns {Object} Test data object which should be passed to `bender.test` function.
18+
*/
19+
function createTestSuite( options ) {
20+
options = CKEDITOR.tools.extend( options, {
21+
browsers: [],
22+
wordVersions: [],
23+
tests: [],
24+
testData: { _should: { ignore: {} } },
25+
ignoreAll: false,
26+
compareRawData: false,
27+
customFilters: null
28+
} );
29+
30+
var testData = options.testData,
31+
testsKeys = CKEDITOR.tools.objectKeys( options.tests ),
32+
wordVersion, testKey, testName, i, j, k;
33+
34+
if ( testsKeys.length ) {
35+
for ( i = 0; i < testsKeys.length; i++ ) {
36+
for ( j = 0; j < options.browsers.length; j++ ) {
37+
for ( k = 0; k < options.wordVersions.length; k++ ) {
38+
39+
wordVersion = options.wordVersions[ k ];
40+
testKey = testsKeys[ i ];
41+
42+
if ( options.tests[ testKey ] === true || CKEDITOR.tools.indexOf( options.tests[ testKey ], wordVersion ) !== -1 ) {
43+
44+
testName = [ 'test', testKey, wordVersion, options.browsers[ j ] ].join( ' ' );
45+
46+
if ( options.ignoreAll ) {
47+
testData._should.ignore[ testName ] = true;
48+
}
49+
50+
testData[ testName ] = createTestCase( {
51+
name: testKey,
52+
wordVersion: wordVersion,
53+
browser: options.browsers[ j ],
54+
compareRawData: options.compareRawData,
55+
customFilters: options.customFilters
56+
} );
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
return testData;
64+
}

tests/plugins/pastefromword/generated/config.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
44
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
55
/* jshint ignore:end */
6-
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
7-
/* global createTestCase */
6+
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
7+
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
8+
/* global createTestSuite */
89

910
( function() {
1011
'use strict';
@@ -16,32 +17,21 @@
1617
}
1718
};
1819

19-
var browsers = [
20+
bender.test( createTestSuite( {
21+
browsers: [
2022
'chrome',
2123
'firefox',
2224
'ie8',
2325
'ie11',
2426
'safari'
2527
],
26-
wordVersions = [
28+
wordVersions: [
2729
'word2007',
2830
'word2013'
2931
],
30-
tests = {
32+
tests: {
3133
'Config_remove_font_styles': true
3234
},
33-
keys = CKEDITOR.tools.objectKeys( tests ),
34-
testData = {};
35-
36-
for ( var i = 0; i < keys.length; i++ ) {
37-
for ( var j = 0; j < wordVersions.length; j++ ) {
38-
for ( var k = 0; k < browsers.length; k++ ) {
39-
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
40-
testData[ [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' ) ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, true );
41-
}
42-
}
43-
}
44-
}
45-
46-
bender.test( testData );
35+
compareRawData: true
36+
} ) );
4737
} )();

tests/plugins/pastefromword/generated/generic.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
44
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
55
/* jshint ignore:end */
6-
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
7-
/* global createTestCase,pfwTools */
6+
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
7+
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
8+
/* global pfwTools,createTestSuite */
89

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

16-
var browsers = [
17+
bender.test( createTestSuite( {
18+
browsers: [
1719
'chrome',
1820
'firefox',
1921
'ie8',
2022
'ie11',
2123
'safari'
2224
],
23-
wordVersions = [
25+
wordVersions: [
2426
'word2007',
2527
'word2013'
2628
],
27-
tests = {
29+
tests: {
2830
'Bold': true,
2931
'Colors': true,
3032
'Custom_list_markers': true,
@@ -45,28 +47,9 @@
4547
'Table_alignment': true,
4648
'Table_vertical_alignment': true
4749
},
48-
keys = CKEDITOR.tools.objectKeys( tests ),
49-
testData = {
50-
_should: {
51-
ignore: {}
52-
}
53-
};
54-
55-
for ( var i = 0; i < keys.length; i++ ) {
56-
for ( var j = 0; j < wordVersions.length; j++ ) {
57-
for ( var k = 0; k < browsers.length; k++ ) {
58-
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
59-
var testName = [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' );
60-
61-
if ( CKEDITOR.env.ie && CKEDITOR.env.version <= 11 ) {
62-
testData._should.ignore[ testName ] = true;
63-
}
64-
65-
testData[ testName ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, false, [ pfwTools.filters.span ] );
66-
}
67-
}
68-
}
69-
}
70-
71-
bender.test( testData );
50+
customFilters: [
51+
pfwTools.filters.span
52+
],
53+
ignoreAll: CKEDITOR.env.ie && CKEDITOR.env.version <= 11
54+
} ) );
7255
} )();

tests/plugins/pastefromword/generated/generic_strict.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
44
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
55
/* jshint ignore:end */
6-
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
7-
/* global pfwTools,createTestCase */
6+
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
7+
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
8+
/* global pfwTools,createTestSuite */
89

910
( function() {
1011
'use strict';
@@ -15,39 +16,26 @@
1516
}
1617
};
1718

18-
var browsers = [
19+
bender.test( createTestSuite( {
20+
browsers: [
1921
'chrome',
2022
'firefox',
2123
'ie8',
2224
'ie11',
2325
'edge',
2426
'safari'
2527
],
26-
wordVersions = [
28+
wordVersions: [
2729
'word2007',
2830
'word2013'
2931
],
30-
// To test only particular word versions set the key value to an array in the form: [ 'word2007', 'word2013' ].
31-
tests = {
32+
tests: {
3233
'Unordered_list_multiple': true,
3334
'White_space': true
3435
},
35-
keys = CKEDITOR.tools.objectKeys( tests ),
36-
testData = {
37-
_should: {
38-
ignore: {}
39-
}
40-
};
41-
42-
for ( var i = 0; i < keys.length; i++ ) {
43-
for ( var j = 0; j < wordVersions.length; j++ ) {
44-
for ( var k = 0; k < browsers.length; k++ ) {
45-
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
46-
testData[ [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' ) ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, true, [ pfwTools.filters.font ] );
47-
}
48-
}
49-
}
50-
}
51-
52-
bender.test( testData );
36+
customFilters: [
37+
pfwTools.filters.font
38+
],
39+
compareRawData: true
40+
} ) );
5341
} )();

tests/plugins/pastefromword/generated/inline_styles.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
44
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
55
/* jshint ignore:end */
6-
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_lib/q.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js,_helpers/pfwTools.js */
7-
/* global createTestCase,pfwTools */
6+
/* bender-include: _lib/q.js,_helpers/promisePasteEvent.js,_helpers/assertWordFilter.js,_helpers/createTestCase.js */
7+
/* bender-include: _helpers/createTestSuite.js,_helpers/pfwTools.js */
8+
/* global pfwTools,createTestSuite */
89

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

16-
var browsers = [
17+
bender.test( createTestSuite( {
18+
browsers: [
1719
'chrome',
1820
'firefox',
1921
'safari'
2022
],
21-
wordVersions = [
23+
wordVersions: [
2224
'word2007',
2325
'word2013'
2426
],
25-
tests = {
27+
tests: {
2628
'InlineStyles': true
2729
},
28-
keys = CKEDITOR.tools.objectKeys( tests ),
29-
testData = {
30-
_should: {
31-
ignore: {
32-
'InlineStyles': true
33-
}
34-
}
35-
};
36-
37-
for ( var i = 0; i < keys.length; i++ ) {
38-
for ( var j = 0; j < wordVersions.length; j++ ) {
39-
for ( var k = 0; k < browsers.length; k++ ) {
40-
if ( tests[ keys[ i ] ] === true || CKEDITOR.tools.indexOf( tests[ keys[ i ] ], wordVersions[ j ] ) !== -1 ) {
41-
var testName = [ 'test', keys[ i ], wordVersions[ j ], browsers[ k ] ].join( ' ' );
42-
43-
if ( CKEDITOR.env.ie ) {
44-
testData._should.ignore[ testName ] = true;
45-
}
46-
47-
testData[ testName ] = createTestCase( keys[ i ], wordVersions[ j ], browsers[ k ], false, false, [ pfwTools.filters.style ] );
48-
}
49-
}
50-
}
51-
}
52-
53-
bender.test( testData );
30+
customFilters: [
31+
pfwTools.filters.style
32+
],
33+
ignoreAll: CKEDITOR.env.ie
34+
} ) );
5435
} )();

0 commit comments

Comments
 (0)