<commit_before><!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();<commit_msg>Fixed broken unit test since the behavior has changed.<commit_after><!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: {},
		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: {},
		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();
{'fraction_non_alphanumeric': 0.2680043198999602, 'fraction_numerical': 0.004774626271812653, 'mean_word_length': 6.9109712230215825, 'pattern_counts': {'":': 234, '<': 37, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206259', 'n_tokens_mistral': 5893, 'n_tokens_neox': 5704, 'n_words': 1035}