/*! * VisualEditor Base method tests. * * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ QUnit.module( 've' ); /* Tests */ // ve.cloneObject: Tested upstream (OOJS) // ve.getObjectValues: Tested upstream (OOJS) // ve.getObjectKeys: Tested upstream (JavaScript) // ve.compare: Tested upstream (OOJS) // ve.copy: Tested upstream (OOJS) // ve.isPlainObject: Tested upstream (jQuery) // ve.isEmptyObject: Tested upstream (jQuery) // ve.isArray: Tested upstream (jQuery) // ve.bind: Tested upstream (jQuery) // ve.indexOf: Tested upstream (jQuery) // ve.extendObject: Tested upstream (jQuery) QUnit.test( 'getDomAttributes', 1, function ( assert ) { assert.deepEqual( ve.getDomAttributes( $( '
' ).get( 0 ) ), { 'foo': 'bar', 'baz': '', 'quux': '3' }, 'getDomAttributes() returns object with correct attributes' ); } ); QUnit.test( 'setDomAttributes', 3, function ( assert ) { var element = document.createElement( 'div' ); ve.setDomAttributes( element, { 'foo': 'bar', 'baz': '', 'quux': 3 } ); assert.deepEqual( ve.getDomAttributes( element ), { 'foo': 'bar', 'baz': '', 'quux': '3' }, 'setDomAttributes() sets attributes correctly' ); ve.setDomAttributes( element, { 'foo': null, 'bar': 1, 'baz': undefined, 'quux': 5, 'whee': 'yay' } ); assert.deepEqual( ve.getDomAttributes( element ), { 'bar': '1', 'quux': '5', 'whee': 'yay' }, 'setDomAttributes() overwrites attributes, removes attributes, and sets new attributes' ); ve.setDomAttributes( element, { 'onclick': 'alert(1);' }, ['foo', 'bar', 'baz', 'quux', 'whee'] ); assert.ok( !element.hasAttribute( 'onclick' ), 'event attributes are blocked when sanitizing' ); } ); QUnit.test( 'getOpeningHtmlTag', 5, function ( assert ) { assert.deepEqual( ve.getOpeningHtmlTag( 'code', {} ), '', 'opening tag without attributes' ); assert.deepEqual( ve.getOpeningHtmlTag( 'img', { 'src': 'foo' } ), '', 'opening tag with one attribute' ); assert.deepEqual( ve.getOpeningHtmlTag( 'a', { 'href': 'foo', 'rel': 'bar' } ), '', 'tag with two attributes' ); assert.deepEqual( ve.getOpeningHtmlTag( 'option', { 'selected': true, 'blah': false, 'value': 3 } ), '