mediawiki-extensions-Visual.../modules/ve/test/ce/ve.ce.test.js
Inez Korczyński a9082e6dde Only apply HTML attributes to DOM nodes that are "safe"
* Added whitelist argument to setDomAttributes which allows filtering of attributes being set
* Added prefix argument to ve.dm.Node.getAttributes to allow extracting a subset of attributes by name prefix
* Added a whitelist to ve.ce.Node which was extracted from MediaWiki's Sanitizer class
* Replaced attribute copying code with a call to setDomAttributes using the whitelist argument, passing in attributes from a call to ve.dm.Node.getAttributes using the prefix argument

Also…

* Removed comment in constructor of ve.ce.Node, documentation for properties is usually in the getters/setters, and already was in this case
* Renamed ve.setDOMAttributes to ve.setDomAttributes
* Renamed ve.getDOMAttributes to ve.getDomAttributes
* Renamed ve.getDOMText to ve.getDomText
* Renamed ve.getDOMHash to ve.getDomHash
* Updated all callers of renamed methods

Change-Id: Id556172d5d18ea431044b9d402400e1f0e67a293
2012-11-27 14:34:29 -08:00

32 lines
1 KiB
JavaScript

/**
* VisualEditor content editable tests.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ce' );
/* Tests */
QUnit.test( 'whitespacePattern', 4, function ( assert ) {
assert.equal( 'a b'.match( ve.ce.whitespacePattern ), ' ', 'matches spaces' );
assert.equal( 'a\u00A0b'.match( ve.ce.whitespacePattern ), '\u00A0', 'matches non-breaking spaces' );
assert.equal( 'a\tb'.match( ve.ce.whitespacePattern ), null, 'does not match tab' );
assert.equal( 'ab'.match( ve.ce.whitespacePattern ), null, 'does not match non-whitespace' );
} );
QUnit.test( 'getDomText', 1, function ( assert ) {
assert.equal( ve.ce.getDomText(
$( '<span>a<b><a href="#">b</a></b><span></span><i>c</i>d</span>' )[0] ),
'abcd'
);
} );
QUnit.test( 'getDomHash', 1, function ( assert ) {
assert.equal(
ve.ce.getDomHash( $( '<span>a<b><a href="#">b</a></b><span></span><i>c</i>d</span>' )[0] ),
'<SPAN>#<B><A>#</A></B><SPAN></SPAN><I>#</I>#</SPAN>'
);
} );