', 'Output name and attribute rules');
ser.setRules('a[href|target<_blank?_top|title:forced value]');
DOM.setHTML('test', 'linktest2');
equal(ser.serialize(DOM.get('test')), 'linktest2');
ser.setRules('img[src|border=0|alt=]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '', 'Default attribute with empty value');
ser.setRules('img[src|border=0|alt=],*[*]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '
');
ser = new tinymce.dom.Serializer({
valid_elements : 'img[src|border=0|alt=]',
extended_valid_elements : 'div[id],img[src|alt=]'
});
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
ser = new tinymce.dom.Serializer({invalid_elements : 'hr,br'});
DOM.setHTML('test', ' ');
equal(ser.serialize(DOM.get('test')), '');
});
test('Entity encoding', function() {
var ser;
expect(4);
ser = new tinymce.dom.Serializer({entity_encoding : 'numeric'});
DOM.setHTML('test', '<>&" åäö');
equal(ser.serialize(DOM.get('test')), '
<>&" åäö
');
ser = new tinymce.dom.Serializer({entity_encoding : 'named'});
DOM.setHTML('test', '<>&" åäö');
equal(ser.serialize(DOM.get('test')), '
<>&" åäö
');
ser = new tinymce.dom.Serializer({entity_encoding : 'named+numeric', entities : '160,nbsp,34,quot,38,amp,60,lt,62,gt'});
DOM.setHTML('test', '<>&" åäö');
equal(ser.serialize(DOM.get('test')), '
<>&" åäö
');
ser = new tinymce.dom.Serializer({entity_encoding : 'raw'});
DOM.setHTML('test', '<>&" åäö');
equal(ser.serialize(DOM.get('test')), '
<>&"\u00a0\u00e5\u00e4\u00f6
');
});
test('Form elements (general)', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(5);
ser.setRules('form[method],label[for],input[type|name|value|checked|disabled|readonly|length|maxlength],select[multiple],option[value|selected],textarea[name|disabled|readonly]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
// Edge will add an empty input value so remove that to normalize test since it doesn't break anything
equal(ser.serialize(DOM.get('test')).replace(/ value=""/g, ''), '');
});
test('Form elements (checkbox)', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(4);
ser.setRules('form[method],label[for],input[type|name|value|checked|disabled|readonly|length|maxlength],select[multiple],option[value|selected]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
});
test('Form elements (select)', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(7);
ser.setRules('form[method],label[for],input[type|name|value|checked|disabled|readonly|length|maxlength],select[multiple],option[value|selected]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
});
test('List elements', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(5);
ser.setRules('ul[compact],ol,li');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
a
b
c
e
');
equal(ser.serialize(DOM.get('test')), '
a
b
c
e
');
});
test('Tables', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(4);
ser.setRules('table,tr,td[nowrap]');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
DOM.setHTML('test', '
');
equal(ser.serialize(DOM.get('test')), '
');
});
test('Styles', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(1);
ser.setRules('*[*]');
DOM.setHTML('test', 'test');
equal(ser.serialize(DOM.get('test')), '
test
');
});
test('Comments', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(1);
ser.setRules('*[*]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')), '');
});
test('Non HTML elements and attributes', function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
expect(2);
ser.setRules('*[*]');
ser.schema.addValidChildren('+div[prefix:test]');
DOM.setHTML('test', '
');
});
test('Script with non JS type attribute', 1, function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
ser.setRules('script[type|language|src]');
DOM.setHTML('test', '');
equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '');
});
test('Script with tags inside a comment', 1, function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
ser.setRules('script[type|language|src]');
DOM.setHTML('test', '// ');
equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '// \n// ]]>');
});
test('Script with less than', 1, function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
ser.setRules('script[type|language|src]');
DOM.setHTML('test', '1 < 2;');
equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '// ');
});
test('Script with type attrib and less than', 1, function() {
var ser = new tinymce.dom.Serializer({fix_list_elements : true});
ser.setRules('script[type|language|src]');
DOM.setHTML('test', '1 < 2;');
equal(ser.serialize(DOM.get('test')).replace(/\r/g, ''), '