module("tinymce.EditorCommands", { setupModule: function() { QUnit.stop(); tinymce.init({ selector: "textarea", 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('

1234

'); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('h1')[0].firstChild, 1); rng.setEnd(editor.dom.select('h1')[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, 'H1'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'H1'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - li inside li', function() { var rng; expect(7); editor.setContent(''); rng = editor.dom.createRng(); rng.setStart(editor.dom.select('li')[0].firstChild, 1); rng.setEnd(editor.dom.select('li')[0].firstChild, 3); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, '
  • abc
  • '); equal(getContent(), ''); rng = Utils.normalizeRng(editor.selection.getRng(true)); ok(rng.collapsed); equal(rng.startContainer.nodeName, 'LI'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'LI'); equal(rng.endOffset, 1); equal(rng.startContainer.innerHTML, 'abc'); }); test('mceInsertContent - p inside empty editor', function() { var rng; expect(7); editor.setContent(''); 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 - 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 = '


    '; rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild, 0); rng.setEnd(editor.getBody().firstChild, 0); editor.selection.setRng(rng); editor.execCommand('mceInsertContent', false, 'abc'); equal(editor.getBody().innerHTML.toLowerCase(), '

    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, 'ustrikefont'); equal(editor.getContent(), '

    ustrikefont

    '); }); 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, '
    '); 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('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

    '); }); test('mceInsertContent - mixed inline content inside td', function() { expect(1); // Forced root block editor.getBody().innerHTML = '
    X
    '; Utils.setSelection('td', 0, 'td', 0); editor.execCommand('mceInsertContent', false, 'test123'); equal(editor.getContent(), '
    test123X
    '); }); test('mceInsertContent - invalid insertion 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('mceInsertContent', false, insertedContent); equal(editor.getContent(), insertedContent + startingContent); }); test('mceInsertContent - text with space before at start of block', function() { editor.getBody().innerHTML = '

    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('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('
    one
    two
    '); Utils.setSelection('#a', 0, '#b', 3); equal(editor.queryCommandState('JustifyLeft'), false); ok(editor.queryCommandState('JustifyRight')); }); test('Formatting commands (xhtmlTextStyles)', function() { expect(19); editor.focus(); editor.setContent('test 123'); editor.execCommand('SelectAll'); editor.execCommand('Bold'); equal(editor.getContent(), "

    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

    '); 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('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, ''), '

    test123

    '); editor.setContent('

    test 123

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('mceBlockQuote'); equal(editor.getContent().replace(/\s+/g, ''), '

    test123

    test123

    '); }); test('FormatBlock', function() { expect(9); editor.setContent('

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h1'); equal(editor.getContent(), '

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h2'); equal(editor.getContent(), '

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h3'); equal(editor.getContent(), '

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h4'); equal(editor.getContent(), '

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h5'); equal(editor.getContent(), '
    test 123
    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'h6'); equal(editor.getContent(), '
    test 123
    '); editor.execCommand('SelectAll'); try { editor.execCommand('FormatBlock', false, 'div'); } catch (ex) { //t.log('Failed: ' + ex.message); } equal(editor.getContent(), '
    test 123
    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'address'); equal(editor.getContent(), '
    test 123
    '); editor.execCommand('SelectAll'); editor.execCommand('FormatBlock', false, 'pre'); 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 123

    '); }); 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 123

    '); }); test('mceInsertLink (link encoded)', function() { expect(1); editor.setContent('

    test 123

    '); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, '"&<>'); equal(editor.getContent(), '

    test 123

    '); }); 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 123

    '); }); 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 123

    '); }); 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(), '

    ab

    '); }); test('mceInsertLink (link text inside text)', function() { expect(1); editor.setContent('

    abc

    '); Utils.setSelection('em', 1, 'em', 2); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), '

    abc

    '); }); test('mceInsertLink (link around existing links)', function() { expect(1); editor.setContent('

    12

    '); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), '

    12

    '); }); test('mceInsertLink (link around existing links with different attrs)', function() { expect(1); editor.setContent('

    12

    '); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), '

    12

    '); }); test('mceInsertLink (link around existing complex contents with links)', function() { expect(1); editor.setContent('

    12

    '); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), '

    12

    '); }); test('mceInsertLink (link text inside link)', function() { expect(1); editor.setContent('

    test

    '); Utils.setSelection('p', 0, 'p', 1); editor.execCommand('SelectAll'); editor.execCommand('mceInsertLink', false, 'link'); equal(editor.getContent(), '

    test

    '); }); test('unlink', function() { editor.setContent('

    test 123

    '); 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

    '); editor.execCommand('SelectAll'); editor.execCommand('RemoveFormat'); equal(editor.getContent(), '

    dfn tag code tag samp tag kbd tag var tag cite tag mark tag q tag

    '); });