Skip to content
Permalink
Browse files

Merge branch 't/12101'

  • Loading branch information...
Reinmar committed Jun 12, 2014
2 parents d888ea2 + 2c17a73 commit dbbf367cb2a3c0cf4b44f0f7cd444c8b07505f25
Showing with 164 additions and 0 deletions.
  1. +71 −0 tests/utils/assert/isinnerhtmlmatching.js
  2. +93 −0 tests/utils/html/compareinnerhtml.js
@@ -0,0 +1,71 @@
/* bender-tags: editor,unit,utils */

( function() {
'use strict';

var htmlTools = bender.tools.html,
shouldReturn, called, expected, actual, options;

htmlTools.compareInnerHtml = function( argExpected, argActual, argOptions ) {
called = true;
expected = argExpected;
actual = argActual;
options = argOptions;

return shouldReturn;
};

bender.test( {
setUp: function() {
called = expected = actual = options = undefined;
shouldReturn = true;
},

'test passes - no opts': function() {
assert.isInnerHtmlMatching( 'a', 'b' );
assert.isTrue( called, 'compareInnerHtml was called' );
assert.areSame( 'a', expected, 'expected' );
assert.areSame( 'b', actual, 'actual' );
assert.isNull( options, 'options' );
},

'test passes - opts': function() {
var obj = {};

assert.isInnerHtmlMatching( 'a', 'b', obj );
assert.isTrue( called, 'compareInnerHtml was called' );
assert.areSame( 'a', expected, 'expected' );
assert.areSame( 'b', actual, 'actual' );
assert.areSame( obj, options, 'options' );
},

'test passes - message': function() {
assert.isInnerHtmlMatching( 'a', 'b', 'msg' );
assert.isTrue( called, 'compareInnerHtml was called' );
assert.areSame( 'a', expected, 'expected' );
assert.areSame( 'b', actual, 'actual' );
assert.isNull( options, 'options' );
},

'test fails': function() {
shouldReturn = false;

var error,
failed = false;

try {
assert.isInnerHtmlMatching( 'a', 'b', 'msg' );
} catch ( e ) {
error = e;
failed = true;
}

assert.isTrue( failed, 'failed' );
assert.isTrue( called, 'compareInnerHtml was called' );
assert.areSame( 'a', expected, 'expected' );
assert.areSame( 'b', actual, 'actual' );
assert.isNull( options, 'options' );
assert.areSame( 'msg', error.message, 'message' )
}
} );
} )();
@@ -0,0 +1,93 @@
/* bender-tags: editor,unit,utils */

