module("tinymce.plugins.Paste", {
setupModule: function() {
QUnit.stop();
tinymce.init({
selector: "textarea",
add_unload_trigger: false,
skin: false,
indent: false,
plugins: wpPlugins,
wp_paste_filters: false,
setup: function(ed) {
ed.on('NodeChange', false);
},
init_instance_callback: function(ed) {
window.editor = ed;
QUnit.start();
}
});
},
teardown: function() {
delete editor.settings.paste_remove_styles_if_webkit;
delete editor.settings.paste_retain_style_properties;
delete editor.settings.paste_enable_default_filters;
delete editor.settings.paste_data_images;
delete editor.settings.paste_webkit_styles;
}
});
test("Paste simple text content", function() {
var rng = editor.dom.createRng();
editor.setContent('
1234
');
editor.focus();
rng.setStart(editor.getBody().firstChild.firstChild, 1);
rng.setEnd(editor.getBody().firstChild.firstChild, 3);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: 'TEST'});
equal(editor.getContent(), '1TEST4
');
});
test("Paste styled text content", function() {
var rng = editor.dom.createRng();
editor.settings.paste_remove_styles_if_webkit = false;
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 1);
rng.setEnd(editor.getBody().firstChild.firstChild, 3);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: 'TEST '});
equal(editor.getContent(), '1TEST 4
'); // Changed in WordPress
});
test("Paste paragraph in paragraph", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 1);
rng.setEnd(editor.getBody().firstChild.firstChild, 3);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: 'TEST
'});
equal(editor.getContent(), '1
TEST
4
');
});
test("Paste paragraphs in complex paragraph", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.dom.select('em,i')[0].firstChild, 1);
rng.setEnd(editor.dom.select('em,i')[0].firstChild, 3);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: 'TEST 1
TEST 2
'});
equal(editor.getContent(), '1
TEST 1
TEST 2
4
');
});
test("Paste Word fake list", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: ' · Item 1
· Item 2
· Item 3
· Item 4
· Item 5
· Item 6
'});
equal(editor.getContent(), 'Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 ');
editor.settings.paste_retain_style_properties = 'border';
rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: '\u25CF Item Spaces.
'});
equal(editor.getContent(), '');
rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: '1. Version 7.0 :
'});
equal(editor.getContent(), 'Version 7.0: ');
});
test("Paste Word fake list before BR", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertContent', false, ' a');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild, 0);
rng.setEnd(editor.getBody().firstChild, 0);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: ' · Item 1
· Item 2
· Item 3
· Item 4
· Item 5
· Item 6
'});
equal(editor.getContent(), 'Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 a
');
});
test("Paste Word fake lists interrupted by header", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: '· List before heading A
· List before heading B
heading · List after heading A
· List after heading B
'});
equal(editor.getContent(), 'List before heading A List before heading B heading List after heading A List after heading B ');
});
test("Paste list like paragraph and list", function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: 'ABC. X
1. Y
'
});
equal(editor.getContent(), 'ABC. X
Y ');
});
test("Paste list like paragraph and list (disabled)", function() {
editor.setContent('');
editor.settings.paste_convert_word_fake_lists = false;
editor.execCommand('mceInsertClipboardContent', false, {
content: 'ABC. X
1. Y
'
});
delete editor.settings.paste_convert_word_fake_lists;
equal(editor.getContent(), 'ABC. X
1. Y
');
});
test("Paste Word table", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: ' Cell 1
Cell 2
Cell 3
Cell 4
'});
equal(editor.getContent(), '
');
});
test("Paste Office 365", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test
'});
equal(editor.getContent(), 'Test
');
});
test("Paste Google Docs", function() {
var rng = editor.dom.createRng();
editor.setContent('1234
');
rng.setStart(editor.getBody().firstChild.firstChild, 0);
rng.setEnd(editor.getBody().firstChild.firstChild, 4);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: '' +
'
' +
'Comic Sans MS ' +
'
' +
' '
)
});
equal(editor.getContent(), (
'Comic Sans MS
'
));
});
test("Paste Word links", function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'' +
'1 ' +
'2 ' +
'3 ' +
'4 ' +
'[5] ' +
'[5] ' +
'[6] ' +
'[7] ' +
'8 ' +
'9 ' +
'named_link ' +
'5 ' +
'
'
)
});
equal(editor.getContent(), (
'' +
'1 ' +
'2 ' +
' 3' +
' 4' +
'[5] ' +
'[5] ' +
'[6] ' +
'[7] ' +
'8 ' +
'9' +
'named_link' +
'5' +
'
'
));
});
test("Paste Word retain styles", function() {
editor.settings.paste_retain_style_properties = 'color,background-color,font-family';
// Test color
editor.setContent('');
editor.execCommand('SelectAll');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test
'});
equal(editor.getContent(), 'Test
');
// Test background-color
editor.setContent('');
editor.execCommand('SelectAll');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test
'});
equal(editor.getContent(), 'Test
');
});
test("Paste Word retain bold/italic styles to elements", function() {
editor.settings.paste_retain_style_properties = 'color';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'' +
'bold ' +
'italic ' +
'bold + italic ' +
'bold + color ' +
'
'
)
});
equal(editor.getContent(), 'bold italic bold + italic bold + color
');
});
test('paste track changes comment', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'1
' +
'2
' +
'3 ' +
'4'
)
});
equal(editor.getContent(), '1
');
});
test('paste nested (UL) word list', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: (
"" +
"" +
"· " +
" a
" +
"" +
"" +
"o b
" +
"" +
"" +
"§ c 1. x
"
)
});
equal(
editor.getContent(),
''
);
});
test('paste nested (OL) word list', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: (
"" +
"" +
"1. " +
" a
" +
"" +
"a." +
" b
" +
"" +
"" +
" " +
" " +
" " +
" i." +
" c
"
)
});
equal(
editor.getContent(),
''+
'a' +
'' +
'b' +
'' +
'c ' +
' ' +
' ' +
' ' +
' ' +
' '
);
});
test("Paste list start index", function() {
editor.settings.paste_merge_formats = true;
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'' +
'10.' +
'J ');
})
test("Paste paste_merge_formats: true", function() {
editor.settings.paste_merge_formats = true;
editor.setContent('a
');
Utils.setSelection('p', 1);
editor.execCommand('mceInsertClipboardContent', false, {content: 'b '});
equal(editor.getContent(), 'ab
');
});
test("Paste paste_merge_formats: false", function() {
editor.settings.paste_merge_formats = false;
editor.setContent('a
');
Utils.setSelection('p', 1);
editor.execCommand('mceInsertClipboardContent', false, {content: 'b '});
equal(editor.getContent(), 'ab
');
});
test("Paste word DIV as P", function() {
editor.setContent('');
editor.execCommand('SelectAll');
editor.execCommand('mceInsertClipboardContent', false, {content: '1
2
'});
equal(editor.getContent(), '1
2
');
});
test("Paste part of list from IE", function() {
editor.setContent('');
editor.execCommand('SelectAll');
editor.execCommand('mceInsertClipboardContent', false, {content: 'item2 item3 '});
equal(Utils.trimContent(editor.getContent()), '', 'List tags are inferred when pasting LI');
});
test("Disable default filters", function() {
editor.settings.paste_enable_default_filters = false;
// Test color
editor.setContent('');
editor.execCommand('SelectAll');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test
'});
equal(editor.getContent(), 'Test
');
});
test('paste invalid content with spans on page', function() {
var startingContent = '123 testing span later in document
',
insertedContent = '';
editor.setContent(startingContent);
var rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 0);
rng.setEnd(editor.dom.select('p')[0].firstChild, 0);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {content: insertedContent});
equal(editor.getContent(), insertedContent + startingContent);
});
test('paste plain text with space', function() {
editor.setContent('text
');
var rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 1);
rng.setEnd(editor.dom.select('p')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {text: ' a '});
equal(editor.getContent(), 't a xt
');
});
test('paste plain text with linefeeds', function() {
editor.setContent('text
');
var rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 1);
rng.setEnd(editor.dom.select('p')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {text: 'a\nb\nc\n'});
equal(editor.getContent(), 'ta b c xt
');
});
test('paste plain text with double linefeeds', function() {
editor.setContent('text
');
var rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 1);
rng.setEnd(editor.dom.select('p')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {text: 'a\n\nb\n\nc'});
equal(editor.getContent(), 't
a
b
c
xt
');
});
test('paste plain text with entities', function() {
editor.setContent('text
');
var rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 1);
rng.setEnd(editor.dom.select('p')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {text: '< & >'});
equal(editor.getContent(), 't< & >xt
');
});
test('paste plain text with paragraphs', function() {
editor.setContent('text
');
var rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 1);
rng.setEnd(editor.dom.select('p')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.execCommand('mceInsertClipboardContent', false, {text: 'a\nb \n\nc'});
equal(editor.getContent(), 't
a <b>b</b>
c
xt
');
});
test('paste data image with paste_data_images: false', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: ' '});
equal(editor.getContent(), '');
editor.execCommand('mceInsertClipboardContent', false, {content: ' '});
equal(editor.getContent(), '');
});
test('paste data image with paste_data_images: true', function() {
editor.settings.paste_data_images = true;
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: ' '});
equal(editor.getContent(), '
');
});
test('paste pre process text (event)', function() {
function callback(e) {
e.content = 'PRE:' + e.content;
}
editor.setContent('a
');
Utils.setSelection('p', 0, 'p', 1);
editor.on('PastePreProcess', callback);
editor.execCommand('mceInsertClipboardContent', false, {text: 'b\n2'});
equal(editor.getContent(), 'PRE:b 2
');
editor.setContent('a
');
Utils.setSelection('p', 0, 'p', 1);
editor.off('PastePreProcess', callback);
editor.execCommand('mceInsertClipboardContent', false, {text: 'c'});
equal(editor.getContent(), 'c
');
});
test('paste pre process html (event)', function() {
function callback(e) {
e.content = 'PRE:' + e.content;
}
editor.setContent('a
');
Utils.setSelection('p', 0, 'p', 1);
editor.on('PastePreProcess', callback);
editor.execCommand('mceInsertClipboardContent', false, {content: 'b '});
equal(editor.getContent(), 'PRE:b
');
editor.setContent('a
');
Utils.setSelection('p', 0, 'p', 1);
editor.off('PastePreProcess', callback);
editor.execCommand('mceInsertClipboardContent', false, {content: 'c '});
equal(editor.getContent(), 'c
');
});
test('paste post process (event)', function() {
function callback(e) {
e.node.innerHTML += ':POST';
}
editor.setContent('a
');
Utils.setSelection('p', 0, 'p', 1);
editor.on('PastePostProcess', callback);
editor.execCommand('mceInsertClipboardContent', false, {content: 'b '});
equal(editor.getContent(), 'b :POST
');
editor.setContent('a
');
Utils.setSelection('p', 0, 'p', 1);
editor.off('PastePostProcess', callback);
editor.execCommand('mceInsertClipboardContent', false, {content: 'c '});
equal(editor.getContent(), 'c
');
});
test('paste innerText of conditional comments', function() {
equal(tinymce.pasteplugin.Utils.innerText('X'), 'X');
});
test('paste innerText of single P', function() {
editor.setContent('a
');
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML), 'a');
});
test('paste innerText of single P with whitespace wrapped content', function() {
editor.setContent(' a
');
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML), 'a');
});
test('paste innerText of two P', function() {
editor.setContent('a
b
');
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML), 'a\n\nb');
});
test('paste innerText of H1 and P', function() {
editor.setContent('a b
');
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML), 'a\nb');
});
test('paste innerText of P with BR', function() {
editor.setContent('a b
');
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML), 'a\nb');
});
test('paste innerText of P with VIDEO', function() {
editor.setContent('ab c d
');
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML), 'a d');
});
test('paste innerText of PRE', function() {
editor.getBody().innerHTML = 'a\nb\n ';
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().innerHTML).replace(/\r\n/g, '\n'), 'a\nb\n');
});
test('paste innerText of textnode with whitespace', function() {
editor.getBody().innerHTML = ' a ';
equal(tinymce.pasteplugin.Utils.innerText(editor.getBody().firstChild.innerHTML), ' a ');
});
test('trim html from clipboard fragments', function() {
equal(tinymce.pasteplugin.Utils.trimHtml('a'), 'a');
equal(tinymce.pasteplugin.Utils.trimHtml('a\n\n\nb\n\n\nc'), '\nb\n');
equal(tinymce.pasteplugin.Utils.trimHtml('abc'), 'abc');
equal(tinymce.pasteplugin.Utils.trimHtml('abc'), 'b');
equal(tinymce.pasteplugin.Utils.trimHtml('a\u00a0<\/span>b'), 'a b');
equal(tinymce.pasteplugin.Utils.trimHtml('\u00a0<\/span>b'), ' b');
equal(tinymce.pasteplugin.Utils.trimHtml('a\u00a0<\/span>'), 'a ');
equal(tinymce.pasteplugin.Utils.trimHtml('\u00a0<\/span>'), ' ');
});
if (tinymce.Env.webkit) {
test('paste webkit retains text styles runtime styles internal', function() {
editor.settings.paste_webkit_styles = 'color';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: '<span style="color:red"><span data-mce-style="color:red">'});
equal(editor.getContent(), '<span style="color:red"><span data-mce-style="color:red">
');
});
test('paste webkit remove runtime styles internal', function() {
editor.settings.paste_webkit_styles = 'color';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (color)', function() {
editor.settings.paste_webkit_styles = 'color';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles keep before attr', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles keep after attr', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles keep before/after attr', function() {
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (background-color)', function() {
editor.settings.paste_webkit_styles = 'background-color';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (font-size)', function() {
editor.settings.paste_webkit_styles = 'font-size';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (font-family)', function() {
editor.settings.paste_webkit_styles = 'font-family';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles font-family allowed but not specified', function() {
editor.settings.paste_webkit_styles = 'font-family';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test
'});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (custom styles)', function() {
editor.settings.paste_webkit_styles = 'color font-style';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (all)', function() {
editor.settings.paste_webkit_styles = 'all';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (none)', function() {
editor.settings.paste_webkit_styles = 'none';
editor.setContent('');
editor.execCommand('mceInsertClipboardContent', false, {content: 'Test '});
equal(editor.getContent(), 'Test
');
});
test('paste webkit remove runtime styles (color) in the same (color) (named)', function() {
editor.settings.paste_webkit_styles = 'color';
editor.setContent('Test
');
Utils.setSelection('p', 0, 'p', 4);
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'a ' +
'b '
)
});
equal(editor.getContent(), 'ab
');
});
test('paste webkit remove runtime styles (color) in the same (color) (hex)', function() {
editor.setContent('Test
');
Utils.setSelection('p', 0, 'p', 4);
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'a ' +
'b ' +
'c '
)
});
equal(editor.getContent(), 'abc
');
});
test('paste webkit remove runtime styles (color) in the same (color) (rgb)', function() {
editor.setContent('Test
');
Utils.setSelection('p', 0, 'p', 4);
editor.execCommand('mceInsertClipboardContent', false, {
content: (
'a ' +
'b ' +
'c '
)
});
equal(editor.getContent(), 'abc
');
});
}