module("tinymce.EditorCommands", { setupModule: function() { QUnit.stop(); tinymce.init({ selector: "textarea", plugins: wpPlugins, add_unload_trigger: false, disable_nodechange: true, indent: false, skin: false, entities: 'raw', convert_urls: false, valid_styles: { '*': 'color,font-size,font-family,background-color,font-weight,font-style,text-decoration,float,margin,margin-top,margin-right,margin-bottom,margin-left,padding-left,text-align,display' }, init_instance_callback: function(ed) { window.editor = ed; QUnit.start(); } }); } }); function getContent() { return editor.getContent({format:'raw'}).toLowerCase().replace(/[\r\n]+/g, ''); } test('mceInsertContent - p inside text of p', function() { var rng; expect(7); editor.setContent('
1234
'); editor.focus(); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 1); rng.setEnd(editor.dom.select('p')[0].firstChild, 3); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, 'abc
'); equal(getContent(), '1
abc
4
'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - p inside whole p', function() { var rng; expect(7); editor.setContent('1234
'); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 4); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, 'abc
'); equal(getContent(), 'abc
'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - pre in text of pre', function() { var rng; expect(7); editor.setContent('1234'); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('pre')[0].firstChild, 1); rng.setEnd(editor.dom.select('pre')[0].firstChild, 3); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, '
abc'); equal(getContent(), '
1
abc
4'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'PRE'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'PRE'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - h1 in text of h1', function() { var rng; expect(7); editor.setContent('
abc
'); equal(getContent(), 'abc
'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - text inside empty p', function() { var rng; expect(7); editor.getBody().innerHTML = ''; Utils.setSelection('p', 0); editor.execCommand('mceInsertContent', false, 'abc'); equal(editor.getBody().innerHTML.toLowerCase().replace(/^abc
'); // Opera inserts a BR at the beginning of contents if the P is empty rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - text inside empty p with br caret node', function() { var rng; expect(7); editor.getBody().innerHTML = 'abc
'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - image inside p', function() { var rng; expect(6); editor.setContent('1
'); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 1); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, ''); equal(editor.getContent(), ''); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 1); }); test('mceInsertContent - legacy content', function() { var rng; expect(1); // Convert legacy content editor.setContent('1
'); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('p')[0].firstChild, 0); rng.setEnd(editor.dom.select('p')[0].firstChild, 1); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, 'uustrikefont
'); }); test('mceInsertContent - hr', function() { var rng; expect(7); editor.setContent('123
'); 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('mceInsertContent', false, '1
3
'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer, editor.getBody().lastChild); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 0); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 0); }); test('mceInsertContent - forced root block', function() { expect(1); // Forced root block editor.getBody().innerHTML = ''; editor.execCommand('mceInsertContent', false, 'test123'); // Opera adds an extra paragraph since it adds a BR at the end of the contents pass though this for now since it's an minority browser equal(editor.getContent().replace(/\u00a0<\/p>/g, ''), '
test123
'); // WordPress doesn't convert to }); test('mceInsertContent - mixed inline content inside td', function() { expect(1); // Forced root block editor.getBody().innerHTML = 'X |
test123X |
123 testing span later in document
', insertedContent = 'a
'; Utils.setSelection('p', 0); editor.execCommand('mceInsertContent', false, ' b'); equal(editor.getContent(), '\u00a0ba
'); }); test('mceInsertContent - text with space after at end of block', function() { editor.getBody().innerHTML = 'a
'; Utils.setSelection('p', 1); editor.execCommand('mceInsertContent', false, 'b '); equal(editor.getContent(), 'ab\u00a0
'); }); test('mceInsertContent - text with space before/after at middle of block', function() { editor.getBody().innerHTML = 'ac
'; Utils.setSelection('p', 1); editor.execCommand('mceInsertContent', false, ' b '); equal(editor.getContent(), 'a b c
'); }); test('mceInsertContent - inline element with space before/after at middle of block', function() { editor.getBody().innerHTML = 'ac
'; Utils.setSelection('p', 1); editor.execCommand('mceInsertContent', false, ' b '); equal(editor.getContent(), 'a b c
'); }); test('mceInsertContent - block element with space before/after at middle of block', function() { editor.getBody().innerHTML = 'ac
'; Utils.setSelection('p', 1); editor.execCommand('mceInsertContent', false, 'b
'); equal(editor.getContent(), 'a
b
c
'); }); test('mceInsertContent - strong in strong', function() { editor.getBody().innerHTML = 'ac'; Utils.setSelection('strong', 1); editor.execCommand('mceInsertContent', false, {content: 'b', merge: true}); equal(editor.getContent(), 'abc
'); }); test('mceInsertContent - span in span same style color', function() { editor.getBody().innerHTML = 'ac'; Utils.setSelection('span', 1); editor.execCommand('mceInsertContent', false, {content: 'b', merge: true}); equal(editor.getContent(), 'abc
'); }); test('mceInsertContent - span in span different style color', function() { editor.getBody().innerHTML = 'ac'; Utils.setSelection('span', 1); editor.execCommand('mceInsertContent', false, {content: 'b', merge: true}); equal(editor.getContent(), 'abc
'); }); test('mceInsertContent - select with option element', function() { editor.getBody().innerHTML = '1
'; Utils.setSelection('p', 1); editor.execCommand('mceInsertContent', false, '2'); equal(editor.getContent(), '12
'); }); test('mceInsertContent - insert P in span style element #7090', function() { editor.setContent('1
3
'); Utils.setSelection('span', 1); editor.execCommand('mceInsertContent', false, '2
'); equal(editor.getContent(), '1
2
3
'); }); test('InsertHorizontalRule', function() { var rng; expect(7); editor.setContent('123
'); 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('InsertHorizontalRule'); equal(editor.getContent(), '1
3
'); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer, editor.getBody().lastChild); equal(rng.startContainer.nodeName, 'P'); equal(rng.startOffset, 0); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 0); }); test('Justify - multiple block elements selected - queryCommandState', function() { editor.setContent('test 123
"); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Italic'); equal(editor.getContent(), "test 123
"); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Underline'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Strikethrough'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontName',false,'Arial'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('FontSize',false,'7'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('ForeColor', false, '#FF0000'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('HiliteColor', false, '#FF0000'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); editor.setContent('testtest'); equal(editor.getContent(), 'testtest
'); editor.setContent('test 123
'); equal(editor.getContent(), 'test 123
'); }); test('Formatting commands (alignInline)', function() { expect(7); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyLeft'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyCenter'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyRight'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('JustifyFull'); equal(editor.getContent(), 'test 123
'); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyLeft'); equal(editor.getContent(), ''); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyCenter'); equal(editor.getContent(), ''); editor.setContent(''); editor.selection.select(editor.dom.select('img')[0]); editor.execCommand('JustifyRight'); equal(editor.getContent(), ''); }); test('mceBlockQuote', function() { expect(2); editor.focus(); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('mceBlockQuote'); equal(editor.getContent().replace(/\s+/g, ''), ''); editor.setContent('test123
test 123
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('mceBlockQuote'); equal(editor.getContent().replace(/\s+/g, ''), ''); }); test('FormatBlock', function() { expect(9); editor.setContent('test123
test123
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h1'); equal(editor.getContent(), 'test 123'); }); test('mceInsertLink (relative)', function() { expect(1); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'test'); equal(editor.getContent(), ''); }); test('mceInsertLink (link absolute)', function() { expect(1); editor.setContent('
test 123
'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'http://www.site.com'); equal(editor.getContent(), ''); }); test('mceInsertLink (link encoded)', function() { expect(1); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, '"&<>'); equal(editor.getContent(), ''); }); test('mceInsertLink (link encoded and with class)', function() { expect(1); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, {href : '"&<>', 'class' : 'test'}); equal(editor.getContent(), ''); }); test('mceInsertLink (link with space)', function() { expect(1); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, {href : 'foo bar'}); equal(editor.getContent(), ''); }); test('mceInsertLink (link floated img)', function() { expect(1); editor.setContent(''); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('mceInsertLink (link adjacent text)', function() { var rng; expect(1); editor.setContent('ab
'); rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild.lastChild, 0); rng.setEnd(editor.getBody().firstChild.lastChild, 1); editor.selection.setRng(rng); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('mceInsertLink (link text inside text)', function() { expect(1); editor.setContent(''); Utils.setSelection('em', 1, 'em', 2); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('mceInsertLink (link around existing links)', function() { expect(1); editor.setContent(''); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('mceInsertLink (link around existing links with different attrs)', function() { expect(1); editor.setContent(''); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('mceInsertLink (link around existing complex contents with links)', function() { expect(1); editor.setContent(''); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('mceInsertLink (link text inside link)', function() { expect(1); editor.setContent(''); Utils.setSelection('p', 0, 'p', 1); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), ''); }); test('unlink', function() { editor.setContent(''); editor.execCommand('SelectAll'); editor.execCommand('unlink'); equal(editor.getContent(), 'test 123
'); }); test('subscript/superscript', function() { expect(4); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('subscript'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('superscript'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('subscript'); editor.execCommand('subscript'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('superscript'); editor.execCommand('superscript'); equal(editor.getContent(), 'test 123
'); }); test('indent/outdent', function() { expect(4); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('Indent'); editor.execCommand('Indent'); editor.execCommand('Outdent'); equal(editor.getContent(), 'test 123
'); editor.setContent('test 123
'); editor.execCommand('SelectAll'); editor.execCommand('Outdent'); equal(editor.getContent(), 'test 123
'); }); test('RemoveFormat', function() { expect(4); editor.setContent('test 123 123 123
'); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); equal(editor.getContent(), 'test 123 123 123
'); editor.setContent('test 123 123 123
'); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); equal(editor.getContent(), 'test 123 123 123
'); editor.setContent('testtest 123123 123
'); editor.selection.select(editor.dom.get('x')); editor.execCommand('RemoveFormat'); equal(editor.getContent(), 'testtest 123123 123
'); editor.setContent('dfn tag code tag
samp tag kbd tag var tag cite tag mark tag q tag
dfn tag code tag samp tag kbd tag var tag cite tag mark tag q tag
'); }); test('InsertLineBreak', function() { editor.setContent('123
'); Utils.setSelection('p', 2); editor.execCommand('InsertLineBreak'); equal(editor.getContent(), '12
3
123
'); Utils.setSelection('p', 0); editor.execCommand('InsertLineBreak'); equal(editor.getContent(), '
123
123
'); Utils.setSelection('p', 3); editor.execCommand('InsertLineBreak'); equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? '123
123