2014-02-10 02:11:25 +01:00
|
|
|
module("tinymce.html.Writer");
|
|
|
|
|
|
|
|
test('Comment', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(2);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.comment('text');
|
|
|
|
equal(writer.getContent(), '<!--text-->');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.comment('');
|
|
|
|
equal(writer.getContent(), '<!---->');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('CDATA', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(2);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.cdata('text');
|
|
|
|
equal(writer.getContent(), '<![CDATA[text]]>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.cdata('');
|
|
|
|
equal(writer.getContent(), '<![CDATA[]]>');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('PI', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.pi('xml', 'someval');
|
|
|
|
equal(writer.getContent(), '<?xml someval?>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.pi('xml');
|
|
|
|
equal(writer.getContent(), '<?xml?>');
|
2015-07-01 02:51:22 +02:00
|
|
|
|
|
|
|
writer = new tinymce.html.Writer();
|
|
|
|
writer.pi('xml', 'encoding="UTF-8" < >');
|
|
|
|
equal(writer.getContent(), '<?xml encoding="UTF-8" < >?>');
|
2014-02-10 02:11:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Doctype', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(2);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.doctype(' text');
|
|
|
|
equal(writer.getContent(), '<!DOCTYPE text>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.doctype('');
|
|
|
|
equal(writer.getContent(), '<!DOCTYPE>');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Text', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(2);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.text('te<xt');
|
|
|
|
equal(writer.getContent(), 'te<xt');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.text('');
|
|
|
|
equal(writer.getContent(), '');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Text raw', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(2);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.text('te<xt', true);
|
|
|
|
equal(writer.getContent(), 'te<xt');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.text('', true);
|
|
|
|
equal(writer.getContent(), '');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Start', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(5);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('b');
|
|
|
|
equal(writer.getContent(), '<b>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('b', [{name: 'attr1', value: 'value1'}, {name: 'attr2', value: 'value2'}]);
|
|
|
|
equal(writer.getContent(), '<b attr1="value1" attr2="value2">');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('b', [{name: 'attr1', value: 'val<"ue1'}]);
|
|
|
|
equal(writer.getContent(), '<b attr1="val<"ue1">');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('img', [{name: 'attr1', value: 'value1'}, {name: 'attr2', value: 'value2'}], true);
|
|
|
|
equal(writer.getContent(), '<img attr1="value1" attr2="value2" />');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('br', null, true);
|
|
|
|
equal(writer.getContent(), '<br />');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('End', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(1);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.end('b');
|
|
|
|
equal(writer.getContent(), '</b>');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Indentation', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(2);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer({indent: true, indent_before: 'p', indent_after:'p'});
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('p');
|
|
|
|
writer.start('span');
|
|
|
|
writer.text('a');
|
|
|
|
writer.end('span');
|
|
|
|
writer.end('p');
|
|
|
|
writer.start('p');
|
|
|
|
writer.text('a');
|
|
|
|
writer.end('p');
|
|
|
|
equal(writer.getContent(), '<p><span>a</span></p>\n<p>a</p>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer({indent: true, indent_before: 'p', indent_after:'p'});
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('p');
|
|
|
|
writer.text('a');
|
|
|
|
writer.end('p');
|
|
|
|
equal(writer.getContent(), '<p>a</p>');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Entities', function() {
|
2014-03-24 06:59:45 +01:00
|
|
|
var writer;
|
|
|
|
|
2014-02-10 02:11:25 +01:00
|
|
|
expect(3);
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer();
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('p', [{name: "title", value: '<>"\'&\u00e5\u00e4\u00f6'}]);
|
|
|
|
writer.text('<>"\'&\u00e5\u00e4\u00f6');
|
|
|
|
writer.end('p');
|
|
|
|
equal(writer.getContent(), '<p title="<>"\'&\u00e5\u00e4\u00f6"><>"\'&\u00e5\u00e4\u00f6</p>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer({entity_encoding: 'numeric'});
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('p', [{name: "title", value: '<>"\'&\u00e5\u00e4\u00f6'}]);
|
|
|
|
writer.text('<>"\'&\u00e5\u00e4\u00f6');
|
|
|
|
writer.end('p');
|
|
|
|
equal(writer.getContent(), '<p title="<>"\'&åäö"><>"\'&åäö</p>');
|
|
|
|
|
2014-03-24 06:59:45 +01:00
|
|
|
writer = new tinymce.html.Writer({entity_encoding: 'named'});
|
2014-02-10 02:11:25 +01:00
|
|
|
writer.start('p', [{name: "title", value: '<>"\'&\u00e5\u00e4\u00f6'}]);
|
|
|
|
writer.text('<>"\'&\u00e5\u00e4\u00f6');
|
|
|
|
writer.end('p');
|
|
|
|
equal(writer.getContent(), '<p title="<>"\'&åäö"><>"\'&åäö</p>');
|
|
|
|
});
|