if (wysihtml5.browser.supported()) { module("wysihtml5.dom.parse", { sanitize: function(html, rules, context, cleanUp, uneditableClass) { return wysihtml5.dom.parse(html, { "rules": rules, "cleanUp": cleanUp, "context": context, "uneditableClass": uneditableClass }); }, equal: function(actual, expected, message) { return QUnit.assert.htmlEqual(actual, expected, message); } }); test("Simple tests using plain tags only", function() { var rules = { tags: { p: "div", script: undefined, div: {} } }; this.equal( this.sanitize("bar", rules), "bar", "Unknown tag gets renamed to span" ); this.equal( this.sanitize("
foo
", rules), "| I'm a table! |
foobar
foobar
html5 doctype
", { tags: { p: true } }), "html5 doctype
", "Stripped out doctype" ); }); test("Advanced tests using tags and attributes", function() { var rules = { tags: { img: { set_attributes: { alt: "foo", border: "1" }, check_attributes: { src: "url", width: "numbers", height: "numbers", border: "numbers" } }, a: { rename_tag: "i", set_attributes: { title: "" } }, video: undefined, h1: { rename_tag: "h2" }, h2: true, h3: undefined } }; this.equal( this.sanitize( '
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'foo', rules);
var secondResult = this.sanitize(firstResult, rules);
ok(secondResult.indexOf("foo") !== -1);
this.equal(firstResult, secondResult);
firstResult = this.sanitize(' foo
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
''
);
this.equal(
this.sanitize(
'
',
rules
),
''
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'',
rules
),
'
'
);
});
test("Advanced tests for 'br' elements", function() {
var rules = {
classes: {
"wysiwyg-clear-both": 1,
"wysiwyg-clear-left": 1,
"wysiwyg-clear-right": 1
},
tags: {
div: true,
br: {
add_class: {
clear: "clear_br"
}
}
}
};
this.equal(
this.sanitize(
'
bar
bar
bar
bar
bar
bar
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
this.equal(
this.sanitize(
'
',
rules
),
'
'
);
});
test("Advanced tests for 'font' elements", function() {
var rules = {
classes: {
"wysiwyg-font-size-xx-small": 1,
"wysiwyg-font-size-small": 1,
"wysiwyg-font-size-medium": 1,
"wysiwyg-font-size-large": 1,
"wysiwyg-font-size-x-large": 1,
"wysiwyg-font-size-xx-large": 1,
"wysiwyg-font-size-smaller": 1,
"wysiwyg-font-size-larger": 1
},
tags: {
font: {
add_class: { size: "size_font" },
rename_tag: "span"
}
}
};
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
this.equal(
this.sanitize(
'foo',
rules
),
'foo'
);
});
test("Check whether namespaces are handled correctly", function() {
var rules = {
tags: {
p: true
}
};
this.equal(
this.sanitize("
",
output_list = "This is a list",
input_table = "
",
output_table = "This is a table";
this.equal(this.sanitize(input_list, rules), output_list, "List unwrapping working ok");
this.equal(this.sanitize(input_table, rules), output_table, "Table unwrapping working ok");
});
test("Test valid type check by attributes", function() {
var rules = {
"type_definitions": {
"valid_image_src": {
"attrs": {
"src": /^[^data\:]/i
}
}
},
"tags": {
"img": {
"one_of_type": {
"valid_image_src": 1
},
"check_attributes": {
"src": "src",
"height": "numbers",
"width": "numbers",
"alt": "alt"
}
}
}
},
input = 'This is a table ',
input_valid = '
',
input_valid_2 = '
';
this.equal(this.sanitize(input, rules), "", "Image with data src gets removed");
this.equal(this.sanitize(input_valid, rules), input_valid, "Valid image is kept");
this.equal(this.sanitize(input_valid_2, rules), input_valid_2, "Valid image is kept2");
});
test("Test valid type definition visible_content_object ", function() {
var rules = {
"type_definitions": {
"visible_content_object": {
"methods": {
"has_visible_contet": 1
}
},
},
"tags": {
'div': {
"one_of_type": {
"visible_content_object": 1
},
"remove_action": "unwrap",
"check_attributes": {
"style": "any"
}
},
'img': {
"check_attributes": {
"src": "any"
}
},
'span': {}
}
},
input1 = '',
input2 = '