( function() {
'use strict';

var compatHtmlArgs,
originalCompatHtml = bender.tools.compatHtml,
htmlTools = bender.tools.html;

bender.tools.compatHtml = function( html, noInterWS, sortAttributes, fixZWS, fixStyles, fixNbsp ) {
compatHtmlArgs = {
noInterWS: !!noInterWS,
sortAttributes: !!sortAttributes,
fixZWS: !!fixZWS,
fixStyles: !!fixStyles,
fixNbsp: !!fixNbsp
};

return originalCompatHtml.call( bender.tools, html, noInterWS, sortAttributes, fixZWS, fixStyles, fixNbsp );
};

function t( ret, expected, actual, options, expectedCompatHtmlArgs ) {
return function() {
// In case compatHtml was not called at all.
compatHtmlArgs = {};
assert.areSame( ret, htmlTools.compareInnerHtml( expected, actual, options ), 'returned value' );

if ( expectedCompatHtmlArgs ) {
for ( var arg in expectedCompatHtmlArgs ) {
assert.areSame( expectedCompatHtmlArgs[ arg ], compatHtmlArgs[ arg ],
'compatHtml\'s argument: ' + arg );
}
}
};
}

bender.test( {
// Options ------------------------------------------------------------

'opts.noInterWS defaults to false': t( true, '', '', null, { noInterWS: false } ),
'opts.noInterWS defaults to false 2': t( true, '', '', {}, { noInterWS: false } ),
'opts.noInterWS is passed': t( true, '', '', { noInterWS: true }, { noInterWS: true } ),

'opts.fixStyles defaults to false': t( true, '', '', null, { fixStyles: false } ),
'opts.fixStyles is passed': t( true, '', '', { fixStyles: true }, { fixStyles: true } ),

'opts.sortAttributes defaults to true': t( true, '', '', null, { sortAttributes: true } ),
'opts.fixZWS defaults to true': t( true, '', '', null, { fixZWS: true } ),
'opts.fixNbsp defaults to true': t( true, '', '', null, { fixNbsp: true } ),

'multiple opts': t( true, '', '', { fixNbsp: false, fixStyles: true }, { fixZWS: true, fixNbsp: false, fixStyles: true } ),

// Passing ------------------------------------------------------------

'simple string': t( true, 'foo', 'foo' ),
'simple element': t( true, '<b>foo</b>', '<B>foo</B>' ),
'bogus expected, not exists': t( true, 'a@', 'a' ),
'bogus expected, exists': t( true, 'a@', 'a<br />' ),
'multiple boguses': t( true, '<p>a@</p><p>b@</p><p>c@</p>', '<p>a<br /></p><p>b</p><p>c<br /></p>' ),
'regexp conflict [': t( true, 'ba[r', 'ba[r' ),

'markers 1 - no opts.compareSelection': t( true, 'ba[r]', 'ba[r]' ),
'markers 2 - no opts.compareSelection': t( true, 'ba{}r', 'ba{}r' ),
'markers 3 - no opts.compareSelection': t( true, '<ul><li>[</li><li>a</li></ul>', '<ul>[<li>a</li></ul>' ),

'markers 1 - opts.compareSelection': t( true, 'ba[r}', 'ba[r}', { compareSelection: true } ),
'markers 2 - opts.compareSelection': t( true, 'ba{}r', 'ba{}r', { compareSelection: true } ),
'markers 3 - opts.compareSelection': t( true, 'ba[]r', 'ba[]r', { compareSelection: true } ),
'markers 4 - opts.compareSelection': t( true, '<ul>[<li>a</li>]</ul>', '<ul>[<li>a</li>]</ul>', { compareSelection: true } ),

'markers 1 - opts.compare&normalizeSelection': t( true, 'ba[r]', 'ba{r}', { compareSelection: true, normalizeSelection: true } ),
'markers 2 - opts.compare&normalizeSelection': t( true, 'ba^r', 'ba{}r', { compareSelection: true, normalizeSelection: true } ),
'markers 3 - opts.compare&normalizeSelection': t( true, 'ba^r', 'ba[]r', { compareSelection: true, normalizeSelection: true } ),
'markers 4 - opts.compare&normalizeSelection': t( true, '<ul>[<li>a</li>]</ul>', '<ul>[<li>a</li>]</ul>', { compareSelection: true, normalizeSelection: true } ),

// Failing ------------------------------------------------------------

'simple string - fail': t( false, 'foo', 'bar' ),
'simple element - fail': t( false, '<b>foo</b>', '<I>foo</I>' ),
'not expected bogus - fail': t( false, '<p>foo<br /></p>', '<p>foo</p>' ),

// Expected part has to be regexified if special characters are not escaped
// bad things may happen.
'regexp conflict * - fail': t( false, 'ba*r', 'br' ),
'regexp - partial match - start - fail': t( false, 'bar', 'barx' ),
'regexp - partial match - end - fail': t( false, 'bar', 'xbar' ),

'markers 1 - no opts.compareSelection - fail': t( false, 'bar', 'ba[]r' ),
'markers 2 - no opts.compareSelection - fail': t( false, 'ba{}r', 'ba[]r' ),
'markers - opts.compareSelection - fail': t( false, 'ba{}r', 'ba[]r', { compareSelection: true } ),
'markers - opts.compare&normalizeSelection - fail': t( false, 'ba[]r', 'ba[]r', { compareSelection: true, normalizeSelection: true } ),
} );
} )();

0 comments on commit dbbf367

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