module("tinymce.html.Schema"); 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() { var schema; expect(17); schema = new tinymce.html.Schema({valid_elements: '*[id|class]'}); deepEqual(schema.getElementRule('b').attributes, {"id": {}, "class": {} }); deepEqual(schema.getElementRule('b').attributesOrder, ["id", "class"]); 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); 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); 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() { var schema; expect(13); 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')); 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')); 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() { var schema; expect(3); 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() { var schema; expect(1); 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() { var schema; expect(1); 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() { var schema; expect(1); 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() { var schema; expect(1); 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() { var schema; expect(1); schema = new tinymce.html.Schema({valid_elements: 'span[dir