375 lines
15 KiB
HTML
375 lines
15 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>tinymce.html.Schema tests</title>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
|
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
|
||
|
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
|
||
|
<script src="../../js/qunit/reporter.js"></script>
|
||
|
<script src="../../js/utils.js"></script>
|
||
|
<script src="../../js/tinymce_loader.js"></script>
|
||
|
<script>
|
||
|
module("tinymce.html.Schema");
|
||
|
|
||
|
QUnit.config.reorder = false;
|
||
|
|
||
|
test('Valid elements global rule', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: '@[id|style],img[src|-style]'});
|
||
|
deepEqual(schema.getElementRule('img'), {"attributes": {"id": {}, "src": {}}, "attributesOrder": ["id", "src"]});
|
||
|
});
|
||
|
|
||
|
test('Whildcard element rule', function() {
|
||
|
expect(17);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: '*[id|class]'});
|
||
|
deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'b*[id|class]'});
|
||
|
deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]);
|
||
|
deepEqual(schema.getElementRule('body').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('body').attributesOrder, ["id", "class"]);
|
||
|
equal(schema.getElementRule('img'), undefined);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'b?[id|class]'});
|
||
|
deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]);
|
||
|
deepEqual(schema.getElementRule('bx').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('bx').attributesOrder, ["id", "class"]);
|
||
|
equal(schema.getElementRule('body'), undefined);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'b+[id|class]'});
|
||
|
deepEqual(schema.getElementRule('body').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('body').attributesOrder, ["id", "class"]);
|
||
|
deepEqual(schema.getElementRule('bx').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('bx').attributesOrder, ["id", "class"]);
|
||
|
equal(schema.getElementRule('b'), undefined);
|
||
|
});
|
||
|
|
||
|
test('Whildcard attribute rule', function() {
|
||
|
expect(13);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'b[id|class|*]'});
|
||
|
deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]);
|
||
|
ok(schema.getElementRule('b').attributePatterns[0].pattern.test('x'));
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'b[id|class|x?]'});
|
||
|
deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]);
|
||
|
ok(schema.getElementRule('b').attributePatterns[0].pattern.test('xy'));
|
||
|
ok(!schema.getElementRule('b').attributePatterns[0].pattern.test('xba'));
|
||
|
ok(!schema.getElementRule('b').attributePatterns[0].pattern.test('a'));
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'b[id|class|x+]'});
|
||
|
deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} });
|
||
|
deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]);
|
||
|
ok(!schema.getElementRule('b').attributePatterns[0].pattern.test('x'));
|
||
|
ok(schema.getElementRule('b').attributePatterns[0].pattern.test('xb'));
|
||
|
ok(schema.getElementRule('b').attributePatterns[0].pattern.test('xba'));
|
||
|
});
|
||
|
|
||
|
test('Valid attributes and attribute order', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'div,a[href|title],b[title]'});
|
||
|
deepEqual(schema.getElementRule('div'), {"attributes": {}, "attributesOrder": []});
|
||
|
deepEqual(schema.getElementRule('a'), {"attributes": {"href": {}, "title": {}}, "attributesOrder": ["href", "title"]});
|
||
|
deepEqual(schema.getElementRule('b'), {"attributes": {"title": {}}, "attributesOrder": ["title"]});
|
||
|
});
|
||
|
|
||
|
test('Required any attributes', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'a![id|style|href]'});
|
||
|
deepEqual(schema.getElementRule('a'), {"attributes": {"href": {}, "id": {}, "style": {}}, "attributesOrder": ["id", "style", "href"], "removeEmptyAttrs": true});
|
||
|
});
|
||
|
|
||
|
test('Required attributes', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'a[!href|!name]'});
|
||
|
deepEqual(schema.getElementRule('a'), {"attributes": {"href": {"required": true}, "name": {"required": true}}, "attributesOrder": ["href", "name"], "attributesRequired": ["href", "name"]});
|
||
|
});
|
||
|
|
||
|
test('Default attribute values', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'img[border=0]'});
|
||
|
deepEqual(schema.getElementRule('img'), {"attributes": {"border": {"defaultValue": "0"}}, "attributesOrder": ["border"], "attributesDefault": [{"name": "border", "value": "0"}]});
|
||
|
});
|
||
|
|
||
|
test('Forced attribute values', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'img[border:0]'});
|
||
|
deepEqual(schema.getElementRule('img'), {"attributes": {"border": {"forcedValue": "0"}}, "attributesOrder": ["border"], "attributesForced": [{"name": "border", "value": "0"}]});
|
||
|
});
|
||
|
|
||
|
test('Required attribute values', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'span[dir<ltr?rtl]'});
|
||
|
deepEqual(schema.getElementRule('span'), {"attributes": {"dir": {"validValues": {"rtl": {}, "ltr": {}}}}, "attributesOrder": ["dir"]});
|
||
|
});
|
||
|
|
||
|
test('Remove empty elements', function() {
|
||
|
expect(2);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: '-span'});
|
||
|
deepEqual(schema.getElementRule('span'), {"attributes": {}, "attributesOrder": [], "removeEmpty": true});
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: '#span'});
|
||
|
deepEqual(schema.getElementRule('span'), {"attributes": {}, "attributesOrder": [], "paddEmpty": true});
|
||
|
});
|
||
|
|
||
|
test('addValidElements', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: '@[id|style],img[src|-style]'});
|
||
|
schema.addValidElements('b[class]');
|
||
|
deepEqual(schema.getElementRule('b'), {"attributes": {"id": {}, "style": {}, "class": {}}, "attributesOrder": ["id", "style", "class"]});
|
||
|
});
|
||
|
|
||
|
test('setValidElements', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: '@[id|style],img[src|-style]'});
|
||
|
schema.setValidElements('b[class]');
|
||
|
equal(schema.getElementRule('img'), undefined);
|
||
|
deepEqual(schema.getElementRule('b'), {"attributes": {"class": {}}, "attributesOrder": ["class"]});
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements: 'img[src]'});
|
||
|
schema.setValidElements('@[id|style],img[src]');
|
||
|
deepEqual(schema.getElementRule('img'), {"attributes": {"id": {}, "style": {}, "src": {}}, "attributesOrder": ["id", "style", "src"]});
|
||
|
});
|
||
|
|
||
|
test('getBoolAttrs', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
deepEqual(schema.getBoolAttrs(), {
|
||
|
"CONTROLS": {}, "LOOP": {}, "AUTOPLAY": {}, "SELECTED": {}, "READONLY": {}, "NOWRAP": {},
|
||
|
"NOSHADE": {}, "NORESIZE": {}, "NOHREF": {}, "MULTIPLE": {}, "ISMAP": {}, "DISABLED": {}, "DEFER": {},
|
||
|
"DECLARE": {}, "COMPACT": {}, "CHECKED": {},
|
||
|
"controls": {}, "loop": {}, "autoplay": {}, "selected": {}, "readonly": {}, "nowrap": {},
|
||
|
"noshade": {}, "noresize": {}, "nohref": {}, "multiple": {}, "ismap": {}, "disabled": {}, "defer": {},
|
||
|
"declare": {}, "compact": {}, "checked": {}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('getBlockElements', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
deepEqual(schema.getBlockElements(), {
|
||
|
ASIDE: {}, HGROUP: {}, SECTION: {}, ARTICLE: {}, FOOTER: {}, HEADER: {}, SAMP: {},
|
||
|
ISINDEX: {}, MENU: {}, NOSCRIPT: {}, FIELDSET: {}, DIR: {}, DD: {}, DT: {},
|
||
|
DL: {}, CENTER: {}, BLOCKQUOTE: {}, CAPTION: {}, UL: {}, OL: {}, LI: {},
|
||
|
TD: {}, TR: {}, TH: {}, TFOOT: {}, THEAD: {}, TBODY: {}, TABLE: {}, FORM: {},
|
||
|
PRE: {}, ADDRESS: {}, DIV: {}, P: {}, HR: {}, H6: {}, H5: {}, H4: {}, H3: {},
|
||
|
H2: {}, H1: {}, NAV: {}, FIGURE: {}, DATALIST: {}, OPTGROUP: {}, OPTION: {}, SELECT: {},
|
||
|
aside: {}, hgroup: {}, section: {}, article: {}, footer: {}, header: {}, samp: {},
|
||
|
isindex: {}, menu: {}, noscript: {}, fieldset: {}, dir: {}, dd: {}, dt: {}, dl: {}, center: {},
|
||
|
blockquote: {}, caption: {}, ul: {}, ol: {}, li: {}, td: {}, tr: {}, th: {}, tfoot: {}, thead: {},
|
||
|
tbody: {}, table: {}, form: {}, pre: {}, address: {}, div: {}, p: {}, hr: {}, h6: {},
|
||
|
h5: {}, h4: {}, h3: {}, h2: {}, h1: {}, nav: {}, figure: {}, datalist: {}, optgroup: {},
|
||
|
option: {}, select: {}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('getShortEndedElements', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
deepEqual(schema.getShortEndedElements(), {
|
||
|
"EMBED": {}, "PARAM": {}, "META": {}, "LINK": {}, "ISINDEX": {},
|
||
|
"INPUT": {}, "IMG": {}, "HR": {}, "FRAME": {}, "COL": {}, "BR": {},
|
||
|
"BASEFONT": {}, "BASE": {}, "AREA": {}, "SOURCE" : {}, "WBR" : {}, "TRACK" : {},
|
||
|
"embed": {}, "param": {}, "meta": {}, "link": {}, "isindex": {},
|
||
|
"input": {}, "img": {}, "hr": {}, "frame": {}, "col": {}, "br": {},
|
||
|
"basefont": {}, "base": {}, "area": {}, "source" : {}, "wbr" : {}, "track" : {}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('getNonEmptyElements', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
deepEqual(schema.getNonEmptyElements(), {
|
||
|
"EMBED": {}, "PARAM": {}, "META": {}, "LINK": {}, "ISINDEX": {},
|
||
|
"INPUT": {}, "IMG": {}, "HR": {}, "FRAME": {}, "COL": {}, "BR": {},
|
||
|
"BASEFONT": {}, "BASE": {}, "AREA": {}, "SOURCE" : {},
|
||
|
"TD": {}, "TH": {}, "IFRAME": {}, "VIDEO": {}, "AUDIO": {}, "OBJECT": {}, "WBR": {}, "TRACK" : {}, "SCRIPT" : {},
|
||
|
"embed": {}, "param": {}, "meta": {}, "link": {}, "isindex": {},
|
||
|
"input": {}, "img": {}, "hr": {}, "frame": {}, "col": {}, "br": {},
|
||
|
"basefont": {}, "base": {}, "area": {}, "source" : {},
|
||
|
"td": {}, "th": {}, "iframe": {}, "video": {}, "audio": {}, "object": {}, "wbr" : {}, "track" : {}, "script" : {},
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('getWhiteSpaceElements', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
deepEqual(schema.getWhiteSpaceElements(), {
|
||
|
"IFRAME": {}, "NOSCRIPT": {}, "OBJECT": {}, "PRE": {},
|
||
|
"SCRIPT": {}, "STYLE": {}, "TEXTAREA": {}, "VIDEO": {}, "AUDIO": {},
|
||
|
"iframe": {}, "noscript": {}, "object": {}, "pre": {},
|
||
|
"script": {}, "style": {}, "textarea": {}, "video": {}, "audio": {}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('getTextBlockElements', function() {
|
||
|
expect(1);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
deepEqual(schema.getTextBlockElements(), {
|
||
|
"ADDRESS": {}, "ARTICLE": {}, "ASIDE": {}, "BLOCKQUOTE": {}, "CENTER": {}, "DIR": {}, "DIV": {}, "FIELDSET": {}, "FIGURE": {}, "FOOTER": {}, "FORM": {},
|
||
|
"H1": {}, "H2": {}, "H3": {}, "H4": {}, "H5": {}, "H6": {}, "HEADER": {}, "HGROUP": {}, "NAV": {}, "P": {}, "PRE": {}, "SECTION": {},
|
||
|
"address": {}, "article": {}, "aside": {}, "blockquote": {}, "center": {}, "dir": {}, "div": {}, "fieldset": {}, "figure": {}, "footer": {}, "form": {},
|
||
|
"h1": {}, "h2": {}, "h3": {}, "h4": {}, "h5": {}, "h6": {}, "header": {}, "hgroup": {}, "nav": {}, "p": {}, "pre": {}, "section": {}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('isValidChild', function() {
|
||
|
expect(4);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
ok(schema.isValidChild('body', 'p'));
|
||
|
ok(schema.isValidChild('p', 'img'));
|
||
|
ok(!schema.isValidChild('body', 'body'));
|
||
|
ok(!schema.isValidChild('p', 'body'));
|
||
|
});
|
||
|
|
||
|
test('getElementRule', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
ok(schema.getElementRule('b'));
|
||
|
ok(!schema.getElementRule('bx'));
|
||
|
ok(!schema.getElementRule(null));
|
||
|
});
|
||
|
|
||
|
test('addCustomElements', function() {
|
||
|
expect(5);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({valid_elements:'inline,block'});
|
||
|
schema.addCustomElements('~inline,block');
|
||
|
ok(schema.getElementRule('inline'));
|
||
|
ok(schema.getElementRule('block'));
|
||
|
ok(schema.isValidChild('body', 'block'));
|
||
|
ok(schema.isValidChild('block', 'inline'));
|
||
|
ok(schema.isValidChild('p', 'inline'));
|
||
|
});
|
||
|
|
||
|
test('addValidChildren', function() {
|
||
|
expect(7);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
ok(schema.isValidChild('body', 'p'));
|
||
|
ok(!schema.isValidChild('body', 'body'));
|
||
|
ok(!schema.isValidChild('body', 'html'));
|
||
|
schema.addValidChildren('+body[body|html]');
|
||
|
ok(schema.isValidChild('body', 'body'));
|
||
|
ok(schema.isValidChild('body', 'html'));
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
ok(schema.isValidChild('body', 'p'));
|
||
|
schema.addValidChildren('-body[p]');
|
||
|
ok(!schema.isValidChild('body', 'p'));
|
||
|
});
|
||
|
|
||
|
test('addCustomElements/getCustomElements', function() {
|
||
|
expect(4);
|
||
|
|
||
|
var schema = new tinymce.html.Schema();
|
||
|
schema.addCustomElements('~inline,block');
|
||
|
ok(schema.getBlockElements()['block']);
|
||
|
ok(!schema.getBlockElements()['inline']);
|
||
|
ok(schema.getCustomElements()['inline']);
|
||
|
ok(schema.getCustomElements()['block']);
|
||
|
});
|
||
|
|
||
|
test('whitespaceElements', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({whitespace_elements : 'pre,p'});
|
||
|
ok(schema.getWhiteSpaceElements()['pre']);
|
||
|
ok(!schema.getWhiteSpaceElements()['span']);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({whitespace_elements : 'code'});
|
||
|
ok(schema.getWhiteSpaceElements()['code']);
|
||
|
});
|
||
|
|
||
|
test('selfClosingElements', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({self_closing_elements : 'pre,p'});
|
||
|
ok(schema.getSelfClosingElements()['pre']);
|
||
|
ok(schema.getSelfClosingElements()['p']);
|
||
|
ok(!schema.getSelfClosingElements()['li']);
|
||
|
});
|
||
|
|
||
|
test('shortEndedElements', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({short_ended_elements : 'pre,p'});
|
||
|
ok(schema.getShortEndedElements()['pre']);
|
||
|
ok(schema.getShortEndedElements()['p']);
|
||
|
ok(!schema.getShortEndedElements()['img']);
|
||
|
});
|
||
|
|
||
|
test('booleanAttributes', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({boolean_attributes : 'href,alt'});
|
||
|
ok(schema.getBoolAttrs()['href']);
|
||
|
ok(schema.getBoolAttrs()['alt']);
|
||
|
ok(!schema.getBoolAttrs()['checked']);
|
||
|
});
|
||
|
|
||
|
test('nonEmptyElements', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({non_empty_elements : 'pre,p'});
|
||
|
ok(schema.getNonEmptyElements()['pre']);
|
||
|
ok(schema.getNonEmptyElements()['p']);
|
||
|
ok(!schema.getNonEmptyElements()['img']);
|
||
|
});
|
||
|
|
||
|
test('blockElements', function() {
|
||
|
expect(3);
|
||
|
|
||
|
var schema = new tinymce.html.Schema({block_elements : 'pre,p'});
|
||
|
ok(schema.getBlockElements()['pre']);
|
||
|
ok(schema.getBlockElements()['p']);
|
||
|
ok(!schema.getBlockElements()['h1']);
|
||
|
});
|
||
|
|
||
|
test('isValid', function() {
|
||
|
var schema = new tinymce.html.Schema({valid_elements : 'a[href],i[*]'});
|
||
|
|
||
|
ok(schema.isValid('a'));
|
||
|
ok(schema.isValid('a', 'href'));
|
||
|
ok(!schema.isValid('b'));
|
||
|
ok(!schema.isValid('b', 'href'));
|
||
|
ok(!schema.isValid('a', 'id'));
|
||
|
ok(schema.isValid('i'));
|
||
|
ok(schema.isValid('i', 'id'));
|
||
|
});
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<h1 id="qunit-header">tinymce.html.Schema tests</h1>
|
||
|
<h2 id="qunit-banner"></h2>
|
||
|
<div id="qunit-testrunner-toolbar"></div>
|
||
|
<h2 id="qunit-userAgent"></h2>
|
||
|
<ol id="qunit-tests"></ol>
|
||
|
<div id="content"></div>
|
||
|
</body>
|
||
|
</html>
|