diff --git a/tests/qunit/editor/external-plugins/noneditable/plugin.js b/tests/qunit/editor/external-plugins/noneditable/plugin.js deleted file mode 100644 index 5ab5f4f38f..0000000000 --- a/tests/qunit/editor/external-plugins/noneditable/plugin.js +++ /dev/null @@ -1,101 +0,0 @@ -/** - * plugin.js - * - * Released under LGPL License. - * Copyright (c) 1999-2015 Ephox Corp. All rights reserved - * - * License: http://www.tinymce.com/license - * Contributing: http://www.tinymce.com/contributing - */ - -/*global tinymce:true */ - -tinymce.PluginManager.add('noneditable', function(editor) { - var editClass, nonEditClass, nonEditableRegExps, contentEditableAttrName = 'contenteditable'; - - function hasClass(checkClassName) { - return function(node) { - return (" " + node.attr("class") + " ").indexOf(checkClassName) !== -1; - }; - } - - function convertRegExpsToNonEditable(e) { - var i = nonEditableRegExps.length, content = e.content, cls = tinymce.trim(nonEditClass); - - function replaceMatchWithSpan(match) { - var args = arguments, index = args[args.length - 2]; - - // Is value inside an attribute then don't replace - if (index > 0 && content.charAt(index - 1) == '"') { - return match; - } - - return ( - '' + - editor.dom.encode(typeof args[1] === "string" ? args[1] : args[0]) + '' - ); - } - - // Don't replace the variables when raw is used for example on undo/redo - if (e.format == "raw") { - return; - } - - while (i--) { - content = content.replace(nonEditableRegExps[i], replaceMatchWithSpan); - } - - e.content = content; - } - - editClass = " " + tinymce.trim(editor.getParam("noneditable_editable_class", "mceEditable")) + " "; - nonEditClass = " " + tinymce.trim(editor.getParam("noneditable_noneditable_class", "mceNonEditable")) + " "; - - var hasEditClass = hasClass(editClass); - var hasNonEditClass = hasClass(nonEditClass); - - nonEditableRegExps = editor.getParam("noneditable_regexp"); - if (nonEditableRegExps && !nonEditableRegExps.length) { - nonEditableRegExps = [nonEditableRegExps]; - } - - editor.on('PreInit', function() { - if (nonEditableRegExps) { - editor.on('BeforeSetContent', convertRegExpsToNonEditable); - } - - editor.parser.addAttributeFilter('class', function(nodes) { - var i = nodes.length, node; - - while (i--) { - node = nodes[i]; - - if (hasEditClass(node)) { - node.attr(contentEditableAttrName, "true"); - } else if (hasNonEditClass(node)) { - node.attr(contentEditableAttrName, "false"); - } - } - }); - - editor.serializer.addAttributeFilter(contentEditableAttrName, function(nodes) { - var i = nodes.length, node; - - while (i--) { - node = nodes[i]; - if (!hasEditClass(node) && !hasNonEditClass(node)) { - continue; - } - - if (nonEditableRegExps && node.attr('data-mce-content')) { - node.name = "#text"; - node.type = 3; - node.raw = true; - node.value = node.attr('data-mce-content'); - } else { - node.attr(contentEditableAttrName, null); - } - } - }); - }); -}); \ No newline at end of file diff --git a/tests/qunit/editor/external-plugins/noneditable/plugin.min.js b/tests/qunit/editor/external-plugins/noneditable/plugin.min.js deleted file mode 100644 index 49e9d5a532..0000000000 --- a/tests/qunit/editor/external-plugins/noneditable/plugin.min.js +++ /dev/null @@ -1 +0,0 @@ -tinymce.PluginManager.add("noneditable",function(a){function b(a){return function(b){return-1!==(" "+b.attr("class")+" ").indexOf(a)}}function c(b){function c(b){var c=arguments,d=c[c.length-2];return d>0&&'"'==g.charAt(d-1)?b:''+a.dom.encode("string"==typeof c[1]?c[1]:c[0])+""}var d=f.length,g=b.content,h=tinymce.trim(e);if("raw"!=b.format){for(;d--;)g=g.replace(f[d],c);b.content=g}}var d,e,f,g="contenteditable";d=" "+tinymce.trim(a.getParam("noneditable_editable_class","mceEditable"))+" ",e=" "+tinymce.trim(a.getParam("noneditable_noneditable_class","mceNonEditable"))+" ";var h=b(d),i=b(e);f=a.getParam("noneditable_regexp"),f&&!f.length&&(f=[f]),a.on("PreInit",function(){f&&a.on("BeforeSetContent",c),a.parser.addAttributeFilter("class",function(a){for(var b,c=a.length;c--;)b=a[c],h(b)?b.attr(g,"true"):i(b)&&b.attr(g,"false")}),a.serializer.addAttributeFilter(g,function(a){for(var b,c=a.length;c--;)b=a[c],(h(b)||i(b))&&(f&&b.attr("data-mce-content")?(b.name="#text",b.type=3,b.raw=!0,b.value=b.attr("data-mce-content")):b.attr(g,null))})})}); \ No newline at end of file diff --git a/tests/qunit/editor/index.html b/tests/qunit/editor/index.html deleted file mode 100644 index f013b9a13c..0000000000 --- a/tests/qunit/editor/index.html +++ /dev/null @@ -1,155 +0,0 @@ - - -
- -| Expected: | " + expected + " |
|---|---|
| Result: | " + actual + " |
| Diff: | " + QUnit.diff( expected, actual ) + " |
| Source: | " + escapeText( source ) + " |
| Result: | " + escapeText( actual ) + " |
|---|---|
| Source: | " + escapeText( source ) + " |
| Source: | " + - escapeText( source ) + - " |
|---|
<\/p>\n?/, '').replace(/\n?
<\/p>$/, ''); - } - - /** - * Fakes a key event. - * - * @param {Element/String} e DOM element object or element id to send fake event to. - * @param {String} na Event name to fake like "keydown". - * @param {Object} o Optional object with data to send with the event like keyCode and charCode. - */ - function fakeKeyEvent(e, na, o) { - var ev; - - o = tinymce.extend({ - keyCode : 13, - charCode : 0 - }, o); - - e = tinymce.DOM.get(e); - - if (e.fireEvent) { - ev = document.createEventObject(); - tinymce.extend(ev, o); - e.fireEvent('on' + na, ev); - return; - } - - if (document.createEvent) { - try { - // Fails in Safari - ev = document.createEvent('KeyEvents'); - ev.initKeyEvent(na, true, true, window, false, false, false, false, o.keyCode, o.charCode); - } catch (ex) { - ev = document.createEvent('Events'); - ev.initEvent(na, true, true); - - ev.keyCode = o.keyCode; - ev.charCode = o.charCode; - } - } else { - ev = document.createEvent('UIEvents'); - - if (ev.initUIEvent) { - ev.initUIEvent(na, true, true, window, 1); - } - - ev.keyCode = o.keyCode; - ev.charCode = o.charCode; - } - - e.dispatchEvent(ev); - } - - function normalizeRng(rng) { - if (rng.startContainer.nodeType == 3) { - if (rng.startOffset === 0) { - rng.setStartBefore(rng.startContainer); - } else if (rng.startOffset >= rng.startContainer.nodeValue.length - 1) { - rng.setStartAfter(rng.startContainer); - } - } - - if (rng.endContainer.nodeType == 3) { - if (rng.endOffset === 0) { - rng.setEndBefore(rng.endContainer); - } else if (rng.endOffset >= rng.endContainer.nodeValue.length - 1) { - rng.setEndAfter(rng.endContainer); - } - } - - return rng; - } - - // TODO: Replace this with the new event logic in 3.5 - function type(chr) { - var editor = tinymce.activeEditor, keyCode, charCode, evt, startElm, rng, offset; - - function charCodeToKeyCode(charCode) { - var lookup = { - '0': 48, '1': 49, '2': 50, '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, '8': 56, '9': 57, 'a': 65, 'b': 66, 'c': 67, - 'd': 68, 'e': 69, 'f': 70, 'g': 71, 'h': 72, 'i': 73, 'j': 74, 'k': 75, 'l': 76, 'm': 77, 'n': 78, 'o': 79, 'p': 80, 'q': 81, - 'r': 82, 's': 83, 't': 84, 'u': 85, 'v': 86, 'w': 87, 'x': 88, 'y': 89, ' ': 32, ',': 188, '-': 189, '.': 190, '/': 191, '\\': 220, - '[': 219, ']': 221, '\'': 222, ';': 186, '=': 187, ')': 41 - }; - - return lookup[String.fromCharCode(charCode)]; - } - - function fakeEvent(target, type, evt) { - editor.dom.fire(target, type, evt); - } - - // Numeric keyCode - if (typeof chr == "number") { - charCode = chr; - keyCode = charCodeToKeyCode(charCode); - } else if (typeof chr == "string") { - // String value - if (chr == '\b') { - keyCode = 8; - charCode = chr.charCodeAt(0); - } else if (chr == '\n') { - keyCode = 13; - charCode = chr.charCodeAt(0); - } else { - charCode = chr.charCodeAt(0); - keyCode = charCodeToKeyCode(charCode); - } - } else { - evt = chr; - - if (evt.charCode) { - chr = String.fromCharCode(evt.charCode); - } - - if (evt.keyCode) { - keyCode = evt.keyCode; - } - } - - evt = evt || {keyCode: keyCode, charCode: charCode}; - - startElm = editor.selection.getStart(); - fakeEvent(startElm, 'keydown', evt); - fakeEvent(startElm, 'keypress', evt); - - if (!evt.isDefaultPrevented()) { - if (keyCode == 8) { - if (editor.getDoc().selection) { - rng = editor.getDoc().selection.createRange(); - - if (rng.text.length === 0) { - rng.moveStart('character', -1); - rng.select(); - } - - rng.execCommand('Delete', false, null); - } else { - rng = editor.selection.getRng(); - - if (rng.collapsed) { - if (rng.startContainer.nodeType == 1) { - var nodes = rng.startContainer.childNodes, lastNode = nodes[nodes.length - 1]; - - // If caret is at
abc|
and after the abc text node then move it to the end of the text node - // Expand the range to include the last charab[c]
since IE 11 doesn't delete otherwise - if (rng.startOffset >= nodes.length - 1 && lastNode && lastNode.nodeType == 3 && lastNode.data.length > 0) { - rng.setStart(lastNode, lastNode.data.length - 1); - rng.setEnd(lastNode, lastNode.data.length); - editor.selection.setRng(rng); - } - } else if (rng.startContainer.nodeType == 3) { - // If caret is atabc|
and after the abc text node then move it to the end of the text node - // Expand the range to include the last charab[c]
since IE 11 doesn't delete otherwise - offset = rng.startOffset; - if (offset > 0) { - rng.setStart(rng.startContainer, offset - 1); - rng.setEnd(rng.startContainer, offset); - editor.selection.setRng(rng); - } - } - } - - editor.getDoc().execCommand('Delete', false, null); - } - } else if (typeof chr == 'string') { - rng = editor.selection.getRng(true); - - if (rng.startContainer.nodeType == 3 && rng.collapsed) { - rng.startContainer.insertData(rng.startOffset, chr); - rng.setStart(rng.startContainer, rng.startOffset + 1); - rng.collapse(true); - editor.selection.setRng(rng); - } else { - rng.deleteContents(); - rng.insertNode(editor.getDoc().createTextNode(chr)); - } - } - } - - fakeEvent(startElm, 'keyup', evt); - } - - function cleanHtml(html) { - html = html.toLowerCase().replace(/[\r\n]+/gi, ''); - html = html.replace(/ (sizcache[0-9]+|sizcache|nodeindex|sizset[0-9]+|sizset|data\-mce\-expando|data\-mce\-selected)="[^"]*"/gi, ''); - html = html.replace(/]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\/span>|a
'); - equal(lastLevel.content, editor.undoManager.data[0].content); - - editor.off('change'); -}); - -test('Event: beforeExecCommand', function() { - var cmd, ui, value; - - editor.on('BeforeExecCommand', function(e) { - cmd = e.command; - ui = e.ui; - value = e.value; - - e.preventDefault(); - }); - - editor.setContent(''); - editor.insertContent('a'); - equal(editor.getContent(), ''); - equal(cmd, 'mceInsertContent'); - equal(ui, false); - equal(value, 'a'); - - editor.off('BeforeExecCommand'); - editor.setContent(''); - editor.insertContent('a'); - equal(editor.getContent(), 'a
'); -}); - -test('urls - relativeURLs', function() { - editor.settings.relative_urls = true; - editor.documentBaseURI = new tinymce.util.URI('http://www.site.com/dirA/dirB/dirC/'); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); -}); - -test('urls - absoluteURLs', function() { - editor.settings.relative_urls = false; - editor.settings.remove_script_host = true; - editor.documentBaseURI = new tinymce.util.URI('http://www.site.com/dirA/dirB/dirC/'); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.settings.relative_urls = false; - editor.settings.remove_script_host = false; - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); - - editor.setContent('test'); - equal(editor.getContent(), ''); -}); - -test('WebKit Serialization range bug', function() { - expect(1); - - if (tinymce.isIE) { - ok(true, "Skip IE"); - } else { - // Note that if we create the P with this invalid content directly, Chrome cleans it up differently to other browsers so we don't - // wind up testing the serialization functionality we were aiming for and the test fails. - var p = editor.dom.create('p', {}, '123| X |
123
| X |
456
'); - } -}); - -test('editor_methods - getParam', function() { - expect(5); - - editor.settings.test = 'a,b,c'; - equal(editor.getParam('test', '', 'hash').c, 'c'); - - editor.settings.test = 'a'; - equal(editor.getParam('test', '', 'hash').a, 'a'); - - editor.settings.test = 'a=b'; - equal(editor.getParam('test', '', 'hash').a, 'b'); - - editor.settings.test = 'a=b;c=d,e'; - equal(editor.getParam('test', '', 'hash').c, 'd,e'); - - editor.settings.test = 'a=b,c=d'; - equal(editor.getParam('test', '', 'hash').c, 'd'); -}); - -test('setContent', function() { - var count; - - expect(4); - - function callback(e) { - e.content = e.content.replace(/test/, 'X'); - count++; - } - - editor.on('SetContent', callback); - editor.on('BeforeSetContent', callback); - count = 0; - editor.setContent('test
'); - equal(editor.getContent(), "X
"); - equal(count, 2); - editor.off('SetContent', callback); - editor.off('BeforeSetContent', callback); - - count = 0; - editor.setContent('test
'); - equal(editor.getContent(), "test
"); - equal(count, 0); -}); - -test('setContent with comment bug #4409', function() { - editor.setContent('\u00a0
"); -}); - -test('custom elements', function() { - editor.setContent('abc
'); - equal(editor.getContent(), 'abc
'); -}); - -test('show/hide/isHidden and events', function() { - var lastEvent; - - editor.on('show hide', function(e) { - lastEvent = e; - }); - - equal(editor.isHidden(), false, 'Initial isHidden state'); - - editor.hide(); - equal(editor.isHidden(), true, 'After hide isHidden state'); - equal(lastEvent.type, "hide"); - - lastEvent = null; - editor.hide(); - strictEqual(lastEvent, null); - - editor.show(); - equal(editor.isHidden(), false, 'After show isHidden state'); - equal(lastEvent.type, "show"); - - lastEvent = null; - editor.show(); - strictEqual(lastEvent, null); -}); - -test('show/hide/isHidden and events (inline)', function() { - var lastEvent; - - inlineEditor.on('show hide', function(e) { - lastEvent = e; - }); - - equal(inlineEditor.isHidden(), false, 'Initial isHidden state'); - - inlineEditor.hide(); - equal(inlineEditor.isHidden(), true, 'After hide isHidden state'); - equal(lastEvent.type, "hide"); - strictEqual(inlineEditor.getBody().contentEditable, "false", "ContentEditable after hide"); - - lastEvent = null; - inlineEditor.hide(); - strictEqual(lastEvent, null); - - inlineEditor.show(); - equal(inlineEditor.isHidden(), false, 'After show isHidden state'); - equal(lastEvent.type, "show"); - strictEqual(inlineEditor.getBody().contentEditable, "true", "ContentEditable after show"); - - lastEvent = null; - inlineEditor.show(); - strictEqual(lastEvent, null); -}); - -test('hide save content and hidden state while saving', function() { - var lastEvent, hiddenStateWhileSaving; - - editor.on('SaveContent', function(e) { - lastEvent = e; - hiddenStateWhileSaving = editor.isHidden(); - }); - - editor.setContent('xyz'); - editor.hide(); - - strictEqual(hiddenStateWhileSaving, false, 'False isHidden state while saving'); - strictEqual(lastEvent.content, 'xyz
'); - strictEqual(document.getElementById('elm1').value, 'xyz
'); -}); - -asyncTest('remove editor', function() { - document.getElementById('view').appendChild(tinymce.DOM.create('textarea', {id: 'elmx'})); - - tinymce.init({ - selector: "#elmx", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - init_instance_callback: function(editor) { - window.setTimeout(function() { - var lastEvent; - - editor.on('SaveContent', function(e) { - lastEvent = e; - }); - - editor.setContent('xyz'); - editor.remove(); - - QUnit.start(); - - strictEqual(lastEvent.content, 'xyz
'); - strictEqual(document.getElementById('elmx').value, 'xyz
'); - }, 0); - } - }); -}); - -test('insertContent', function() { - editor.setContent('ab
'); - Utils.setSelection('p', 1); - editor.insertContent('c'); - equal(editor.getContent(), 'acb
'); -}); - -test('insertContent merge', function() { - editor.setContent('a
'); - Utils.setSelection('p', 1); - editor.insertContent('b', {merge: true}); - equal(editor.getContent(), 'ab
'); -}); - -test('execCommand return values for native commands', function() { - var lastCmd; - - strictEqual(editor.execCommand("NonExistingCommand"), false, "Return value for a completely unhandled command"); - - Utils.patch(editor.getDoc(), 'execCommand', function(orgFunc, cmd) { - lastCmd = cmd; - return true; - }); - - strictEqual(editor.execCommand("ExistingCommand"), true, "Return value for an editor handled command"); - strictEqual(lastCmd, "ExistingCommand"); -}); - -test('addCommand', function() { - var scope = {}, lastScope, lastArgs; - - function callback() { - lastScope = this; - lastArgs = arguments; - } - - editor.addCommand("CustomCommand1", callback, scope); - editor.addCommand("CustomCommand2", callback); - - editor.execCommand("CustomCommand1", false, "value", {extra: true}); - strictEqual(lastArgs[0], false); - strictEqual(lastArgs[1], "value"); - ok(lastScope === scope); - - editor.execCommand("CustomCommand2"); - equal(typeof lastArgs[0], "undefined"); - equal(typeof lastArgs[1], "undefined"); - ok(lastScope === editor); -}); - -test('addQueryStateHandler', function() { - var scope = {}, lastScope, currentState; - - function callback() { - lastScope = this; - return currentState; - } - - editor.addQueryStateHandler("CustomCommand1", callback, scope); - editor.addQueryStateHandler("CustomCommand2", callback); - - currentState = false; - ok(!editor.queryCommandState("CustomCommand1")); - ok(lastScope === scope, "Scope is not custom scope"); - - currentState = true; - ok(editor.queryCommandState("CustomCommand2")); - ok(lastScope === editor, "Scope is not editor"); -}); - -test('Block script execution', function() { - editor.setContent('x
'); - equal( - Utils.cleanHtml(editor.getBody().innerHTML), - '' + - '' + - '' + - 'x
' - ); - equal( - editor.getContent(), - '' + - '' + - '' + - 'x
' - ); -}); - -test('addQueryValueHandler', function() { - var scope = {}, lastScope, currentValue; - - function callback() { - lastScope = this; - return currentValue; - } - - editor.addQueryValueHandler("CustomCommand1", callback, scope); - editor.addQueryValueHandler("CustomCommand2", callback); - - currentValue = "a"; - equal(editor.queryCommandValue("CustomCommand1"), "a"); - ok(lastScope === scope, "Scope is not custom scope"); - - currentValue = "b"; - ok(editor.queryCommandValue("CustomCommand2"), "b"); - ok(lastScope === editor, "Scope is not editor"); -}); - -test('setDirty/isDirty', function() { - var lastArgs = null; - - editor.on('dirty', function(e) { - lastArgs = e; - }); - - editor.setDirty(false); - strictEqual(lastArgs, null); - strictEqual(editor.isDirty(), false); - - editor.setDirty(true); - strictEqual(lastArgs.type, 'dirty'); - strictEqual(editor.isDirty(), true); - - lastArgs = null; - editor.setDirty(true); - strictEqual(lastArgs, null); - strictEqual(editor.isDirty(), true); - - editor.setDirty(false); - strictEqual(lastArgs, null); - strictEqual(editor.isDirty(), false); -}); - -test('setMode', function() { - var clickCount = 0; - - editor.on('click', function() { - clickCount++; - }); - - editor.dom.fire(editor.getBody(), 'click'); - equal(clickCount, 1); - - editor.setMode('readonly'); - equal(editor.theme.panel.find('button:last')[2].disabled(), true); - editor.dom.fire(editor.getBody(), 'click'); - equal(clickCount, 1); - - editor.setMode('design'); - editor.dom.fire(editor.getBody(), 'click'); - equal(editor.theme.panel.find('button:last')[2].disabled(), false); - equal(clickCount, 2); -}); - -test('translate', function() { - tinymce.addI18n('en_US', { - 'input i18n': 'output i18n' - }); - - equal(editor.translate('input i18n'), 'output i18n'); -}); - -test('Treat some paragraphs as empty contents', function() { - editor.setContent('\u00a0
'); - equal(editor.getContent(), ''); -}); - -test('kamer word bounderies', function() { - editor.setContent('!\u200b!\u200b!
'); - equal(editor.getContent(), '!\u200b!\u200b!
'); -}); - -test('Padd empty elements with br', function() { - editor.settings.padd_empty_with_br = true; - editor.setContent('a
'); - equal(editor.getContent(), 'a
a
'); - Utils.setSelection('p', 1); - editor.insertContent('b
'); - equal(editor.getContent(), 'a
b
'); - equal(editor.getContent(), '
'); -}); diff --git a/tests/qunit/editor/tinymce/EditorCommands.js b/tests/qunit/editor/tinymce/EditorCommands.js deleted file mode 100644 index 641cf5e6d0..0000000000 --- a/tests/qunit/editor/tinymce/EditorCommands.js +++ /dev/null @@ -1,890 +0,0 @@ -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 before HR', function() { - var rng; - - editor.setContent('x
def
'); - Utils.setSelection('h1', 3); - editor.execCommand('mceInsertContent', false, 'def
'); -}); - -test('mceInsertContent HR at end of H1 with inline elements with P sibling', function() { - editor.setContent('def
'); - Utils.setSelection('strong', 3); - editor.execCommand('mceInsertContent', false, 'def
'); -}); - -test('mceInsertContent empty block', function() { - editor.setContent('\u00a0
def
'); - Utils.setSelection('h1', 3); - editor.execCommand('mceInsertContent', false, '| \u00a0 |
def
'); -}); - -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, '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, 'strikefont
'); -}); - -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
'); -}); - -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('mceInsertContent - insert char at char surrounded by spaces', function() { - editor.setContent('a b c
'); - Utils.setSelection('p', 2, 'p', 3); - editor.execCommand('mceInsertContent', false, 'X'); - equal(tinymce.util.JSON.serialize(editor.getContent()), '"a X 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('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
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.selection.select(editor.dom.select('img')[0]);
- editor.execCommand('JustifyCenter');
- equal(editor.getContent(), '
');
- editor.selection.select(editor.dom.select('img')[0]);
- editor.execCommand('JustifyRight');
- equal(editor.getContent(), '
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('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('mceInsertLink bug #7331', function() { - editor.setContent('| A |
| B |
| A |
| B |
test 123
'); -}); - -test('unlink - unselected a[href] with childNodes', function() { - editor.setContent(''); - Utils.setSelection('em', 0); - editor.execCommand('unlink'); - equal(editor.getContent(), 'test
'); -}); - -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('indent/outdent table always uses margin', function () { - expect(4); - - editor.setContent('| test |
| test |
| test |
| test |
| test |
| test |
| test |
| test |
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
'); -}); - -if (tinymce.Env.ceFalse) { - test('SelectAll', function() { - editor.setContent('a
c
'); - Utils.setSelection('div div', 0); - editor.execCommand('SelectAll'); - equal(editor.selection.getStart().nodeName, 'DIV'); - equal(editor.selection.getEnd().nodeName, 'DIV'); - equal(editor.selection.isCollapsed(), false); - }); -} - -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



\u00a0
'); - equal(editor.selection.getRng(true).startContainer.nodeName, 'P'); -}); - -test('Enter in midde of H1', function() { - editor.setContent('ab
'); - editor.selection.setCursorLocation(editor.getBody().firstChild, 1); - Utils.pressEnter(); - equal(editor.getContent(), 'a
b
'); - var rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeValue, 'b'); -}); - -test('Enter before first IMG in P', function() { - editor.setContent('\u00a0
\u00a0
abc
abc
abc
abc
\u00a0
'); -}); - -test('Enter before last INPUT in P with text', function() { - editor.setContent('abc
'); - editor.selection.setCursorLocation(editor.getBody().firstChild, 1); - Utils.pressEnter(); - equal(editor.getContent(), 'abc
'); - var rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'INPUT'); -}); - -test('Enter before last INPUT in P with IMG sibling', function() { - editor.setContent(''); - editor.selection.setCursorLocation(editor.getBody().firstChild, 1); - Utils.pressEnter(); - equal(editor.getContent(), ''); - var rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'INPUT'); -}); - -test('Enter after last INPUT in P', function() { - editor.setContent('abc
'); - editor.selection.setCursorLocation(editor.getBody().firstChild, 2); - Utils.pressEnter(); - equal(editor.getContent(), 'abc
\u00a0
'); -}); - -test('Enter at end of P', function() { - editor.setContent('abc
'); - Utils.setSelection('p', 3); - Utils.pressEnter(); - equal(editor.getContent(), 'abc
\u00a0
'); - equal(editor.selection.getRng(true).startContainer.nodeName, 'P'); -}); - -test('Enter at end of EM inside P', function() { - editor.setContent('abc
'); - Utils.setSelection('em', 3); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/abc
'); - equal(editor.selection.getRng(true).startContainer.nodeName, 'EM'); -}); - -test('Enter at middle of EM inside P', function() { - editor.setContent('
abcd
'); - Utils.setSelection('em', 2); - Utils.pressEnter(); - equal(editor.getContent(), 'ab
cd
'); - equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM'); -}); - -test('Enter at beginning EM inside P', function() { - editor.setContent('abc
'); - Utils.setSelection('em', 0); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/abc
'); - equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc'); -}); - -test('Enter at end of STRONG in EM inside P', function() { - editor.setContent('abc
'); - Utils.setSelection('strong', 3); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/abc
'); - equal(editor.selection.getRng(true).startContainer.nodeName, 'STRONG'); -}); - -test('Enter at middle of STRONG in EM inside P', function() { - editor.setContent('
abcd
'); - Utils.setSelection('strong', 2); - Utils.pressEnter(); - equal(editor.getContent(), 'ab
cd
'); - equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG'); -}); - -test('Enter at beginning STRONG in EM inside P', function() { - editor.setContent('abc
'); - Utils.setSelection('strong', 0); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/abc
'); - equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc'); -}); - -test('Enter at beginning of P', function() { - editor.setContent('abc
'); - Utils.setSelection('p', 0); - Utils.pressEnter(); - equal(editor.getContent(), '\u00a0
abc
'); - equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc'); -}); - -test('Enter at middle of P with style, id and class attributes', function() { - editor.setContent('abcd
'); - Utils.setSelection('p', 2); - Utils.pressEnter(); - equal(editor.getContent(), 'ab
cd
'); - equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P'); -}); - -test('Enter at a range between H1 and P', function() { - editor.setContent('efgh
'); - Utils.setSelection('h1', 2, 'p', 2); - Utils.pressEnter(); - equal(editor.getContent(), '| d e |
| d e |
ab
cd
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside at beginning of text node in body', function() { - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 0); - Utils.pressEnter(); - equal(editor.getContent(), '\u00a0
abcd
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside at end of text node in body', function() { - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 4); - Utils.pressEnter(); - equal(editor.getContent(), 'abcd
\u00a0
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside empty body', function() { - editor.getBody().innerHTML = ''; - Utils.setSelection('body', 0); - Utils.pressEnter(); - equal(editor.getContent(), '\u00a0
\u00a0
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside empty li in beginning of ol', function() { - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '\u00a0
\u00a0
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Shift+Enter inside empty li in the middle of ol', function() { - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '\u00a0
\u00a0
\u00a0
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside empty li in the middle of ol with forced_root_block: false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '\u00a0
\u00a0
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter at end of last empty DD inside DL', function() { - editor.getBody().innerHTML = '\u00a0
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter at beginning of P inside LI', function() { - editor.getBody().innerHTML = 'abcd
abcd
abcd
ab
cd
abcd
abcd
abcd
abcd
abcd
ab
cd
abcd
abcd
abcd
abcd
\u00a0
abcd
abcd
ab
cd
abcd
abcd
\u00a0
abc
'; - Utils.setSelection('p', 2); - Utils.pressEnter(); - equal(editor.getContent(), 'ab
c
abc
'; - Utils.setSelection('p', 3); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? 'abc
abc
' : 'abc
'; - Utils.setSelection('p:last', 0); - Utils.pressEnter(); - equal(editor.getContent(), 'abc
abc
\u00a0
'); -}); - -test('Enter in empty P at the beginning of a blockquote and end_container_on_empty_block: true', function() { - editor.settings.end_container_on_empty_block = true; - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '' : 'abc
'; - Utils.setSelection('p', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
abc
\u00a0
'); -}); - -test('Enter in empty P at in the middle of a blockquote and end_container_on_empty_block: true', function() { - editor.settings.end_container_on_empty_block = true; - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? 'abc
' : 'abc
123
'; - Utils.setSelection('p:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), 'abc
123
abc
\u00a0
'); -}); - -test('Enter inside empty P with empty P siblings', function() { - // Tests that a workaround for an IE bug is working correctly - editor.getBody().innerHTML = '123
X
'; - Utils.setSelection('p', 0); - Utils.pressEnter(); - equal(editor.getContent(), '\u00a0
\u00a0
\u00a0
X
'); -}); - -test('Enter at end of H1 with forced_root_block_attrs', function() { - editor.settings.forced_root_block_attrs = {"class": "class1"}; - editor.getBody().innerHTML = '\u00a0
'); -}); - -test('Shift+Enter at beginning of P', function() { - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('p', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
abc
abcd
'; - Utils.setSelection('p', 2); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), 'ab
cd
abcd
'; - Utils.setSelection('p', 4); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), (tinymce.isIE && tinymce.Env.ie < 11) ? 'abcd
' : 'abcd
abcd
ab
cd
abcd
abcd
abc'; - Utils.setSelection('pre', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
'); -}); - -test('Enter in the middle of PRE', function() { - editor.getBody().innerHTML = '
abc
abcd'; - Utils.setSelection('pre', 2); - Utils.pressEnter(); - equal(editor.getContent(), '
ab'); -}); - -test('Enter at the end of PRE', function() { - editor.getBody().innerHTML = '
cd
abcd'; - Utils.setSelection('pre', 4); - Utils.pressEnter(); - equal(editor.getContent(), (tinymce.isIE && tinymce.Env.ie < 11) ? '
abcd' : '
abcd'); -}); - -test('Enter in beginning of PRE and br_in_pre: false', function() { - editor.settings.br_in_pre = false; - editor.getBody().innerHTML = '
abc'; - Utils.setSelection('pre', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
\u00a0
abc'); -}); - -test('Enter in the middle of PRE and br_in_pre: false', function() { - editor.settings.br_in_pre = false; - editor.getBody().innerHTML = '
abcd'; - Utils.setSelection('pre', 2); - Utils.pressEnter(); - equal(editor.getContent(), '
ab
cd'); -}); - -test('Enter at the end of PRE and br_in_pre: false', function() { - editor.settings.br_in_pre = false; - editor.getBody().innerHTML = '
abcd'; - Utils.setSelection('pre', 4); - Utils.pressEnter(); - equal(editor.getContent(), '
abcd
\u00a0
'); -}); - -test('Shift+Enter in beginning of PRE', function() { - editor.getBody().innerHTML = 'abc'; - Utils.setSelection('pre', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
\u00a0
abc'); -}); - -test('Shift+Enter in the middle of PRE', function() { - editor.getBody().innerHTML = '
abcd'; - Utils.setSelection('pre', 2); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
ab
cd'); -}); - -test('Shift+Enter at the end of PRE', function() { - editor.getBody().innerHTML = '
abcd'; - Utils.setSelection('pre', 4); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
abcd
\u00a0
'); -}); - -test('Shift+Enter in beginning of P with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('p', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '\u00a0
abc
'); -}); - -test('Shift+Enter in middle of P with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abcd
'; - Utils.setSelection('p', 2); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), 'ab
cd
'); -}); - -test('Shift+Enter at the end of P with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('p', 3); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), 'abc
\u00a0
'); -}); - -test('Shift+Enter in body with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abcd'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 2); - rng.setEnd(editor.getBody().firstChild, 2); - editor.selection.setRng(rng); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), 'ab
cd
'); -}); - -test('Enter at the end of DIV layer', function() { - editor.settings.br_in_pre = false; - editor.setContent('abcd
\u00a0
ab
cd
ab
cd
X
'; - Utils.setSelection('span', 1); - Utils.pressEnter(); - equal(editor.getContent(), 'X
\u00a0
'); -}); - -test('Shift+enter in LI when forced_root_block: false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'te
xt
'); -}); - -test('Enter at end of br line', function() { - editor.settings.forced_root_block = false; - editor.settings.force_p_newlines = true; - editor.getBody().innerHTML = 'a
b
a
b
\u00a0
\u00a0
| x |
| x |
\u00a0
'); - }); - - test('Enter before table element', function() { - var rng = editor.dom.createRng(); - - editor.getBody().innerHTML = '| x |
\u00a0
| x |
| x |
x
'; - rng.setStartAfter(editor.getBody().firstChild); - rng.setEndAfter(editor.getBody().firstChild); - editor.selection.setRng(rng); - - Utils.pressEnter(); - equal(editor.getContent(), '| x |
\u00a0
x
'); - }); - - test('Enter before table element preceded by a p', function() { - var rng = editor.dom.createRng(); - - editor.getBody().innerHTML = 'x
| x |
x
\u00a0
| x |
| x |
\u00a0
\u00a0
| x |
abc
'); - Utils.setSelection('b', 3); - Utils.pressEnter(); - equal(editor.getContent(), 'abc
\u00a0
'); - - var rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, 'B'); - notEqual(rng.startContainer.data, ' '); - }); -} - -if (tinymce.Env.ceFalse) { - test('Enter before cE=false div', function() { - editor.getBody().innerHTML = 'abcd
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Wrap single root text node in P with attrs', function() { - editor.settings.forced_root_block_attrs = {"class": "class1"}; - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 2); - Utils.pressArrowKey(); - equal(editor.getContent(), 'abcd
'); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Wrap single root text node in P but not table sibling', function() { - editor.getBody().innerHTML = 'abcd| x |
abcd
| x |
| x |
abcd
| x |
1234
5678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[1].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
5678
', 'selection of a list'); -}); - -test('Toggle OFF - Inline element on selected text', function() { - // Toggle OFF - Inline element on selected text - editor.formatter.register('format', { - inline: 'b', - toggle: false - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.toggle('format'); - equal(getContent(), '1234
'); -}); - -test('Toggle OFF - Inline element on partially selected text', function() { - // Toggle OFF - Inline element on partially selected text - editor.formatter.register('format', { - inline: 'b', - toggle: 0 - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].firstChild, 2); - editor.selection.setRng(rng); - editor.formatter.toggle('format'); - equal(getContent(), '1234
'); -}); - -test('Toggle OFF - Inline element on partially selected text in start/end elements', function() { - // Toggle OFF - Inline element on partially selected text in start/end elements - editor.formatter.register('format', { - inline: 'b', - toggle: false - }); - editor.getBody().innerHTML = '1234
1234
'; //'1234
1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[1].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.toggle('format'); - equal(getContent(), '1234
1234
'); -}); - -test('Toggle OFF - Inline element with data attribute', function() { - editor.formatter.register('format', {inline: 'b'}); - editor.getBody().innerHTML = '1
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].firstChild, 1); - editor.selection.setRng(rng); - editor.formatter.toggle('format'); - equal(getContent(), '1
'); -}); - -test('Toggle ON - NO inline element on selected text', function() { - // Inline element on selected text - editor.formatter.register('format', { - inline: 'b', - toggle: true - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element on selected text'); - editor.formatter.toggle('format'); - equal(getContent(), '1234
', 'Toggle ON - NO inline element on selected text'); -}); - -test('Selection spanning from within format to outside format with toggle off', function() { - editor.formatter.register('format', { - inline: 'b', - toggle: false - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].lastChild, 2); - editor.selection.setRng(rng); - editor.formatter.toggle('format'); - equal(getContent(), '1234
', 'Extend formating if start of selection is already formatted'); -}); - -test('Inline element on partially selected text', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element on partially selected text'); - editor.formatter.toggle('format'); - equal(getContent(), '1234
', 'Toggle ON - NO inline element on partially selected text'); -}); - -test('Inline element on partially selected text in start/end elements', function() { - // Inline element on partially selected text in start/end elements - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234
1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 1); - rng.setEnd(editor.dom.select('p')[1].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
1234
'); -}); - -test('Inline element on selected element', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element on selected element'); -}); - -test('Inline element on multiple selected elements', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234
1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
1234
', 'Inline element on multiple selected elements'); -}); - -test('Inline element on multiple selected elements with various childnodes', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '123456789
123456789
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '123456789
123456789
', 'Inline element on multiple selected elements with various childnodes'); -}); - -test('Inline element with attributes', function() { - editor.formatter.register('format', { - inline: 'b', - attributes: { - title: 'value1', - id: 'value2' - } - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element with attributes'); -}); - -test('Inline element with styles', function() { - editor.formatter.register('format', { - inline: 'b', - styles: { - color: '#ff0000', - fontSize: '10px' - } - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element with styles'); -}); - -test('Inline element with attributes and styles', function() { - editor.formatter.register('format', { - inline: 'b', - attributes: { - title: 'value1', - id: 'value2' - }, - styles: { - color: '#ff0000', - fontSize: '10px' - } - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element with attributes and styles'); -}); - -test('Inline element with wrapable parents', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = 'x1234y
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'x1234y
', 'Inline element with wrapable parents'); -}); - -test('Inline element with redundant child', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element with redundant child'); -}); - -test('Inline element with redundant parent', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0].firstChild, 0); - rng.setEnd(editor.dom.select('em')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element with redundant parent'); -}); - -test('Inline element with redundant child of similar type 1', function() { - editor.formatter.register('format', [{ - inline: 'b' - }, { - inline: 'strong' - }]); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 3); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element with redundant child of similar type 1'); -}); - -test('Inline element with redundant child of similar type 2', function() { - editor.formatter.register('format', [{ - inline: 'b' - }, { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }]); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element with redundant child of similar type 2'); -}); - -test('Inline element with redundant children of similar types', function() { - editor.formatter.register('format', [{ - inline: 'b' - }, { - inline: 'strong' - }, { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }]); - editor.getBody().innerHTML = 'a12345678b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a12345678b
', 'Inline element with redundant children of similar types'); -}); - -test('Inline element with redundant parent 1', function() { - editor.formatter.register('format', [{ - inline: 'b' - }, { - inline: 'strong' - }]); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0].firstChild, 0); - rng.setEnd(editor.dom.select('em')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element with redundant parent 1'); -}); - -test('Inline element with redundant parent 2', function() { - editor.formatter.register('format', [{ - inline: 'b' - }, { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }]); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0].firstChild, 0); - rng.setEnd(editor.dom.select('em')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element with redundant parent 2'); -}); - -test('Inline element with redundant parents of similar types', function() { - editor.formatter.register('format', [{ - inline: 'b' - }, { - inline: 'strong' - }, { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }]); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0].firstChild, 0); - rng.setEnd(editor.dom.select('em')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element with redundant parents of similar types'); -}); - -test('Inline element merged with parent and child', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = 'a123456b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 1); - rng.setEnd(editor.dom.select('b')[0].lastChild, 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a123456b
', 'Inline element merged with parent and child'); -}); - -test('Inline element merged with child 1', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element merged with child 1'); -}); - -test('Inline element merged with child 2', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element merged with child 2'); -}); - -test('Inline element merged with child 3', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element merged with child 3'); -}); - -test('Inline element merged with child 3', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - fontWeight: 'bold' - }, - merge: true - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element merged with child 3'); -}); - -test('Inline element merged with child 4', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - color: '#00ff00' - } - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element merged with child 4'); -}); - -test('Inline element with attributes merged with child 1', function() { - editor.formatter.register('format', { - inline: 'font', - attributes: { - face: 'arial' - }, - merge: true - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element with attributes merged with child 1'); -}); - -test('Inline element with attributes merged with child 2', function() { - editor.formatter.register('format', { - inline: 'font', - attributes: { - size: '7' - } - }); - editor.getBody().innerHTML = 'a1234b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a1234b
', 'Inline element with attributes merged with child 2'); -}); - -test('Inline element merged with left sibling', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].lastChild, 0); - rng.setEnd(editor.dom.select('p')[0].lastChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '12345678
', 'Inline element merged with left sibling'); -}); - -test('Inline element merged with right sibling', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '12345678
'; - var 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.formatter.apply('format'); - equal(getContent(), '12345678
', 'Inline element merged with right sibling'); -}); - -test('Inline element merged with left and right siblings', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '123456
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].childNodes[1], 0); - rng.setEnd(editor.dom.select('p')[0].childNodes[1], 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '123456
', 'Inline element merged with left and right siblings'); -}); - -test('Inline element merged with data attributed left sibling', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].lastChild, 0); - rng.setEnd(editor.dom.select('p')[0].lastChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '12345678
', 'Inline element merged with left sibling'); -}); - -test('Don\'t merge siblings with whitespace between 1', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = 'a b
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].lastChild, 1); - rng.setEnd(editor.dom.select('p')[0].lastChild, 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'a b
', 'Don\'t merge siblings with whitespace between 1'); -}); - -test('Don\'t merge siblings with whitespace between 1', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = 'a b
'; - var 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.formatter.apply('format'); - equal(getContent(), 'a b
', 'Don\'t merge siblings with whitespace between 2'); -}); - -test('Inline element not merged in exact mode', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - color: '#00ff00' - }, - exact: true - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element not merged in exact mode'); -}); - -test('Inline element merged in exact mode', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - color: '#ff0000' - }, - exact: true - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Inline element merged in exact mode'); -}); - -test('Deep left branch', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234text1text2
5678
9012
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('ins')[0].firstChild, 1); - rng.setEnd(editor.dom.select('p')[2].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234text1text2
5678
9012
', 'Deep left branch'); -}); - -test('Deep right branch', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '9012
5678
1234text1text2
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('em')[3].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '9012
5678
1234text1text2
', 'Deep right branch'); -}); - -test('Full element text selection on two elements with a table in the middle', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.getBody().innerHTML = '1234
| 123 |
5678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[1].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
| 123 |
5678
', 'Full element text selection on two elements with a table in the middle'); -}); - -test('Inline element on selected text with variables', function() { - editor.formatter.register('format', { - inline: 'b', - styles: { - color: '%color' - }, - attributes: { - title: '%title' - } - }, { - color: '#ff0000', - title: 'title' - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format', { - color: '#ff0000', - title: 'title' - }); - equal(getContent(), '1234
', 'Inline element on selected text'); -}); - -test('Remove redundant children', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - fontFamily: 'arial' - } - }); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
', 'Remove redundant children'); -}); - -test('Inline element on selected text with function values', function() { - editor.formatter.register('format', { - inline: 'b', - styles: { - color: function(vars) { - return vars.color + '00ff'; - } - }, - attributes: { - title: function(vars) { - return vars.title + '2'; - } - } - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format', { - color: '#ff', - title: 'title' - }); - equal(getContent(), '1234
', 'Inline element on selected text with function values'); -}); - -test('Block element on selected text', function() { - editor.formatter.register('format', { - block: 'div' - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
5678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
5678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
5678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('h1')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '', 'Block element wrapper 1'); -}); - -test('Block element wrapper 2', function() { - editor.formatter.register('format', { - block: 'blockquote', - wrapper: 1 - }); - editor.getBody().innerHTML = '1234
5678
', 'Block element wrapper 2'); -}); - -test('Block element wrapper 3', function() { - editor.formatter.register('format', { - block: 'blockquote', - wrapper: 1 - }); - editor.getBody().innerHTML = '1234
', 'Block element wrapper 3'); -}); - -test('Apply format on single element that matches a selector 1', function() { - editor.formatter.register('format', { - selector: 'p', - attributes: { - title: 'test' - }, - styles: { - 'color': '#ff0000' - }, - classes: 'a b c' - }); - editor.getBody().innerHTML = '1234
1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Apply format on single element that matches a selector'); -}); - -test('Apply format on single element parent that matches a selector 2', function() { - editor.formatter.register('format', { - selector: 'div', - attributes: { - title: 'test' - }, - styles: { - 'color': '#ff0000' - }, - classes: 'a b c' - }); - editor.getBody().innerHTML = '1234
test
1234
1234
test
1234
1234
1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[1].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '1234
1234
', 'Apply format on multiple elements that matches a selector'); -}); - -test('Apply format on top of existing selector element', function() { - editor.formatter.register('format', { - selector: 'p', - attributes: { - title: 'test2' - }, - styles: { - 'color': '#00ff00' - }, - classes: 'a b c' - }); - editor.getBody().innerHTML = '1234
'; - var 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.formatter.apply('format'); - equal(getContent(), '1234
', 'Apply format on top of existing selector element'); -}); - -test('Format on single li that matches a selector', function() { - editor.formatter.register('format', { - inline: 'span', - selector: 'li', - attributes: { - title: 'test' - }, - styles: { - 'color': '#ff0000' - }, - classes: 'a b c' - }); - editor.getBody().innerHTML = 'test1 test2 test3 test4 test5 test6
'); - rng.setStart(editor.dom.select('strong')[0].firstChild, 6); - rng.setEnd(editor.dom.select('strong')[0].firstChild, 11); - editor.focus(); - editor.selection.setRng(rng); - editor.execCommand('Italic'); - equal(editor.getContent(), 'test1 test2 test3 test4 test5 test6
', 'Selected text should be bold.'); -}); - -test('Apply color format to links as well', function() { - editor.setContent('123abc456
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].lastChild, 3); - editor.selection.setRng(rng); - - editor.formatter.register('format', { - inline: 'span', - styles: { - color: '#FF0000' - }, - links: true - }); - editor.formatter.apply('format'); - - equal( - editor.getContent(), - '123abc456
', - 'Link should have it\'s own color.' - ); -}); - -test('Color on link element', function() { - editor.setContent('123abc456
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].lastChild, 3); - editor.selection.setRng(rng); - - editor.formatter.register('format', { - inline: 'span', - styles: { - color: '#FF0000' - }, - links: true - }); - editor.formatter.apply('format'); - - equal( - editor.getContent(), - '123abc456
', - 'Link should have it\'s own color.' - ); -}); - -test("Applying formats in lists", function() { - editor.setContent('test
'); - editor.execCommand('SelectAll'); - editor.formatter.apply('format'); - equal(editor.getContent(), 'test
', 'Coloring an underlined text should result in a colored underline'); -}); - -test('Underline colors 2', function() { - editor.formatter.register('format', { - inline: "span", - exact: true, - styles: { - 'textDecoration': 'underline' - } - }); - editor.setContent('test
'); - editor.execCommand('SelectAll'); - editor.formatter.apply('format'); - equal(editor.getContent(), 'test
', 'Underlining colored text should result in a colored underline'); -}); - -test('Underline colors 3', function() { - editor.formatter.register('format', { - inline: "span", - exact: true, - styles: { - 'textDecoration': 'underline' - } - }); - editor.setContent('This is some example text
'); - editor.execCommand('SelectAll'); - editor.formatter.apply('format'); - equal(editor.getContent(), 'This is some example text
', 'Underlining colored and underlined text should result in a colored underline'); -}); - -test('Underline colors 4', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - 'color': '#ff0000' - } - }); - editor.setContent('yellowredyellow
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[1].firstChild, 6); - rng.setEnd(editor.dom.select('span')[1].firstChild, 9); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), 'yellowredyellow
', - 'Coloring an colored underdlined text should result in newly colored underline' - ); -}); - -test('Underline colors 5', function() { - editor.formatter.register('format', { - inline: "span", - exact: true, - styles: { - 'textDecoration': 'underline' - } - }); - editor.setContent('This is some example text
This is some example text
This is some example text
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('strong')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[4].lastChild, 5); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(editor.getContent(), 'This is some example text
This is some example text
This is some example text
', 'Colored elements should be underlined when selection is across multiple paragraphs'); -}); - -test('Underline colors 6', function() { - editor.formatter.register('format', { - inline: 'span', - exact: true, - styles: { - 'color': '#ff0000' - } - }); - editor.setContent('This is some text.
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 8); - rng.setEnd(editor.dom.select('span')[0].firstChild, 12); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - editor.formatter.remove('format'); - equal(editor.getContent(), 'This is some text.
', 'Children nodes that are underlined should be removed if their parent nodes are underlined'); -}); - -test('Underline colors 7', function() { - editor.formatter.register('format', { - inline: 'span', - exact: true, - styles: { - 'color': '#ff0000' - } - }); - editor.setContent('This is some text.
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[1].firstChild, 0); - rng.setEnd(editor.dom.select('span')[1].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(editor.getContent(), 'This is some text.
', 'Children nodes that are underlined should be removed if their parent nodes are underlined'); -}); - -test('Caret format inside single block word', function() { - editor.setContent('abc
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 2, 'p', 2); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
'); -}); - -test('Caret format inside non-ascii single block word', function() { - editor.setContent('noël
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 2, 'p', 2); - editor.formatter.apply('format'); - equal(editor.getContent(), 'noël
'); -}); - -test('Caret format inside first block word', function() { - editor.setContent('abc 123
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 2, 'p', 2); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc 123
'); -}); - -test('Caret format inside last block word', function() { - editor.setContent('abc 123
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 5, 'p', 5); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc 123
'); -}); - -test('Caret format inside middle block word', function() { - editor.setContent('abc 123 456
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 5, 'p', 5); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc 123 456
'); -}); - -test('Caret format on word separated by non breaking space', function() { - editor.setContent('one two
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 1, 'p', 1); - editor.formatter.apply('format'); - equal(editor.getContent(), 'one\u00a0two
'); -}); - -test('Caret format inside single inline wrapped word', function() { - editor.setContent('abc 123 456
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('em', 1, 'em', 1); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc 123 456
'); -}); - -test('Caret format inside word before similar format', function() { - editor.setContent('abc 123 456
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 1, 'p', 1); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc 123 456
'); -}); - -test('Caret format inside last inline wrapped word', function() { - editor.setContent('abc abc 123 456
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('em', 5, 'em', 5); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc abc 123 456
'); -}); - -test('Caret format before text', function() { - editor.setContent('a
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 0, 'p', 0); - editor.formatter.apply('format'); - Utils.type('b'); - equal(editor.getContent(), 'ba
'); -}); - -test('Caret format after text', function() { - editor.setContent('a
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 1, 'p', 1); - editor.formatter.apply('format'); - Utils.type('b'); - equal(editor.getContent(), 'ab
'); -}); - -test('Caret format and no key press', function() { - editor.setContent('a
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 0, 'p', 0); - editor.formatter.apply('format'); - equal(editor.getContent(), 'a
'); -}); - -test('Caret format and arrow left', function() { - editor.setContent('a
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 0, 'p', 0); - editor.formatter.apply('format'); - Utils.type({ - keyCode: 37 - }); - equal(editor.getContent(), 'a
'); -}); - -test('Caret format and arrow right', function() { - editor.setContent('a
'); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('p', 0, 'p', 0); - editor.formatter.apply('format'); - Utils.type({ - keyCode: 39 - }); - equal(editor.getContent(), 'a
'); -}); - -test('Caret format and backspace', function() { - var rng; - - if (tinymce.isOpera) { - ok(true, "Skip Opera since faking backspace doesn't work."); - return; - } - - editor.formatter.register('format', { - inline: 'b' - }); - - editor.setContent('abc
'); - rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 3); - rng.setEnd(editor.dom.select('p')[0].firstChild, 3); - editor.selection.setRng(rng); - - editor.formatter.apply('format'); - Utils.type('\b'); - equal(editor.getContent(), 'ab
'); -}); - -test('Caret format on word in li with word in parent li before it', function() { - editor.setContent('a
'); - editor.formatter.register('format', { - inline: 'span', - selector: '*', - classes: 'test' - }); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.apply('format'); - equal(editor.getContent(), 'a
'); -}); - -test('format inline on contentEditable: false block', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.setContent('abc
def
'); - Utils.setSelection('p:nth-child(2)', 0, 'p:nth-child(2)', 3); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
def
', 'Text is not bold'); -}); - -test('format block on contentEditable: false block', function() { - editor.formatter.register('format', { - block: 'h1' - }); - editor.setContent('abc
def
'); - Utils.setSelection('p:nth-child(2)', 0, 'p:nth-child(2)', 3); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
def
', 'P is not h1'); -}); - -test('contentEditable: false on start and contentEditable: true on end', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.setContent('abc
def
ghi
'); - Utils.setSelection('p:nth-child(2)', 0, 'p:nth-child(3)', 3); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
def
ghi
', 'Text in last paragraph is bold'); -}); - -test('contentEditable: true on start and contentEditable: false on end', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.setContent('abc
def
'); - Utils.setSelection('p:nth-child(1)', 0, 'p:nth-child(2)', 3); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
def
', 'Text in first paragraph is bold'); -}); - -test('contentEditable: true inside contentEditable: false', function() { - editor.formatter.register('format', { - inline: 'b' - }); - editor.setContent('abc
def
'); - Utils.setSelection('span', 0, 'span', 3); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
def
', 'Text is bold'); -}); - -test('Del element wrapping blocks', function() { - editor.setContent('a
'); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.register('format', { - block: 'del', - wrapper: true - }); - editor.formatter.apply('format'); - equal(getContent(), 'a
a
'); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.register('format', { - block: 'del' - }); - editor.formatter.apply('format'); - equal(getContent(), 'a
'); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.register('format', { - inline: 'del' - }); - editor.formatter.apply('format'); - equal(getContent(), 'a
| a |
| a |
a' +
- '
| ' +
- '
a' +
- '
| ' +
- '
ab
'; - - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].lastChild, 1); - editor.selection.setRng(rng); - - editor.formatter.register('format', { - inline: 'span', - attributes: { - id: 'id' - } - }); - editor.formatter.apply('format'); - - equal(Utils.normalizeHtml(editor.getBody().innerHTML), 'ab
'); -}); - -test('Bug #5134 - TinyMCE removes formatting tags in the getContent', function() { - editor.setContent(''); - editor.formatter.register('format', { - inline: 'strong', - toggle: false - }); - editor.formatter.apply('format'); - equal(getContent(), '', 'empty TinyMCE'); - editor.selection.setContent('a'); - equal(getContent(), 'a', 'bold text inside TinyMCE'); -}); - -test('Bug #5134 - TinyMCE removes formatting tags in the getContent - typing', function() { - editor.setContent(''); - editor.formatter.register('format', { - inline: 'strong', - toggle: false - }); - editor.formatter.apply('format'); - equal(getContent(), '', 'empty TinyMCE'); - Utils.type('a'); - equal(getContent(), 'a', 'bold text inside TinyMCE'); -}); - -test('Bug #5453 - TD contents with BR gets wrapped in block format', function() { - editor.setContent('| abc 123 |
abc123 |
abc
'); - Utils.setSelection('p', 2, 'p', 3); - editor.formatter.apply('format'); - Utils.setSelection('p', 1, 'p', 2); - editor.formatter.apply('format'); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.apply('format'); - equal(editor.getContent(), 'abc
'); -}); - -asyncTest('Bug #6518 - Apply div blocks to inline editor paragraph', function() { - tinymce.init({ - selector: "#elm2", - inline: true, - add_unload_trigger: false, - skin: false, - indent: false, - convert_fonts_to_spans: false, - disable_nodechange: true, - entities: 'raw', - 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,display,text-align' - }, - init_instance_callback: function(ed) { - QUnit.start(); - - ed.setContent('a
b
'); - ed.selection.select(ed.getBody().firstChild, true); - ed.selection.collapse(true); - ed.formatter.register('format', { - block: 'div' - }); - ed.formatter.apply('format'); - equal(ed.getContent(), 'b
'); - } - }); -}); - -asyncTest('Bug #7412 - valid_styles affects the Bold and Italic buttons, although it shouldn\'t', function() { - tinymce.init({ - selector: "#elm3", - add_unload_trigger: false, - valid_styles: { - span: 'color,background-color,font-size,text-decoration,padding-left' - }, - init_instance_callback: function(ed) { - QUnit.start(); - - ed.getBody().innerHTML = '1 1234 1
'; - var rng = ed.dom.createRng(); - rng.setStart(ed.dom.select('span')[0], 0); - rng.setEnd(ed.dom.select('span')[0], 1); - ed.selection.setRng(rng); - ed.formatter.toggle('bold'); - equal(ed.getContent(), '1 1234 1
'); - } - }); -}); - -test('Format selection from with end at beginning of block', function(){ - editor.setContent("abcd
"); - Utils.setSelection('strong', 1, 'em', 0); - editor.formatter.apply('underline'); - equal(getContent(), 'abcd
'); -}); - -test("Wrapper with fontSize should retain priority within a branch of nested inline format wrappers", function() { - editor.setContent("abc
"); - Utils.setSelection('p', 0, 'p', 3); - - editor.formatter.apply('fontsize', {value: '18px'}); - editor.formatter.apply('bold'); - editor.formatter.apply('underline'); - editor.formatter.apply('forecolor', {value: '#ff0000'}); - - equal(getContent(), 'abc
'); -}); - -test("Child wrapper having the same format as the immediate parent, shouldn't be removed if it also has other formats merged", function() { - editor.getBody().innerHTML = 'a bc
'; - Utils.setSelection('span span', 0, 'span span', 1); - editor.formatter.apply('fontname', {value: "verdana"}); - equal(getContent(), 'a bc
'); -}); - -test("When format with backgroundColor is applied, all the nested childNodes having fontSize should receive backgroundColor as well", function() { - editor.getBody().innerHTML = 'a b c
'; - editor.selection.select(editor.dom.select('p')[0]); - - editor.formatter.apply('hilitecolor', {value: "#ff0000"}); - equal(getContent(), 'a b c
'); - - editor.formatter.remove('hilitecolor', {value: "#ff0000"}); - equal(getContent(), 'a b c
'); -}); - -test("TINY-782: Can't apply sub/sup to word on own line with large font", function() { - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('span', 0, 'span', 3); - editor.formatter.apply('superscript'); - equal(getContent(), 'abc
'); -}); - -test("TINY-671: Background color on nested font size bug", function() { - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('span', 0, 'span', 3); - editor.formatter.apply('hilitecolor', {value: '#ff0000'}); - equal(getContent(), 'abc
'); -}); - -test("TINY-865: Font size removed when changing background color", function() { - editor.getBody().innerHTML = 'a b c
'; - Utils.setSelection('span span:nth-child(2)', 0, 'span span:nth-child(2)', 1); - editor.formatter.apply('hilitecolor', {value: '#ff0000'}); - equal(getContent(), 'a b c
'); -}); - -test("TINY-935: Text color, then size, then change color wraps span doesn't change color", function() { - editor.getBody().innerHTML = 'text
'; - Utils.setSelection('span', 0, 'span', 4); - editor.formatter.apply('forecolor', {value: '#ff0000'}); - equal(getContent(), 'text
'); -}); - -test("GH-3519: Font family selection does not work after changing font size", function() { - editor.getBody().innerHTML = 'text
'; - Utils.setSelection('span', 0, 'span', 4); - editor.formatter.apply('fontname', {value: "verdana"}); - equal(getContent(), 'text
'); -}); diff --git a/tests/qunit/editor/tinymce/Formatter_check.js b/tests/qunit/editor/tinymce/Formatter_check.js deleted file mode 100644 index eb54b50377..0000000000 --- a/tests/qunit/editor/tinymce/Formatter_check.js +++ /dev/null @@ -1,230 +0,0 @@ -module("tinymce.Formatter - Check", { - setupModule: function() { - document.getElementById('view').innerHTML = ''; - QUnit.stop(); - - tinymce.init({ - selector: "#elm1", - add_unload_trigger: false, - extended_valid_elements: 'b,i,span[style|contenteditable]', - skin: false, - entities: 'raw', - 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,display' - }, - init_instance_callback: function(ed) { - window.editor = ed; - - if (window.inlineEditor) { - QUnit.start(); - } - } - }); - - tinymce.init({ - selector: "#elm2", - inline: true, - add_unload_trigger: false, - indent: false, - skin: false, - convert_fonts_to_spans: false, - disable_nodechange: true, - entities: 'raw', - 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,display' - }, - init_instance_callback: function(ed) { - window.inlineEditor = ed; - - if (window.editor) { - QUnit.start(); - } - } - }); - } -}); - -test('Selected style element text', function() { - editor.formatter.register('bold', {inline: 'b'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('bold'), 'Selected style element text'); -}); - -test('Selected style element with css styles', function() { - editor.formatter.register('color', {inline: 'span', styles: {color: '#ff0000'}}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('color'), 'Selected style element with css styles'); -}); - -test('Selected style element with attributes', function() { - editor.formatter.register('fontsize', {inline: 'font', attributes: {size: '7'}}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('font')[0].firstChild, 0); - rng.setEnd(editor.dom.select('font')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('fontsize'), 'Selected style element with attributes'); -}); - -test('Selected style element text multiple formats', function() { - editor.formatter.register('multiple', [ - {inline: 'b'}, - {inline: 'strong'} - ]); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('strong')[0].firstChild, 0); - rng.setEnd(editor.dom.select('strong')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('multiple'), 'Selected style element text multiple formats'); -}); - -test('Selected complex style element', function() { - editor.formatter.register('complex', {inline: 'span', styles: {fontWeight: 'bold'}}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('complex'), 'Selected complex style element'); -}); - -test('Selected non style element text', function() { - editor.formatter.register('bold', {inline: 'b'}); - editor.getBody().innerHTML = '1234
'; - var 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); - ok(!editor.formatter.match('bold'), 'Selected non style element text'); -}); - -test('Selected partial style element (start)', function() { - editor.formatter.register('bold', {inline: 'b'}); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].lastChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('bold'), 'Selected partial style element (start)'); -}); - -test('Selected partial style element (end)', function() { - editor.formatter.register('bold', {inline: 'b'}); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].lastChild, 4); - editor.selection.setRng(rng); - ok(!editor.formatter.match('bold'), 'Selected partial style element (end)'); -}); - -test('Selected element text with parent inline element', function() { - editor.formatter.register('bold', {inline: 'b'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('bold'), 'Selected element text with parent inline element'); -}); - -test('Selected element match with variable', function() { - editor.formatter.register('complex', {inline: 'span', styles: {color: '%color'}}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('complex', {color: '#ff0000'}), 'Selected element match with variable'); -}); - -test('Selected element match with variable and function', function() { - editor.formatter.register('complex', { - inline: 'span', - styles: { - color: function(vars) { - return vars.color + '00'; - } - } - }); - - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 0); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - ok(editor.formatter.match('complex', {color: '#ff00'}), 'Selected element match with variable and function'); -}); - -test('formatChanged simple format', function() { - var newState, newArgs; - - editor.formatter.formatChanged('bold', function(state, args) { - newState = state; - newArgs = args; - }); - - editor.getBody().innerHTML = 'text
'; - Utils.setSelection('p', 0, 'p', 4); - - // Check apply - editor.formatter.apply('bold'); - editor.nodeChanged(); - ok(newState); - equal(newArgs.format, 'bold'); - equal(newArgs.node, editor.getBody().firstChild.firstChild); - equal(newArgs.parents.length, 2); - - // Check remove - editor.formatter.remove('bold'); - editor.nodeChanged(); - ok(!newState); - equal(newArgs.format, 'bold'); - equal(newArgs.node, editor.getBody().firstChild); - equal(newArgs.parents.length, 1); -}); - -test('formatChanged complex format', function() { - var newState, newArgs; - - editor.formatter.register('complex', {inline: 'span', styles: {color: '%color'}}); - - editor.formatter.formatChanged('complex', function(state, args) { - newState = state; - newArgs = args; - }, true); - - editor.getBody().innerHTML = 'text
'; - Utils.setSelection('p', 0, 'p', 4); - - // Check apply - editor.formatter.apply('complex', {color: '#FF0000'}); - editor.nodeChanged(); - ok(newState); - equal(newArgs.format, 'complex'); - equal(newArgs.node, editor.getBody().firstChild.firstChild); - equal(newArgs.parents.length, 2); - - // Check remove - editor.formatter.remove('complex', {color: '#FF0000'}); - editor.nodeChanged(); - ok(!newState); - equal(newArgs.format, 'complex'); - equal(newArgs.node, editor.getBody().firstChild); - equal(newArgs.parents.length, 1); -}); - -test('Match format on div block in inline mode', function() { - inlineEditor.setContent('a
b
'); - inlineEditor.execCommand('SelectAll'); - ok(!inlineEditor.formatter.match('div'), 'Formatter.match on div says true'); -}); diff --git a/tests/qunit/editor/tinymce/Formatter_remove.js b/tests/qunit/editor/tinymce/Formatter_remove.js deleted file mode 100644 index a1e0da30ad..0000000000 --- a/tests/qunit/editor/tinymce/Formatter_remove.js +++ /dev/null @@ -1,415 +0,0 @@ -module("tinymce.Formatter - Remove", { - setupModule: function() { - document.getElementById('view').innerHTML = ''; - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - external_plugins: { noneditable: '../../../../tests/qunit/editor/external-plugins/noneditable/plugin.min.js' }, // WP - indent: false, - add_unload_trigger: false, - skin: false, - extended_valid_elements: 'b,i,span[style|contenteditable]', - entities: 'raw', - 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,display' - }, - disable_nodechange: true, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - } -}); - -function getContent() { - return editor.getContent().toLowerCase().replace(/[\r]+/g, ''); -} - -test('Inline element on selected text', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Inline element on selected text'); -}); - -test('Inline element on selected text with remove=all', function() { - editor.formatter.register('format', {selector : 'b', remove : 'all'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Inline element on selected text with remove=all'); -}); - -test('Inline element on selected text with remove=none', function() { - editor.formatter.register('format', {selector : 'span', styles : {fontWeight : 'bold'}, remove : 'none'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 1); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Inline element on selected text with remove=none'); -}); - -test('Inline element style where element is format root', function() { - editor.formatter.register('format', {inline : 'span', styles : {fontWeight : 'bold'}}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0].firstChild, 1); - rng.setEnd(editor.dom.select('em')[0].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), - '' + - '123' + - '4' + - '
', - 'Inline element style where element is format root'); -}); - -test('Partially selected inline element text', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 2); - rng.setEnd(editor.dom.select('b')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Partially selected inline element text'); -}); - -test('Partially selected inline element text with children', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[0].firstChild, 2); - rng.setEnd(editor.dom.select('span')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Partially selected inline element text with children'); -}); - -test('Partially selected inline element text with complex children', function() { - editor.formatter.register('format', {inline : 'span', styles : {fontWeight : 'bold'}}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('span')[1].firstChild, 2); - rng.setEnd(editor.dom.select('span')[1].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Partially selected inline element text with complex children'); -}); - -test('Inline elements with exact flag', function() { - editor.formatter.register('format', {inline : 'span', styles : {color : '#ff0000'}, exact : true}); - editor.getBody().innerHTML = '12341234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 2); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '12341234
', 'Inline elements with exact flag'); -}); - -test('Inline elements with variables', function() { - editor.formatter.register('format', {inline : 'span', styles : {color : '%color'}, exact : true}); - editor.getBody().innerHTML = '12341234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 2); - editor.selection.setRng(rng); - editor.formatter.remove('format', {color : '#ff0000'}); - equal(getContent(), '12341234
', 'Inline elements on selected text with variables'); -}); - -test('Inline elements with functions and variables', function() { - editor.formatter.register('format', { - inline : 'span', - styles : { - color : function(vars) { - return vars.color + "00"; - } - }, - exact : true - }); - - editor.getBody().innerHTML = '12341234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('p')[0], 2); - editor.selection.setRng(rng); - editor.formatter.remove('format', { - color : '#ff00' - }); - equal(getContent(), '12341234
', 'Inline elements with functions and variables'); -}); - -test('End within start element', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('b')[0], 2); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '12345678
', 'End within start element'); -}); - -test('Start and end within similar format 1', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0], 0); - rng.setEnd(editor.dom.select('b')[1], 2); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '12345678
', 'Start and end within similar format 1'); -}); - -test('Start and end within similar format 2', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '12345678
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0], 0); - rng.setEnd(editor.dom.select('em')[0], 1); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '12345678
', 'Start and end within similar format 2'); -}); - -test('Start and end within similar format 3', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = '1234
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0], 0); - rng.setEnd(editor.dom.select('em')[0], 1); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '1234
', 'Start and end within similar format 3'); -}); - -test('End within start', function() { - editor.formatter.register('format', {inline : 'b'}); - editor.getBody().innerHTML = 'xabcy
'; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0], 0); - rng.setEnd(editor.dom.select('b')[1].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), 'xabcy
', 'End within start'); -}); - -test('Remove block format', function() { - editor.formatter.register('format', {block : 'h1'}); - editor.getBody().innerHTML = 'text
', 'Remove block format'); -}); - -test('Remove wrapper block format', function() { - editor.formatter.register('format', {block : 'blockquote', wrapper : true}); - editor.getBody().innerHTML = ''; - var 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.formatter.remove('format'); - equal(getContent(), 'text
text
', 'Remove wrapper block format'); -}); - -test('Remove span format within block with style', function() { - editor.formatter.register('format', {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true}); - var rng = editor.dom.createRng(); - editor.getBody().innerHTML = 'text
'; - rng.setStart(editor.dom.select('span')[0].firstChild, 1); - rng.setEnd(editor.dom.select('span')[0].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), 'text
', 'Remove span format within block with style'); -}); - -test('Remove and verify start element', function() { - editor.formatter.register('format', {inline : 'b'}); - var rng = editor.dom.createRng(); - editor.getBody().innerHTML = 'text
'; - rng.setStart(editor.dom.select('b')[0].firstChild, 1); - rng.setEnd(editor.dom.select('b')[0].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), 'text
'); - equal(editor.selection.getStart().nodeName, 'P'); -}); - -test('Remove with selection collapsed ensure correct caret position', function() { - var content = 'test
testing
'; - - editor.formatter.register('format', {block : 'p'}); - var rng = editor.dom.createRng(); - editor.getBody().innerHTML = content; - rng.setStart(editor.dom.select('p')[0].firstChild, 4); - rng.setEnd(editor.dom.select('p')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), content); - equal(editor.selection.getStart(), editor.dom.select('p')[0]); -}); - -test('Caret format at middle of text', function() { - editor.setContent('abc
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('b', 1, 'b', 1); - editor.formatter.remove('format'); - equal(editor.getContent(), 'abc
'); -}); - -test('Caret format at end of text', function() { - editor.setContent('abc
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('b', 3, 'b', 3); - editor.formatter.remove('format'); - Utils.type('d'); - equal(editor.getContent(), 'abcd
'); -}); - -test('Caret format at end of text inside other format', function() { - editor.setContent('abc
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('b', 3, 'b', 3); - editor.formatter.remove('format'); - Utils.type('d'); - equal(editor.getContent(), 'abcd
'); -}); - -test('Caret format at end of text inside other format with text after 1', function() { - editor.setContent('abce
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('b', 3, 'b', 3); - editor.formatter.remove('format'); - Utils.type('d'); - equal(editor.getContent(), 'abcde
'); -}); - -test('Caret format at end of text inside other format with text after 2', function() { - editor.setContent('abce
'); - editor.formatter.register('format', {inline: 'em'}); - Utils.setSelection('b', 3, 'b', 3); - editor.formatter.remove('format'); - Utils.type('d'); - equal(editor.getContent(), 'abcde
'); -}); - -test('Toggle styles at the end of the content don\' removes the format where it is not needed.', function() { - editor.setContent('abce
'); - editor.formatter.register('b', {inline: 'b'}); - editor.formatter.register('em', {inline: 'em'}); - Utils.setSelection('b', 4, 'b', 4); - editor.formatter.remove('b'); - editor.formatter.remove('em'); - equal(editor.getContent(), 'abce
'); -}); - -test('Caret format on second word in table cell', function() { - editor.setContent('| one two |
| one two |
abc
def
ghj
'); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('b')[0].firstChild, 0); - rng.setEnd(editor.dom.select('b')[1].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(editor.getContent(), 'abc
def
ghj
', 'Text in last paragraph is not bold'); -}); - -test('contentEditable: true on start and contentEditable: false on end', function() { - editor.formatter.register('format', {inline: 'b'}); - editor.setContent('abc
def
ghj
'); - Utils.setSelection('p:nth-child(2) b', 0, 'p:last b', 3); - editor.formatter.remove('format'); - equal(editor.getContent(), 'abc
def
ghj
', 'Text in first paragraph is not bold'); -}); - -test('contentEditable: true inside contentEditable: false', function() { - editor.formatter.register('format', {inline: 'b'}); - editor.setContent('abc
def
'); - Utils.setSelection('b', 0, 'b', 3); - editor.formatter.remove('format'); - equal(editor.getContent(), 'abc
def
', 'Text is not bold'); -}); - -test('remove format block on contentEditable: false block', function() { - editor.formatter.register('format', {block: 'h1'}); - editor.setContent('abc
abc
abc
abc
'); -}); - -test('remove format on span with class using removeformat format', function() { - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('span', 0, 'span', 3); - editor.formatter.remove('removeformat'); - equal(Utils.cleanHtml(editor.getBody().innerHTML), 'abc
'); -}); - -test('remove format on span with internal class using removeformat format', function() { - editor.getBody().innerHTML = 'abc
'; - Utils.setSelection('span', 0, 'span', 3); - editor.formatter.remove('removeformat'); - equal(Utils.normalizeHtml(Utils.cleanHtml(editor.getBody().innerHTML)), 'abc
'); -}); - -test('Remove format bug 1', function() { - editor.setContent('abc
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('i', 1, 'i', 2); - editor.formatter.remove('format'); - equal(editor.getContent(), 'abc
'); -}); - -test('Remove format bug 2', function() { - editor.setContent('abc
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('b', 0, 'b', 1); - editor.formatter.remove('format'); - equal(editor.getContent(), 'abc
'); -}); - -test('Remove format bug 3', function() { - editor.setContent('ab
'); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('i', 1, 'i', 2); - editor.formatter.remove('format'); - equal(editor.getContent(), 'ab
'); -}); diff --git a/tests/qunit/editor/tinymce/InsertContent.js b/tests/qunit/editor/tinymce/InsertContent.js deleted file mode 100644 index 765cfdbce6..0000000000 --- a/tests/qunit/editor/tinymce/InsertContent.js +++ /dev/null @@ -1,110 +0,0 @@ -ModuleLoader.require([ - "tinymce/InsertContent" -], function(InsertContent) { - module("tinymce.InsertContent", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - entities: 'raw', - indent: false, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - } - }); - - function assertSelection(selector, offset) { - var node = editor.$(selector)[0]; - var rng = editor.selection.getRng(); - - equal(rng.startContainer, node.firstChild); - equal(rng.startOffset, offset); - equal(rng.collapsed, true); - } - - test('insertAtCaret - i inside text, converts to em', function() { - editor.setContent('1234
'); - editor.focus(); - Utils.setSelection('p', 2); - InsertContent.insertAtCaret(editor, 'a'); - equal(editor.getContent(), '12a34
'); - }); - - test('insertAtCaret - ul at beginning of li', function() { - editor.setContent('a123bc
'); - }); -}); diff --git a/tests/qunit/editor/tinymce/InsertContentForcedRootFalse.js b/tests/qunit/editor/tinymce/InsertContentForcedRootFalse.js deleted file mode 100644 index ab81d6ccaa..0000000000 --- a/tests/qunit/editor/tinymce/InsertContentForcedRootFalse.js +++ /dev/null @@ -1,47 +0,0 @@ -ModuleLoader.require([ - "tinymce/InsertContent" -], function(InsertContent) { - module("tinymce.InsertContentForcedRootFalse", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - entities: 'raw', - indent: false, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - }, - forced_root_block: false - }); - } - }); - - var trimBrs = function(string) { - return string.replace(/abc'); - - Utils.setSelection('pre', 1); - arrow(); - equal(editor.getContent(), '
abc'); - equal(editor.selection.getNode().nodeName, 'PRE'); - - Utils.setSelection('pre', offset); - arrow(); - equal(editor.getContent(), expectedContent); - equal(editor.selection.getNode().nodeName, 'P'); - }; - } - - function assertCaretInCaretBlockContainer() { - var beforeRng = editor.selection.getRng(); - equal(CaretContainer.isCaretContainerBlock(beforeRng.startContainer), true, 'Not in caret block container.'); - } - - var leftArrow = pressKey(VK.LEFT); - var rightArrow = pressKey(VK.RIGHT); - var backspace = pressKey(VK.BACKSPACE); - var forwardDelete = pressKey(VK.DELETE); - var upArrow = pressKey(VK.UP); - var downArrow = pressKey(VK.DOWN); - - test('left/right over cE=false inline', function() { - editor.setContent('1'); - editor.selection.select(editor.$('span')[0]); - - leftArrow(); - equal(editor.getContent(), '
1
'); - equal(CaretContainer.isCaretContainerInline(editor.selection.getRng().startContainer), true); - equal(editor.selection.getRng().startContainer, editor.$('p')[0].firstChild); - - rightArrow(); - equal(editor.getContent(), '1
'); - equal(editor.selection.getNode(), editor.$('span')[0]); - - rightArrow(); - equal(editor.getContent(), '1
'); - equal(CaretContainer.isCaretContainerInline(editor.selection.getRng().startContainer), true); - equal(editor.selection.getRng().startContainer, editor.$('p')[0].lastChild); - }); - - test('left/right over cE=false block', function() { - editor.setContent('1
'); - editor.selection.select(editor.$('p')[0]); - - leftArrow(); - equal(editor.getContent(), '1
'); - equal(CaretContainer.isCaretContainerBlock(editor.selection.getRng().startContainer), true); - - rightArrow(); - equal(editor.getContent(), '1
'); - equal(editor.selection.getNode(), editor.$('p')[0]); - - rightArrow(); - equal(editor.getContent(), '1
'); - equal(CaretContainer.isCaretContainerBlock(editor.selection.getRng().startContainer), true); - }); - - test('left before cE=false block and type', function() { - editor.setContent('1
'); - editor.selection.select(editor.$('p')[0]); - - leftArrow(); - Utils.type('a'); - equal(editor.getContent(), 'a
1
'); - equal(CaretContainer.isCaretContainerBlock(editor.selection.getRng().startContainer.parentNode), false); - }); - - test('right after cE=false block and type', function() { - editor.setContent('1
'); - editor.selection.select(editor.$('p')[0]); - - rightArrow(); - Utils.type('a'); - equal(editor.getContent(), '1
a
'); - equal(CaretContainer.isCaretContainerBlock(editor.selection.getRng().startContainer.parentNode), false); - }); - - test('up from P to inline cE=false', function() { - editor.setContent('a1
abc
'); - Utils.setSelection('p:last', 3); - - upArrow(); - equal(CaretContainer.isCaretContainerInline(editor.$('p:first')[0].lastChild), true); - }); - - test('down from P to inline cE=false', function() { - editor.setContent('abc
a1
'); - Utils.setSelection('p:first', 3); - - downArrow(); - equal(CaretContainer.isCaretContainerInline(editor.$('p:last')[0].lastChild), true); - }); - - test('backspace on selected cE=false block', function() { - editor.setContent('1
'); - editor.selection.select(editor.$('p')[0]); - - backspace(); - equal(editor.getContent(), ''); - equal(editor.selection.getRng().startContainer, editor.$('p')[0]); - }); - - test('backspace after cE=false block', function() { - editor.setContent('1
'); - editor.selection.select(editor.$('p')[0]); - - rightArrow(); - backspace(); - equal(editor.getContent(), ''); - equal(editor.selection.getRng().startContainer, editor.$('p')[0]); - }); - - test('delete on selected cE=false block', function() { - editor.setContent('1
'); - editor.selection.select(editor.$('p')[0]); - - forwardDelete(); - equal(editor.getContent(), ''); - equal(editor.selection.getRng().startContainer, editor.$('p')[0]); - }); - - test('delete inside nested cE=true block element', function() { - editor.setContent('12
3
'); - Utils.setSelection('p:nth-child(2)', 0); - - Utils.type('\b'); - equal(editor.getContent(), '123
'); - ok(Zwsp.isZwsp(editor.selection.getRng().startContainer.data)); - equal(editor.selection.getRng().startContainer.previousSibling.nodeName, 'SPAN'); - }); - - test('delete from block to before cE=false inline', function() { - editor.setContent('1
23
'); - Utils.setSelection('p:nth-child(1)', 1); - - forwardDelete(); - equal(editor.getContent(), '123
'); - ok(Zwsp.isZwsp(editor.selection.getRng().startContainer.data)); - equal(editor.selection.getRng().startContainer.nextSibling.nodeName, 'SPAN'); - }); - - test('backspace from before cE=false block to text', function() { - editor.setContent('1
2
3
'); - editor.selection.select(editor.dom.select('p')[1]); - editor.selection.collapse(true); - assertCaretInCaretBlockContainer(); - - Utils.type('\b'); - var rng = editor.selection.getRng(); - - equal(editor.getContent(), '1
2
3
'); - equal(rng.startContainer, editor.dom.select('p')[0].firstChild); - equal(rng.startOffset, 1); - equal(rng.collapsed, true); - }); - - test('backspace from before first cE=false block', function() { - editor.setContent('1
2
'); - editor.selection.select(editor.dom.select('p')[0]); - editor.selection.collapse(true); - assertCaretInCaretBlockContainer(); - - Utils.type('\b'); - - equal(editor.getContent(), '1
2
'); - assertCaretInCaretBlockContainer(); - }); - - test('backspace from before cE=false block to after cE=false block', function() { - editor.setContent('1
2
'); - editor.selection.select(editor.dom.select('p')[1]); - editor.selection.collapse(true); - assertCaretInCaretBlockContainer(); - - Utils.type('\b'); - var rng = editor.selection.getRng(); - - equal(editor.getContent(), '1
2
'); - assertCaretInCaretBlockContainer(); - equal(rng.startContainer.previousSibling, editor.dom.select('p')[0]); - }); - - test('delete from after cE=false block to text', function() { - editor.setContent('1
2
3
'); - editor.selection.select(editor.dom.select('p')[1]); - editor.selection.collapse(false); - assertCaretInCaretBlockContainer(); - - forwardDelete(); - var rng = editor.selection.getRng(); - - equal(editor.getContent(), '1
2
3
'); - equal(rng.startContainer, editor.dom.select('p')[2].firstChild); - equal(rng.startOffset, 0); - equal(rng.collapsed, true); - }); - - test('delete from after last cE=false block', function() { - editor.setContent('1
2
'); - editor.selection.select(editor.dom.select('p')[1]); - editor.selection.collapse(false); - assertCaretInCaretBlockContainer(); - forwardDelete(); - equal(editor.getContent(), '1
2
'); - assertCaretInCaretBlockContainer(); - }); - - test('delete from after cE=false block to before cE=false block', function() { - editor.setContent('1
2
'); - editor.selection.select(editor.dom.select('p')[0]); - rightArrow(); - assertCaretInCaretBlockContainer(); - - forwardDelete(); - var rng = editor.selection.getRng(); - - equal(editor.getContent(), '1
2
'); - assertCaretInCaretBlockContainer(); - equal(rng.startContainer.nextSibling, editor.dom.select('p')[2]); - }); - - test('delete from block to before cE=false inline', function() { - editor.setContent('1
23
'); - Utils.setSelection('p:nth-child(1)', 1); - - forwardDelete(); - equal(editor.getContent(), '123
'); - ok(Zwsp.isZwsp(editor.selection.getRng().startContainer.data)); - equal(editor.selection.getRng().startContainer.nextSibling.nodeName, 'SPAN'); - }); - - test('backspace from empty block to after cE=false', function() { - editor.getBody().innerHTML = '1
1
'); - assertCaretInCaretBlockContainer(); - }); - - test('delete from empty block to before cE=false', function() { - editor.getBody().innerHTML = '2
'; - Utils.setSelection('p:nth-child(1)', 0); - - forwardDelete(); - equal(editor.getContent(), '2
'); - assertCaretInCaretBlockContainer(); - }); - - test('exit pre block (up)', exitPreTest(upArrow, 0, '\u00a0
abc')); - test('exit pre block (left)', exitPreTest(leftArrow, 0, '
\u00a0
abc')); - test('exit pre block (down)', exitPreTest(downArrow, 3, '
abc
\u00a0
')); - test('exit pre block (right)', exitPreTest(rightArrow, 3, 'abc
\u00a0
')); - - test('click on link in cE=false', function() { - editor.setContent(''); - var evt = editor.fire('click', {target: editor.$('strong')[0]}); - - equal(evt.isDefaultPrevented(), true); - }); - - test('click next to cE=false block', function() { - editor.setContent( - '| 1 | ' + - '2 | ' +
- '
| 1 | 2 |
abc
'); - Utils.setSelection('p', 0); - editor.undoManager.add(); - - editor.undoManager.extra(function() { - Utils.setSelection('p', 1, 'p', 2); - editor.insertContent('1'); - }, function () { - Utils.setSelection('p', 1, 'p', 2); - editor.insertContent('2'); - }); - - data = editor.undoManager.data; - equal(data.length, 3); - equal(data[0].content, 'abc
'); - deepEqual(data[0].bookmark, {start: [0, 0, 0]}); - deepEqual(data[0].beforeBookmark, {start: [0, 0, 0]}); - equal(data[1].content, 'a1c
'); - deepEqual(data[1].bookmark, {start: [2, 0, 0]}); - deepEqual(data[1].beforeBookmark, {start: [2, 0, 0]}); - equal(data[2].content, 'a2c
'); - deepEqual(data[2].bookmark, {start: [2, 0, 0]}); - deepEqual(data[1].beforeBookmark, data[2].bookmark); -}); - -test('Exclude internal elements', function() { - var count = 0, lastLevel; - - editor.undoManager.clear(); - equal(count, 0); - - editor.on('AddUndo', function() { - count++; - }); - - editor.on('BeforeAddUndo', function(e) { - lastLevel = e.level; - }); - - editor.getBody().innerHTML = ( - 'test' + - '| x |
| x |
| x |
| x |
some text
"); - Utils.setSelection('p', 4, 'p', 9); - Utils.type('\b'); - - equal(Utils.cleanHtml(lastLevel.content), "some text
"); - editor.fire('blur'); - equal(Utils.cleanHtml(lastLevel.content), "some
"); - - editor.execCommand('FormatBlock', false, 'h1'); - editor.undoManager.undo(); - equal(editor.getContent(), "some
"); -}); - -test('BeforeAddUndo event', function() { - var lastEvt, addUndoEvt; - - function blockEvent(e) { - e.preventDefault(); - } - - editor.on('BeforeAddUndo', function(e) { - lastEvt = e; - }); - - editor.undoManager.clear(); - editor.setContent("a
"); - editor.undoManager.add(); - - equal(lastEvt.lastLevel, null); - equal(Utils.cleanHtml(lastEvt.level.content), "a
"); - - editor.setContent("b
"); - editor.undoManager.add(); - - equal(Utils.cleanHtml(lastEvt.lastLevel.content), "a
"); - equal(Utils.cleanHtml(lastEvt.level.content), "b
"); - - editor.on('BeforeAddUndo', blockEvent); - - editor.on('AddUndo', function(e) { - addUndoEvt = e; - }); - - editor.setContent("c
"); - editor.undoManager.add(null, {data: 1}); - - equal(Utils.cleanHtml(lastEvt.lastLevel.content), "b
"); - equal(Utils.cleanHtml(lastEvt.level.content), "c
"); - equal(lastEvt.originalEvent.data, 1); - ok(!addUndoEvt, "Event level produced when it should be blocked"); - - editor.off('BeforeAddUndo', blockEvent); -}); - -test('Dirty state type letter', function() { - editor.undoManager.clear(); - editor.setDirty(false); - editor.setContent("a
"); - Utils.setSelection('p', 1); - - ok(!editor.isDirty(), "Dirty state should be false"); - Utils.type('b'); - equal(editor.getContent(), "ab
"); - ok(editor.isDirty(), "Dirty state should be true"); -}); - -test('Dirty state type shift+letter', function() { - editor.undoManager.clear(); - editor.setDirty(false); - editor.setContent("a
"); - Utils.setSelection('p', 1); - - ok(!editor.isDirty(), "Dirty state should be false"); - Utils.type({keyCode: 65, charCode: 66, shiftKey: true}); - equal(editor.getContent(), "aB
"); - ok(editor.isDirty(), "Dirty state should be true"); -}); - -test('Dirty state type AltGr+letter', function() { - editor.undoManager.clear(); - editor.setDirty(false); - editor.setContent("a
"); - Utils.setSelection('p', 1); - - ok(!editor.isDirty(), "Dirty state should be false"); - Utils.type({keyCode: 65, charCode: 66, ctrlKey: true, altKey: true}); - equal(editor.getContent(), "aB
"); - ok(editor.isDirty(), "Dirty state should be true"); -}); - -test('ExecCommand while typing should produce undo level', function() { - editor.undoManager.clear(); - editor.setDirty(false); - editor.setContent('a
'); - Utils.setSelection('p', 1); - - equal(editor.undoManager.typing, false); - Utils.type({keyCode: 66, charCode: 66}); - equal(editor.undoManager.typing, true); - equal(editor.getContent(), 'aB
'); - editor.execCommand('mceInsertContent', false, 'C'); - equal(editor.undoManager.typing, false); - equal(editor.undoManager.data.length, 3); - equal(editor.undoManager.data[0].content, 'a
'); - equal(editor.undoManager.data[1].content, 'aB
'); - equal(editor.undoManager.data[2].content, 'aBC
'); -}); - -test('transact while typing should produce undo level', function() { - editor.undoManager.clear(); - editor.setDirty(false); - editor.setContent('a
'); - Utils.setSelection('p', 1); - - equal(editor.undoManager.typing, false); - Utils.type({keyCode: 66, charCode: 66}); - equal(editor.undoManager.typing, true); - equal(editor.getContent(), 'aB
'); - editor.undoManager.transact(function () { - editor.getBody().firstChild.firstChild.data = 'aBC'; - }); - equal(editor.undoManager.typing, false); - equal(editor.undoManager.data.length, 3); - equal(editor.undoManager.data[0].content, 'a
'); - equal(editor.undoManager.data[1].content, 'aB
'); - equal(editor.undoManager.data[2].content, 'aBC
'); -}); diff --git a/tests/qunit/editor/tinymce/WindowManager.js b/tests/qunit/editor/tinymce/WindowManager.js deleted file mode 100644 index 5e8f3216cc..0000000000 --- a/tests/qunit/editor/tinymce/WindowManager.js +++ /dev/null @@ -1,41 +0,0 @@ -ModuleLoader.require([ -], function() { - module("tinymce.WindowManager", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - }, - - teardown: function() { - editor.off('CloseWindow OpenWindow'); - } - }); - - test('OpenWindow/CloseWindow events', function() { - var openWindowArgs, closeWindowArgs; - - editor.on('CloseWindow', function(e) { - closeWindowArgs = e; - }); - - editor.on('OpenWindow', function(e) { - openWindowArgs = e; - e.win.close(); - }); - - editor.windowManager.alert('test'); - - equal(openWindowArgs.type, 'openwindow'); - equal(closeWindowArgs.type, 'closewindow'); - equal(editor.windowManager.getWindows().length, 0); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/CaretBookmark.js b/tests/qunit/editor/tinymce/caret/CaretBookmark.js deleted file mode 100644 index f6065f5296..0000000000 --- a/tests/qunit/editor/tinymce/caret/CaretBookmark.js +++ /dev/null @@ -1,137 +0,0 @@ -ModuleLoader.require([ - 'tinymce/caret/CaretBookmark', - 'tinymce/caret/CaretPosition' -], function(CaretBookmark, CaretPosition) { - var assertCaretPosition = Utils.assertCaretPosition; - - module('tinymce.caret.CaretBookmark'); - - function getRoot() { - return document.getElementById('view'); - } - - function setupHtml(html) { - getRoot().innerHTML = html; - } - - function createTextPos(textNode, offset) { - return new CaretPosition(textNode, offset); - } - - test('create element index', function() { - setupHtml(''); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(getRoot().childNodes[0])), 'b[0],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(getRoot().childNodes[1])), 'i[0],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(getRoot().childNodes[2])), 'b[1],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.after(getRoot().childNodes[2])), 'b[1],after'); - }); - - test('create text index', function() { - setupHtml('abccc'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[0], 0)), 'text()[0],0'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[2], 1)), 'text()[1],1'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[4], 3)), 'text()[2],3'); - }); - - test('create text index on fragmented text nodes', function() { - setupHtml('a'); - getRoot().appendChild(document.createTextNode('b')); - getRoot().appendChild(document.createTextNode('c')); - getRoot().appendChild(document.createElement('b')); - getRoot().appendChild(document.createTextNode('d')); - getRoot().appendChild(document.createTextNode('e')); - - equal(getRoot().childNodes.length, 6); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[0], 0)), 'text()[0],0'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[1], 0)), 'text()[0],1'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[2], 0)), 'text()[0],2'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[4], 0)), 'text()[1],0'); - equal(CaretBookmark.create(getRoot(), createTextPos(getRoot().childNodes[5], 0)), 'text()[1],1'); - }); - - test('create br element index', function() { - setupHtml('a
'); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(document.getElementById('a'))), 'p[0]/span[1]/b[0],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(document.getElementById('b'))), 'p[0]/span[1]/b[1],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(document.getElementById('c'))), 'p[0]/span[1]/b[2],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.after(document.getElementById('c'))), 'p[0]/span[1]/b[2],after'); - }); - - test('create deep text index', function() { - setupHtml('aabccc
'); - equal(CaretBookmark.create(getRoot(), createTextPos(document.getElementById('x').childNodes[0], 0)), 'p[0]/span[1]/text()[0],0'); - equal(CaretBookmark.create(getRoot(), createTextPos(document.getElementById('x').childNodes[2], 1)), 'p[0]/span[1]/text()[1],1'); - equal(CaretBookmark.create(getRoot(), createTextPos(document.getElementById('x').childNodes[4], 3)), 'p[0]/span[1]/text()[2],3'); - }); - - test('create element index from bogus', function() { - setupHtml(''); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(getRoot().lastChild.lastChild.childNodes[1])), 'b[3],before'); - }); - - test('resolve element index', function() { - setupHtml(''); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'b[0],before'), CaretPosition.before(getRoot().childNodes[0])); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'b[1],before'), CaretPosition.before(getRoot().childNodes[2])); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'b[1],after'), CaretPosition.after(getRoot().childNodes[2])); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'i[0],before'), CaretPosition.before(getRoot().childNodes[1])); - }); - - test('resolve odd element names', function() { - setupHtml('a
'); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'p[0]/span[1]/b[0],before'), CaretPosition.before(document.getElementById('a'))); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'p[0]/span[1]/b[1],before'), CaretPosition.before(document.getElementById('b'))); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'p[0]/span[1]/b[2],before'), CaretPosition.before(document.getElementById('c'))); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'p[0]/span[1]/b[2],after'), CaretPosition.after(document.getElementById('c'))); - }); - - test('resolve text index', function() { - setupHtml('abccc'); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],0'), createTextPos(getRoot().childNodes[0], 0)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[1],1'), createTextPos(getRoot().childNodes[2], 1)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[2],3'), createTextPos(getRoot().childNodes[4], 3)); - }); - - test('resolve text index on fragmented text nodes', function() { - setupHtml('a'); - getRoot().appendChild(document.createTextNode('b')); - getRoot().appendChild(document.createTextNode('c')); - getRoot().appendChild(document.createElement('b')); - getRoot().appendChild(document.createTextNode('d')); - getRoot().appendChild(document.createTextNode('e')); - - equal(getRoot().childNodes.length, 6); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],0'), createTextPos(getRoot().childNodes[0], 0)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],1'), createTextPos(getRoot().childNodes[0], 1)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],2'), createTextPos(getRoot().childNodes[1], 1)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],3'), createTextPos(getRoot().childNodes[2], 1)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],4'), createTextPos(getRoot().childNodes[2], 1)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[1],0'), createTextPos(getRoot().childNodes[4], 0)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[1],1'), createTextPos(getRoot().childNodes[4], 1)); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[1],2'), createTextPos(getRoot().childNodes[5], 1)); - }); - - test('resolve text index with to high offset', function() { - setupHtml('abc'); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'text()[0],10'), createTextPos(getRoot().childNodes[0], 3)); - }); - - test('resolve invalid paths', function() { - setupHtml(''); - equal(CaretBookmark.resolve(getRoot(), 'x[0]/y[1]/z[2]'), null); - equal(CaretBookmark.resolve(getRoot(), 'b[0]/i[2]'), null); - equal(CaretBookmark.resolve(getRoot(), 'x'), null); - equal(CaretBookmark.resolve(getRoot(), null), null); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/CaretCandidate.js b/tests/qunit/editor/tinymce/caret/CaretCandidate.js deleted file mode 100644 index 6485d921b6..0000000000 --- a/tests/qunit/editor/tinymce/caret/CaretCandidate.js +++ /dev/null @@ -1,63 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/CaretCandidate", - "tinymce/dom/DomQuery", - "tinymce/text/Zwsp" -], function(Env, CaretCandidate, $, Zwsp) { - module("tinymce.caret.CaretCandidate"); - - if (!Env.ceFalse) { - return; - } - - function getRoot() { - return document.getElementById('view'); - } - - function setupHtml(html) { - getRoot().innerHTML = html; - } - - test('isCaretCandidate', function() { - $.each("img input textarea hr table iframe video audio object".split(' '), function(index, name) { - equal(CaretCandidate.isCaretCandidate(document.createElement(name)), true); - }); - - equal(CaretCandidate.isCaretCandidate(document.createTextNode('text')), true); - equal(CaretCandidate.isCaretCandidate($('')[0]), true); - equal(CaretCandidate.isCaretCandidate($('')[0]), true); - equal(CaretCandidate.isCaretCandidate($('| X |
| X |
a
'); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/CaretPosition.js b/tests/qunit/editor/tinymce/caret/CaretPosition.js deleted file mode 100644 index 3f18490a66..0000000000 --- a/tests/qunit/editor/tinymce/caret/CaretPosition.js +++ /dev/null @@ -1,173 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/CaretPosition" -], function(Env, CaretPosition) { - module("tinymce.caret.CaretPosition"); - - if (!Env.ceFalse) { - return; - } - - var createRange = Utils.createRange, - assertCaretPosition = Utils.assertCaretPosition, - assertRange = Utils.assertRange; - - function getRoot() { - return document.getElementById('view'); - } - - function setupHtml(html) { - tinymce.$(getRoot()).empty(); - getRoot().innerHTML = html; - } - - test('Constructor', function() { - setupHtml('abc'); - strictEqual(new CaretPosition(getRoot(), 0).container(), getRoot()); - strictEqual(new CaretPosition(getRoot(), 1).offset(), 1); - strictEqual(new CaretPosition(getRoot().firstChild, 0).container(), getRoot().firstChild); - strictEqual(new CaretPosition(getRoot().firstChild, 1).offset(), 1); - }); - - test('fromRangeStart', function() { - setupHtml('abc'); - assertCaretPosition(CaretPosition.fromRangeStart(createRange(getRoot(), 0)), new CaretPosition(getRoot(), 0)); - assertCaretPosition(CaretPosition.fromRangeStart(createRange(getRoot(), 1)), new CaretPosition(getRoot(), 1)); - assertCaretPosition(CaretPosition.fromRangeStart(createRange(getRoot().firstChild, 1)), new CaretPosition(getRoot().firstChild, 1)); - }); - - test('fromRangeEnd', function() { - setupHtml('abc'); - assertCaretPosition(CaretPosition.fromRangeEnd(createRange(getRoot(), 0, getRoot(), 1)), new CaretPosition(getRoot(), 1)); - assertCaretPosition(CaretPosition.fromRangeEnd(createRange(getRoot().firstChild, 0, getRoot().firstChild, 1)), new CaretPosition(getRoot().firstChild, 1)); - }); - - test('after', function() { - setupHtml('abc123'); - assertCaretPosition(CaretPosition.after(getRoot().firstChild), new CaretPosition(getRoot(), 1)); - assertCaretPosition(CaretPosition.after(getRoot().lastChild), new CaretPosition(getRoot(), 2)); - }); - - test('before', function() { - setupHtml('abc123'); - assertCaretPosition(CaretPosition.before(getRoot().firstChild), new CaretPosition(getRoot(), 0)); - assertCaretPosition(CaretPosition.before(getRoot().lastChild), new CaretPosition(getRoot(), 1)); - }); - - test('isAtStart', function() { - setupHtml('abc123123'); - ok(new CaretPosition(getRoot(), 0).isAtStart()); - ok(!new CaretPosition(getRoot(), 1).isAtStart()); - ok(!new CaretPosition(getRoot(), 3).isAtStart()); - ok(new CaretPosition(getRoot().firstChild, 0).isAtStart()); - ok(!new CaretPosition(getRoot().firstChild, 1).isAtStart()); - ok(!new CaretPosition(getRoot().firstChild, 3).isAtStart()); - }); - - test('isAtEnd', function() { - setupHtml('abc123123'); - ok(new CaretPosition(getRoot(), 3).isAtEnd()); - ok(!new CaretPosition(getRoot(), 2).isAtEnd()); - ok(!new CaretPosition(getRoot(), 0).isAtEnd()); - ok(new CaretPosition(getRoot().firstChild, 3).isAtEnd()); - ok(!new CaretPosition(getRoot().firstChild, 0).isAtEnd()); - ok(!new CaretPosition(getRoot().firstChild, 1).isAtEnd()); - }); - - test('toRange', function() { - setupHtml('abc'); - assertRange(new CaretPosition(getRoot(), 0).toRange(), createRange(getRoot(), 0)); - assertRange(new CaretPosition(getRoot(), 1).toRange(), createRange(getRoot(), 1)); - assertRange(new CaretPosition(getRoot().firstChild, 1).toRange(), createRange(getRoot().firstChild, 1)); - }); - - test('isEqual', function() { - setupHtml('abc'); - equal(new CaretPosition(getRoot(), 0).isEqual(new CaretPosition(getRoot(), 0)), true); - equal(new CaretPosition(getRoot(), 1).isEqual(new CaretPosition(getRoot(), 0)), false); - equal(new CaretPosition(getRoot(), 0).isEqual(new CaretPosition(getRoot().firstChild, 0)), false); - }); - - test('isVisible', function() { - setupHtml(' abc'); - equal(new CaretPosition(getRoot().firstChild.firstChild, 0).isVisible(), false); - equal(new CaretPosition(getRoot().firstChild.firstChild, 3).isVisible(), true); - }); - - test('getClientRects', function() { - setupHtml( - 'abc' + - '123
' + - 'abc
| X |
| A |
| B |
' + - '' + - '' + - 'abc' + - '' + - 'def' + - '' + - '
' + - 'abc
' - ); - - assertCaretPosition(logicalCaret.next(findTextPos('span span', 3)), CaretPosition(findElm('p'), 1)); - }); - - test('around cE=false inside nested cE=true', function() { - setupHtml( - '' + - '' + - '1' + - '2' + - '3' + - '' + - '' - ); - - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('span span'), 0)), CaretPosition(findElm('span span'), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('span span'), 1)), CaretPosition(findElm('span span'), 2)); - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('span span'), 2)), CaretPosition(findElm('span span'), 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('span span'), 3)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('span span'), 0)), CaretPosition(getRoot(), 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('span span'), 1)), CaretPosition(findElm('span span'), 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('span span'), 2)), CaretPosition(findElm('span span'), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('span span'), 3)), CaretPosition(findElm('span span'), 2)); - }); - - test('next from last node', function() { - setupHtml( - '' + - '' + - '
' - ); - - assertCaretPosition(logicalCaret.next(findElmPos('p:first', 1)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(findElmPos('p:last', 1)), null); - }); - - test('left/right between cE=false inlines in different blocks', function() { - setupHtml( - '
' + - 'abc' + - '
' + - '' + - 'def' + - '
' - ); - - assertCaretPosition(logicalCaret.next(findElmPos('p:first', 1)), findElmPos('p:last', 0)); - assertCaretPosition(logicalCaret.prev(findElmPos('p:last', 0)), findElmPos('p:first', 1)); - }); - - test('never into caret containers', function() { - setupHtml('abcdefghi'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot().lastChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().lastChild, 0)), CaretPosition(getRoot().firstChild, 3)); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/FakeCaret.js b/tests/qunit/editor/tinymce/caret/FakeCaret.js deleted file mode 100644 index 080896580b..0000000000 --- a/tests/qunit/editor/tinymce/caret/FakeCaret.js +++ /dev/null @@ -1,94 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/FakeCaret", - "tinymce/dom/DomQuery", - "tinymce/text/Zwsp" -], function(Env, FakeCaret, $, Zwsp) { - var fakeCaret; - - if (!Env.ceFalse) { - return; - } - - module("tinymce.caret.FakeCaret", { - setupModule: function() { - fakeCaret = new FakeCaret($('#view')[0], isBlock); - }, - - teardownModule: function() { - fakeCaret.destroy(); - } - }); - - function isBlock(node) { - return node.nodeName == 'DIV'; - } - - test('show/hide (before, block)', function() { - var rng, $fakeCaretElm; - - $('#view').html('a
b
c
'); - - caretPosition = new CaretPosition($('#view')[0].lastChild.lastChild, 1); - result = LineWalker.upUntil($('#view')[0], predicate, caretPosition); - - equal(result.length, 3); - equal(result[0].line, 0); - equal(result[1].line, 1); - equal(result[2].line, 2); - equal(predicateCallCount, 3); - }); - - test('downUntil', function() { - var caretPosition, result, predicateCallCount = 0; - - function predicate() { - predicateCallCount++; - return false; - } - - $('#view').html('a
b
c
'); - - caretPosition = new CaretPosition($('#view')[0].firstChild.firstChild, 0); - result = LineWalker.downUntil($('#view')[0], predicate, caretPosition); - - equal(result.length, 3); - equal(result[0].line, 0); - equal(result[1].line, 1); - equal(result[2].line, 2); - equal(predicateCallCount, 3); - }); - - test('isAboveLine', function() { - equal(LineWalker.isAboveLine(5)({line: 10}), true); - equal(LineWalker.isAboveLine(5)({line: 2}), false); - }); - - test('isLine', function() { - equal(LineWalker.isLine(3)({line: 3}), true); - equal(LineWalker.isLine(3)({line: 4}), false); - }); -}); diff --git a/tests/qunit/editor/tinymce/content/LinkTargets.js b/tests/qunit/editor/tinymce/content/LinkTargets.js deleted file mode 100644 index e03f85454e..0000000000 --- a/tests/qunit/editor/tinymce/content/LinkTargets.js +++ /dev/null @@ -1,104 +0,0 @@ -ModuleLoader.require([ - "tinymce/content/LinkTargets", - "tinymce/util/Arr" -], function(LinkTargets, Arr) { - module("tinymce.content.LinkTargets", {}); - - var createFromHtml = function (html) { - var elm = document.createElement('div'); - elm.contentEditable = true; - elm.innerHTML = html; - return elm; - }; - - var targetsIn = function (html) { - return LinkTargets.find(createFromHtml(html)); - }; - - var equalTargets = function (actualTargets, expectedTargets, message) { - var nonAttachedTargets = Arr.map(actualTargets, function (target) { - return { - level: target.level, - title: target.title, - type: target.type, - url: target.url - }; - }); - - deepEqual(nonAttachedTargets, expectedTargets, message); - }; - - test('Non link targets', function() { - equal(targetsIn('a').length, 0, 'Text has no targets'); - equal(targetsIn('a
').length, 0, 'Paragraph has no targets'); - equal(targetsIn('a').length, 0, 'Link has no targets'); - }); - - test('Anchor targets', function() { - equalTargets(targetsIn(''), [{level: 0, title: '#a', type: 'anchor', url: '#a'}], 'Anchor with id'); - equalTargets(targetsIn(''), [{level: 0, title: '#a', type: 'anchor', url: '#a'}], 'Anchor with name'); - equalTargets(targetsIn(''), [], 'cE=false anchor'); - equalTargets(targetsIn(''), [], 'Anchor in cE=false'); - equalTargets(targetsIn(''), [], 'Empty anchor name should not produce a target'); - equalTargets(targetsIn(''), [], 'Empty anchor id should not produce a target'); - }); - - test('Header targets', function() { - equalTargets(targetsIn('text1innertext2
'); - parent = DOM.select('p', DOM.get('test'))[0]; - point = DOM.select('span', DOM.get('test'))[0]; - DOM.split(parent, point); - equal(DOM.get('test').innerHTML.toLowerCase().replace(/\s+/g, ''), 'text1
innertext2
'); - - DOM.setHTML('test', '
');
- ok(!DOM.isEmpty(DOM.get('test')), 'Non empty html with img element');
-
- DOM.setHTML('test', '');
- ok(!DOM.isEmpty(DOM.get('test')), 'Span with bookmark attribute.');
-
- DOM.setHTML('test', '');
- ok(DOM.isEmpty(DOM.get('test')), 'Span with data-mce attribute.');
-
- DOM.setHTML('test', '');
- ok(!DOM.isEmpty(DOM.get('test')), 'Element with comment.');
-
- DOM.setHTML('test', '');
- ok(DOM.isEmpty(DOM.get('test')), 'Contains just a bogus element.');
-
- DOM.setHTML('test', 'a');
- ok(!DOM.isEmpty(DOM.get('test')), 'Contains a text node in a bogus element.');
-
- DOM.setHTML('test', 'a');
- ok(DOM.isEmpty(DOM.get('test')), 'Contains just a bogus all element.');
-
- DOM.setHTML('test', 'ab');
- ok(!DOM.isEmpty(DOM.get('test')), 'Contains a bogus all element but some text as well.');
-
- DOM.setHTML('test', ' ');
- ok(!DOM.isEmpty(DOM.get('test')), 'Contains a code element should be treated as content.');
-
- DOM.setHTML('test', ''); - ok(!DOM.isEmpty(DOM.get('test')), 'Contains a pre element should be treated as content.'); - - DOM.setHTML('test', '
');
- ok(!DOM.isEmpty(DOM.get('test')), 'Contains a code element should be treated as content.');
-
- DOM.setHTML('test', '');
- ok(!DOM.isEmpty(DOM.get('test')), 'Contains a pre element should be treated as content.');
-
- DOM.remove('test');
- });
-
- test('isEmpty with list of elements considered non-empty', function() {
- var elm = DOM.create('p', null, 'a12
'); - - deepEqual(NodePath.create(getRoot(), getRoot().firstChild), [0]); - deepEqual(NodePath.create(getRoot(), getRoot().firstChild.firstChild), [0, 0]); - deepEqual(NodePath.create(getRoot(), getRoot().firstChild.lastChild.lastChild), [1, 1, 0]); - }); - - test("resolve", function() { - setupHtml('a12
'); - - deepEqual(NodePath.resolve(getRoot(), NodePath.create(getRoot(), getRoot().firstChild)), getRoot().firstChild); - deepEqual(NodePath.resolve(getRoot(), NodePath.create(getRoot(), getRoot().firstChild.firstChild)), getRoot().firstChild.firstChild); - deepEqual(NodePath.resolve(getRoot(), NodePath.create(getRoot(), getRoot().firstChild.lastChild.lastChild)), getRoot().firstChild.lastChild.lastChild); - }); -}); \ No newline at end of file diff --git a/tests/qunit/editor/tinymce/dom/NodeType.js b/tests/qunit/editor/tinymce/dom/NodeType.js deleted file mode 100644 index 73d2b1c13e..0000000000 --- a/tests/qunit/editor/tinymce/dom/NodeType.js +++ /dev/null @@ -1,81 +0,0 @@ -ModuleLoader.require([ - "tinymce/dom/NodeType", - "tinymce/dom/DomQuery" -], function(NodeType, $) { - module("tinymce.dom.NodeType"); - - test('isText/isElement/isComment', function() { - strictEqual(NodeType.isText(document.createTextNode("x")), true); - strictEqual(NodeType.isText(null), false); - strictEqual(NodeType.isText(document.createElement("div")), false); - strictEqual(NodeType.isText(document.createComment("x")), false); - - strictEqual(NodeType.isElement(document.createElement("div")), true); - strictEqual(NodeType.isElement(null), false); - strictEqual(NodeType.isElement(document.createTextNode("x")), false); - strictEqual(NodeType.isElement(document.createComment("x")), false); - - strictEqual(NodeType.isComment(document.createComment("x")), true); - strictEqual(NodeType.isComment(null), false); - strictEqual(NodeType.isComment(document.createTextNode("x")), false); - strictEqual(NodeType.isComment(document.createElement("div")), false); - }); - - test('isBr', function() { - strictEqual(NodeType.isBr(null), false); - strictEqual(NodeType.isBr(document.createTextNode("x")), false); - strictEqual(NodeType.isBr(document.createElement('br')), true); - strictEqual(NodeType.isBr(document.createComment("x")), false); - }); - - test('isContentEditableTrue', function() { - strictEqual(NodeType.isContentEditableTrue(null), false); - strictEqual(NodeType.isContentEditableTrue(document.createComment("x")), false); - strictEqual(NodeType.isContentEditableTrue(document.createTextNode("x")), false); - strictEqual(NodeType.isContentEditableTrue(document.createElement('div')), false); - strictEqual(NodeType.isContentEditableTrue($('')[0]), true); - strictEqual(NodeType.isContentEditableTrue($('')[0]), true); - strictEqual(NodeType.isContentEditableTrue($('')[0]), false); - strictEqual(NodeType.isContentEditableTrue($('')[0]), false); - strictEqual(NodeType.isContentEditableTrue($('')[0]), false); - }); - - test('isContentEditableFalse', function() { - strictEqual(NodeType.isContentEditableFalse(null), false); - strictEqual(NodeType.isContentEditableFalse(document.createComment("x")), false); - strictEqual(NodeType.isContentEditableFalse(document.createTextNode("x")), false); - strictEqual(NodeType.isContentEditableFalse(document.createElement('div')), false); - strictEqual(NodeType.isContentEditableFalse($('')[0]), false); - strictEqual(NodeType.isContentEditableFalse($('')[0]), false); - strictEqual(NodeType.isContentEditableFalse($('')[0]), true); - strictEqual(NodeType.isContentEditableFalse($('')[0]), true); - strictEqual(NodeType.isContentEditableFalse($('')[0]), false); - }); - - test('matchNodeNames', function() { - var matchNodeNames = NodeType.matchNodeNames('a div #text'); - - strictEqual(matchNodeNames(null), false); - strictEqual(matchNodeNames(document.createTextNode('x')), true); - strictEqual(matchNodeNames(document.createElement('a')), true); - strictEqual(matchNodeNames(document.createElement('div')), true); - strictEqual(matchNodeNames(document.createElement('b')), false); - }); - - test('hasPropValue', function() { - var hasTabIndex3 = NodeType.hasPropValue('tabIndex', 3); - - strictEqual(hasTabIndex3(null), false); - strictEqual(hasTabIndex3($('')[0]), true); - strictEqual(hasTabIndex3(document.createElement('div')), false); - strictEqual(hasTabIndex3(document.createElement('b')), false); - }); - - test('isBogus', function() { - strictEqual(NodeType.isBogus($('')[0]), true); - strictEqual(NodeType.isBogus($('')[0]), true); - strictEqual(NodeType.isBogus($('')[0]), false); - strictEqual(NodeType.isBogus(document.createTextNode('test')), false); - strictEqual(NodeType.isBogus(null), false); - }); -}); diff --git a/tests/qunit/editor/tinymce/dom/Range.js b/tests/qunit/editor/tinymce/dom/Range.js deleted file mode 100644 index 1c4edec564..0000000000 --- a/tests/qunit/editor/tinymce/dom/Range.js +++ /dev/null @@ -1,550 +0,0 @@ -ModuleLoader.require([ - "tinymce/dom/Range" -], function(Range) { - module("tinymce.dom.Range", { - setup: function() { - document.getElementById('view').innerHTML = ( - 'first strong strong second em strong.
' + - 'bar
' + - 'some textem textmore text
' + - '| 1 | ' + - 'abc | ' + - '
| 3 | ' + - '4 | ' + - '
textabcspan
' + - 'irst strong strong second em strong.
bar
some textem textmore text
| 1 | ab |
| bc | |
| 3 | 4 |
te
'); - equal(r.startContainer.nodeType, 3); - equal(r.startOffset, 1); - equal(r.endContainer.nodeType, 3); - equal(r.endOffset, 2); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeName, 'DIV'); - - r.setStart(document.getElementById('first').firstChild, 1); - r.setEnd(document.getElementById('first').lastChild, 4); - - equal(getHTML(r.cloneContents()), 'irst strong strong second em str'); - equal(r.startContainer.nodeType, 3); - equal(r.startOffset, 1); - equal(r.endContainer.nodeType, 3); - equal(r.endOffset, 4); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeName, 'P'); - - r.setStart(document.getElementById('first').firstChild, 1); - r.setEnd(document.getElementById('first').firstChild, 4); - - equal(getHTML(r.cloneContents()), 'irs'); - equal(r.startContainer.nodeType, 3); - equal(r.startOffset, 1); - equal(r.endContainer.nodeType, 3); - equal(r.endOffset, 4); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeType, 3); - - r.setStart(document.getElementById('first'), 0); - r.setEnd(document.getElementById('last'), 0); - - equal(getHTML(r.cloneContents()), 'first strong strong second em strong.
bar
some textem textmore text
| 1 | abc |
| 3 | 4 |
strong strong second em strong.
bar
some textem textmore text
| 1 | abc |
| 3 | 4 |
textabc
'); - equal(r.startContainer.nodeType, 1); - equal(r.startOffset, 1); - equal(r.endContainer.nodeType, 1); - equal(r.endOffset, 1); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeType, 1); - - r.setStart(document.getElementById('sample'), 0); - r.setEnd(document.getElementById('sample'), document.getElementById('sample').childNodes.length - 1); - - equal(getHTML(r.cloneContents()), 'first strong strong second em strong.
bar
some textem textmore text
| 1 | abc |
| 3 | 4 |
first strong strong second em strong.
bar
some textem textmore text
| 1 | abc |
| 3 | 4 |
t
'); - equal(r.startContainer.nodeType, 1); - equal(r.startOffset, 0); - equal(r.endContainer.nodeType, 3); - equal(r.endOffset, 1); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeType, 1); - - r.setStart(document.getElementById('first').firstChild, 1); - r.setEnd(document.getElementById('last'), 0); - - equal(getHTML(r.cloneContents()), 'irst strong strong second em strong.
bar
some textem textmore text
| 1 | abc |
| 3 | 4 |
first strong strong second em strong.
bar
some textem text
'); - equal(r.startContainer.nodeType, 1); - equal(r.startOffset, 0); - equal(r.endContainer.nodeType, 1); - equal(r.endOffset, 2); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeType, 1); - - r.setStart(document.getElementById('sample'), 0); - r.setEnd(document.getElementById('traverse'), 1); - - equal(getHTML(r.cloneContents()), 'first strong strong second em strong.
bar
some text
'); - equal(r.startContainer.nodeType, 1); - equal(r.startOffset, 0); - equal(r.endContainer.nodeType, 1); - equal(r.endOffset, 1); - equal(r.collapsed, false); - equal(r.commonAncestorContainer.nodeType, 1); - }); - } - - test("test_extractContents1", function() { - var r = createRng(); - - expect(10); - - r.setStart(document.getElementById('first').firstChild, 1); - r.setEnd(document.getElementById('first').firstChild, 4); - - equal(getHTML(r.extractContents()), 'irs'); - equal(r.startContainer.nodeType, 3); - equal(r.startOffset, 1); - equal(r.endContainer.nodeType, 3); - equal(r.endOffset, 1); - equal(r.collapsed, true); - equal(r.startContainer == r.endContainer, true); - equal(r.startOffset == r.endOffset, true); - equal(r.commonAncestorContainer.nodeType, 3); - equal(getHTML(document.getElementById('first')), 'ft strong strong second em strong.
'); - }); - - test("test_extractContents2", function() { - var r = createRng(); - - expect(9); - - r.setStart(document.getElementById('two').firstChild, 1); - r.setEnd(document.getElementById('last').firstChild, 2); - - equal(getHTML(r.extractContents()), '| bc | |
| 3 | 4 |
te
'); - equal(r.startContainer.nodeType, 1); - equal(getHTML(r.startContainer), 'first strong strong second em strong.
bar
some textem textmore text
| 1 | a |
xtabcspan
first strong strong second em strong.
bar
some textem textmore text
| 1 | a |
xtabcspan
first strong strong second em strong.
bar
some textem text
'); - equal(getHTML(r.startContainer), 'more text
| 1 | abc |
| 3 | 4 |
textabcspan
more text
| 1 | abc |
| 3 | 4 |
textabcspan
more text
| 1 | abc |
| 3 | 4 |
textabcspan
first strong strong second em strong.
bar
some textem textmore text
| 1 | a |
xtabcspan
first strong strong second em strong.
bar
some textem textmore text
| 1 | a |
xtabcspan
first strong strong second em strong.
bar
some textem textmore text
| 1 | a |
xtabcspan
fong.
'); - equal(r.startOffset, 1); - equal(r.endContainer.nodeType, 1); - equal(r.endOffset, 1); - equal(getHTML(r.endContainer), 'fong.
'); - equal(getHTML(document.getElementById('sample')), 'fong.
bar
some textem textmore text
| 1 | abc |
| 3 | 4 |
textabcspan
some textem textmore text
| 1 | abc |
| 3 | 4 |
textabcspan
some textem textmore text
| 1 | abc |
| 3 | 4 |
textabcspan
some textem textmore text
| 1 | abc |
| 3 | 4 |
textabcspan
more text
| 1 | abc |
| 3 | 4 |
textabcspan
more text
| 1 | abc |
| 3 | 4 |
textabcspan
more text
| 1 | abc |
| 3 | 4 |
textabcspan
text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - equal(editor.selection.getContent(), 'text
', 'Get selected contents'); - - // Get selected contents (collapsed) - editor.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 0); - editor.selection.setRng(rng); - equal(editor.selection.getContent(), '', 'Get selected contents (collapsed)'); - - // Get selected contents, onGetContent event - eventObj = {}; - - function handler(event) { - eventObj = event; - } - - editor.on('GetContent', handler); - editor.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.selection.getContent(); - equal(eventObj.content, 'text
', 'Get selected contents, onGetContent event'); - editor.off('GetContent', handler); - }); - - test('setContent', function() { - var rng, eventObj; - - // Set contents at selection - editor.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.selection.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 0); - editor.selection.setRng(rng); - editor.selection.setContent('text
', 'Set contents at selection (collapsed)'); - - // Insert in middle of paragraph - editor.setContent('beforeafter
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.firstChild, 'before'.length); - rng.setEnd(editor.getBody().firstChild.firstChild, 'before'.length); - editor.selection.setRng(rng); - editor.selection.setContent('before
after
text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 0); - editor.selection.setRng(rng); - editor.selection.setContent(''); - equal(editor.getContent(), 'text
', 'Set contents to empty at selection (collapsed)'); - rng = editor.selection.getRng(true); - if (!document.createRange) { - // The old IE selection can only be positioned in text nodes - equal(rng.startContainer, editor.getBody().firstChild.firstChild, 'Selection start container'); - equal(rng.startOffset, 0, 'Selection start offset'); - equal(rng.endContainer, editor.getBody().firstChild.firstChild, 'Selection end container'); - equal(rng.endOffset, 0, 'Selection end offset'); - } else { - equal(rng.startContainer, editor.getBody(), 'Selection start container'); - equal(rng.startOffset, 0, 'Selection start offset'); - equal(rng.endContainer, editor.getBody(), 'Selection end container'); - equal(rng.endOffset, 0, 'Selection end offset'); - } - - // Set selected contents, onSetContent event - eventObj = {}; - - function handler(event) { - eventObj = event; - } - - editor.on('SetContent', handler); - editor.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.selection.setContent('text
text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.firstChild, 0); - rng.setEnd(editor.getBody().lastChild.firstChild, 0); - editor.selection.setRng(rng); - equal(editor.selection.getStart().id, 'a', 'Selected contents (getStart)'); - equal(editor.selection.getEnd().id, 'b', 'Selected contents (getEnd)'); - - // Selected contents (collapsed) - editor.setContent('text
\ntext
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.firstChild, 0); - rng.setEnd(editor.getBody().firstChild.firstChild, 0); - editor.selection.setRng(rng); - equal(editor.selection.getStart().id, 'a', 'Selected contents (getStart, collapsed)'); - equal(editor.selection.getEnd().id, 'a', 'Selected contents (getEnd, collapsed)'); - }); - - test('getBookmark/setBookmark (persistent)', function() { - var rng, bookmark; - - // Get persistent bookmark simple text selection - editor.setContent('text'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 1); - rng.setEnd(editor.getBody().firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(); - equal(editor.getContent(), 'text', 'Editor contents (text)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ex', 'Selected contents (text)'); - - // Get persistent bookmark multiple elements text selection - editor.setContent('text
\ntext
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.firstChild, 1); - rng.setEnd(editor.getBody().lastChild.firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(); - equal(editor.getContent(), 'text
\ntext
', 'Editor contents (elements)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ext
\ntex
', 'Selected contents (elements)'); - }); - - test('getBookmark/setBookmark (simple)', function() { - var rng, bookmark; - - // Get persistent bookmark simple text selection - editor.setContent('text'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 1); - rng.setEnd(editor.getBody().firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(1); - equal(editor.getContent(), 'text', 'Editor contents (text)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ex', 'Selected contents (text)'); - - // Get persistent bookmark multiple elements text selection - editor.setContent('text
\ntext
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.firstChild, 1); - rng.setEnd(editor.getBody().lastChild.firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(1); - equal(editor.getContent(), 'text
\ntext
', 'Editor contents (elements)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ext
\ntex
', 'Selected contents (elements)'); - }); - - test('getBookmark/setBookmark (nonintrusive) - simple text selection', function() { - var rng, bookmark; - - expect(2); - - editor.setContent('text'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 1); - rng.setEnd(editor.getBody().firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2); - equal(editor.getContent(), 'text', 'Editor contents (text)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ex', 'Selected contents (text)'); - }); - - test('getBookmark/setBookmark (nonintrusive) - Get non intrusive bookmark simple element selection', function() { - var rng, bookmark; - - expect(1); - - // Get non intrusive bookmark simple element selection - editor.setContent('textabc
'); - rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('em')[0], 1); - rng.setEnd(editor.dom.select('em')[0], 2); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'b', 'Selected contents (element)'); - }); - - test('getBookmark/setBookmark (nonintrusive) - Get non intrusive bookmark multiple elements text selection', function() { - var rng, bookmark; - - expect(2); - - // Get non intrusive bookmark multiple elements text selection - editor.setContent('text
\ntext
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.firstChild, 1); - rng.setEnd(editor.getBody().lastChild.firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2); - equal(editor.getContent(), 'text
\ntext
', 'Editor contents (elements)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ext
\ntex
', 'Selected contents (elements)'); - }); - - test('getBookmark/setBookmark (nonintrusive)', function() { - var rng, bookmark; - - expect(2); - - // Get non intrusive bookmark multiple elements text selection fragmented - editor.setContent('text
text
'); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a')); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a')); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a')); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('text')); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.lastChild, 1); - rng.setEnd(editor.getBody().lastChild.firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2); - equal(editor.getContent(), 'textaaatext
\ntext
', 'Editor contents (fragmented, elements)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ext
\ntex
', 'Selected contents (fragmented, elements)'); - }); - - test('getBookmark/setBookmark (nonintrusive) - fragmentext text (normalized)', function() { - var rng, bookmark; - - expect(2); - - // Get non intrusive bookmark multiple elements text selection fragmented - editor.setContent('text
text
'); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a')); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a')); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a')); - editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('text')); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.lastChild, 1); - rng.setEnd(editor.getBody().lastChild.firstChild, 3); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2, true); - editor.setContent(editor.getContent()); - equal(editor.getContent(), 'textaaatext
\ntext
', 'Editor contents (fragmented, elements)'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getContent(), 'ext
\ntex
', 'Selected contents (fragmented, elements)'); - }); - - test('getBookmark/setBookmark (nonintrusive) - Get bookmark before image', function() { - var rng, bookmark; - - expect(4); - - editor.setContent('abc
123123
123123
| abc |
1
'); - CaretContainer.insertInline(editor.$('span')[0], true); - rng = editor.dom.createRng(); - rng.setStart(editor.$('span')[0].previousSibling, 0); - rng.setEnd(editor.$('span')[0].previousSibling, 0); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2); - editor.setContent('1
'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getNode(), editor.$('span')[0]); - }); - - test('getBookmark/setBookmark before cE=false block', function() { - var rng, bookmark; - - editor.setContent('1
'); - CaretContainer.insertBlock('p', editor.$('p')[0], true); - rng = editor.dom.createRng(); - rng.setStart(editor.$('p')[0], 0); - rng.setEnd(editor.$('p')[0], 0); - editor.selection.setRng(rng); - bookmark = editor.selection.getBookmark(2); - editor.setContent('1
'); - editor.selection.moveToBookmark(bookmark); - equal(editor.selection.getNode(), editor.$('p')[0]); - }); - - test('select empty TD', function() { - editor.getBody().innerHTML = 'text1
text2
'); - editor.selection.select(editor.dom.select('p')[0]); - equal(editor.selection.getContent(), 'text1
', 'Select simple element, content'); - equal(editor.selection.getStart().nodeName, 'P', 'Select simple element, nodeName'); - }); - - test('select table', 2, function() { - editor.setContent('| text1 |
| text1 | \n
| text1 | text2 |
span1 word span2 word span3
'); - rng = editor.dom.createRng(); - rng.setStart(editor.dom.get('s1').firstChild, 0); - rng.setEnd(editor.dom.get('s1').nextSibling, 0); - editor.selection.setRng(rng); - deepEqual(editor.selection.getNode(), editor.dom.get('s1'), 'Detect selection ends immediately after node at start of paragraph.'); - - rng = editor.dom.createRng(); - rng.setStart(editor.dom.get('s2').previousSibling, editor.dom.get('s2').previousSibling.length); - rng.setEnd(editor.dom.get('s2').nextSibling, 0); - editor.selection.setRng(rng); - deepEqual(editor.selection.getNode(), editor.dom.get('s2'), 'Detect selection immediately surrounds node in middle of paragraph.'); - - rng = editor.dom.createRng(); - rng.setStart(editor.dom.get('s3').previousSibling, editor.dom.get('s3').previousSibling.length); - rng.setEnd(editor.dom.get('s3').lastChild, editor.dom.get('s3').lastChild.length); - editor.selection.setRng(rng); - deepEqual(editor.selection.getNode(), editor.dom.get('s3'), 'Detect selection starts immediately before node at end of paragraph.'); - - rng = editor.dom.createRng(); - rng.setStart(editor.dom.get('s2').previousSibling, editor.dom.get('s2').previousSibling.length); - rng.setEnd(editor.dom.get('s3').lastChild, editor.dom.get('s3').lastChild.length); - editor.selection.setRng(rng); - deepEqual(editor.selection.getNode(), editor.dom.get('p1'), 'Detect selection wrapping multiple nodes does not collapse.'); - }); - - test('normalize to text node from document', function() { - var rng; - - if (tinymce.isOpera || tinymce.isIE) { - ok(true, "Skipped on Opera/IE since Opera doesn't let you to set the range to document and IE will steal focus."); - return; - } - - editor.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getDoc(), 0); - rng.setEnd(editor.getDoc(), 0); - editor.selection.setRng(rng); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeType, 3, 'startContainer node type'); - equal(rng.startOffset, 0, 'startContainer offset'); - equal(rng.endContainer.nodeType, 3, 'endContainer node type'); - equal(rng.endOffset, 0, 'endOffset offset'); - }); - - test('normalize to br from document', function() { - var rng; - - if (tinymce.isOpera || tinymce.isIE) { - ok(true, "Skipped on Opera/IE since Opera doesn't let you to set the range to document and IE will steal focus."); - return; - } - - editor.setContent('abc
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.lastChild, 0); - rng.setEnd(editor.getBody().firstChild.lastChild, 0); - editor.selection.setRng(rng); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.collapsed, true); - equal(CaretContainer.isCaretContainer(rng.startContainer), true); - }); - - test('normalize with contentEditable:false parent and contentEditable:true child element', function() { - editor.setContent('ab
'); - Utils.setSelection('em', 0); - editor.selection.normalize(); - - var rng = editor.selection.getRng(true); - equal(rng.collapsed, true); - equal(rng.startContainer.nodeType, 3); - equal(rng.startContainer.data, 'b'); - - // WebKit is in some state state here, so lets restore it - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 0); - editor.selection.setRng(rng); - }); - - test('normalize with contentEditable:true parent and contentEditable:false child element', function() { - editor.setContent('ab
'); - Utils.setSelection('em', 0); - editor.selection.normalize(); - - var rng = editor.selection.getRng(true); - - if (Env.ie && Env.ie < 12) { - // IE automatically normalizes - ok(rng.startContainer.parentNode.contentEditable != 'false'); - } else { - equal(CaretContainer.isCaretContainer(rng.startContainer), true); - } - - // Excluding assert on IE since it's a minor issue - if (tinymce.ie) { - equal(rng.startOffset, 1); - } - }); - - test('normalize to text node from body', function() { - var rng; - - editor.setContent('text
'); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 0); - editor.selection.setRng(rng); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeType, 3, 'startContainer node type'); - equal(rng.startOffset, 0, 'startContainer offset'); - equal(rng.endContainer.nodeType, 3, 'endContainer node type'); - equal(rng.endOffset, 0, 'endOffset offset'); - }); - - test('normalize to br from body', function() { - var rng; - - editor.setContent('abc
'; - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, '#text', 'startContainer node name'); - equal(rng.startOffset, 0, 'startContainer offset'); - equal(rng.endContainer.nodeName, '#text', 'endContainer node name'); - equal(rng.endOffset, 3, 'endOffset offset'); - }); - - test('normalize lean left if at the start of text node', function() { - var rng; - - editor.getBody().innerHTML = 'ab
'; - Utils.setSelection('i', 0); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, '#text', 'startContainer node name'); - equal(rng.startContainer.parentNode.nodeName, 'B'); - equal(rng.startOffset, 1, 'startContainer offset'); - equal(rng.endContainer.nodeName, '#text'); - equal(rng.endContainer.parentNode.nodeName, 'B'); - equal(rng.endOffset, 1, 'endOffset offset'); - }); - - test('normalize lean start to the right if at end of text node', function() { - var rng; - - editor.getBody().innerHTML = 'ab
'; - Utils.setSelection('b', 1, 'i', 1); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, '#text', 'startContainer node name'); - equal(rng.startContainer.parentNode.nodeName, 'I'); - equal(rng.startOffset, 0, 'startContainer offset'); - equal(rng.endContainer.nodeName, '#text'); - equal(rng.endContainer.parentNode.nodeName, 'I'); - equal(rng.endOffset, 1, 'endOffset offset'); - }); - - test('normalize lean left but break before br', function() { - var rng; - - editor.getBody().innerHTML = 'a
b
ab
a
b
'; - Utils.setSelection('b', 0); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeValue, 'b'); - equal(rng.startOffset, 0); - }); - - test('normalize lean left into empty inline elements when caret is before br', function() { - var rng; - - editor.getBody().innerHTML = '' + Zwsp.ZWSP + '
| X |
a
'; - rng = editor.dom.createRng(); - rng.setStartAfter(editor.getBody().firstChild); - rng.setEndAfter(editor.getBody().lastChild); - editor.selection.setRng(rng); - editor.selection.normalize(); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, '#text'); - equal(rng.startOffset, 1); - equal(rng.endContainer.nodeName, '#text'); - equal(rng.endOffset, 1); - }); - - test('normalize caret after trailing BR', function() { - var rng; - - editor.setContent('a
| b |
a
text
'; - Utils.setSelection('p', 0, 'p', 4); - editor.nodeChanged(); - equal(newArgs.selector, 'a[href]'); - equal(newArgs.node, editor.getBody().firstChild); - equal(newArgs.parents.length, 1); - }); - - test('setRng', function() { - var rng = editor.dom.createRng(); - - editor.setContent('x
'); - rng.setStart(editor.$('p')[0].firstChild, 0); - rng.setEnd(editor.$('p')[0].firstChild, 1); - - editor.selection.setRng(rng); - editor.selection.setRng(null); - - rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, '#text'); - equal(rng.startOffset, 0); - equal(rng.endContainer.nodeName, '#text'); - equal(rng.endOffset, 1); - }); - - test('getRng should return null if win.document is not defined or null', function() { - var win = editor.selection.win, - rng = editor.dom.createRng(); - - editor.setContent('x
'); - - rng.setStart(editor.$('p')[0].firstChild, 0); - rng.setEnd(editor.$('p')[0].firstChild, 1); - - editor.selection.setRng(rng); - editor.selection.setRng(null); - - editor.selection.win = {}; - rng = editor.selection.getRng(true); - equal(rng, null); - - editor.selection.win = {document:null}; - rng = editor.selection.getRng(true); - equal(rng, null); - - editor.selection.win = win; - }); - - test('image selection webkit bug', function() { - var testImageSelection = function (inputHtml, expectedContainerName, expectedOffset) { - editor.setContent(inputHtml); - editor.selection.select(editor.dom.select('img')[0]); - - var rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startOffset, expectedOffset); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.endOffset, expectedOffset + 1); - equal(editor.selection.getNode().nodeName, 'IMG'); - equal(editor.selection.getStart().nodeName, 'IMG'); - equal(editor.selection.getEnd().nodeName, 'IMG'); - - var nativeRng = editor.selection.getSel().getRangeAt(0); - equal(nativeRng.startContainer.nodeName, 'P'); - equal(nativeRng.startOffset, expectedOffset); - equal(nativeRng.startContainer.nodeName, 'P'); - equal(nativeRng.endOffset, expectedOffset + 1); - }; - - testImageSelection('abc
abc
abcdef
abc
abc
abcdef
abc
abc
abcdef
abc
abc
abcdef
abc
abc
abcdef
test
test
');
- equal(ser.serialize(DOM.get('test')), '', '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')), '


test
'); - equal(ser.serialize(DOM.get('test')), 'test
'); -}); - -test('Padd empty elements with BR', function() { - var ser = new tinymce.dom.Serializer({padd_empty_with_br: true}); - - ser.setRules('#p,table,tr,#td,br'); - - DOM.setHTML('test', '
a
'); - equal(ser.serialize(DOM.get('test')), 'a
a
a
test
'); - equal(ser.serialize(DOM.get('test')), 'test
'); -}); - -test('Pre/post process events', function() { - var ser = new tinymce.dom.Serializer({fix_list_elements : true}); - - expect(3); - - ser.setRules('div[id],span[id|class],a[href],b[class]'); - - ser.onPreProcess = function(o) { - equal(o.test, 'abc'); - DOM.setAttrib(o.node.getElementsByTagName('span')[0], 'class', 'abc'); - }; - - ser.onPostProcess = function(o) { - equal(o.test, 'abc'); - o.content = o.content.replace(//g, ''); - }; - - DOM.setHTML('test', 'abc123link'); - equal(ser.serialize(DOM.get('test'), {test : 'abc'}), '