From 1727d6fbef669c9ac190717e16ba950bdc71790b Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 8 May 2017 05:35:41 +0000 Subject: [PATCH] TinyMCE: remove the pre-4.6.0 tests. Move regression testing for obsolete tags and attributes to the default QUnit tests. See #40690. git-svn-id: https://develop.svn.wordpress.org/trunk@40584 602fd350-edb4-49c9-b593-d223f7449a82 --- .../external-plugins/noneditable/plugin.js | 101 - .../noneditable/plugin.min.js | 1 - tests/qunit/editor/index.html | 155 -- tests/qunit/editor/js/init.js | 122 - tests/qunit/editor/js/module_loader.js | 37 - tests/qunit/editor/js/qunit/QUnit.LICENSE | 20 - tests/qunit/editor/js/qunit/qunit.css | 237 -- tests/qunit/editor/js/qunit/qunit.js | 2293 ----------------- tests/qunit/editor/js/runner.js | 148 -- tests/qunit/editor/js/tinymce_loader.js | 9 - tests/qunit/editor/js/utils.js | 493 ---- tests/qunit/editor/tinymce/AddOnManager.js | 39 - tests/qunit/editor/tinymce/Editor.js | 527 ---- tests/qunit/editor/tinymce/EditorCommands.js | 890 ------- .../qunit/editor/tinymce/EditorCustomTheme.js | 43 - tests/qunit/editor/tinymce/EditorManager.js | 207 -- tests/qunit/editor/tinymce/EditorUpload.js | 324 --- tests/qunit/editor/tinymce/Editor_rtl.js | 55 - tests/qunit/editor/tinymce/EnterKey.js | 1121 -------- tests/qunit/editor/tinymce/FocusManager.js | 46 - tests/qunit/editor/tinymce/ForceBlocks.js | 87 - tests/qunit/editor/tinymce/Formatter_apply.js | 1795 ------------- tests/qunit/editor/tinymce/Formatter_check.js | 230 -- .../qunit/editor/tinymce/Formatter_remove.js | 415 --- tests/qunit/editor/tinymce/InsertContent.js | 110 - .../tinymce/InsertContentForcedRootFalse.js | 47 - tests/qunit/editor/tinymce/InsertList.js | 41 - .../editor/tinymce/NotificationManager.js | 109 - .../editor/tinymce/SelectionOverrides.js | 357 --- tests/qunit/editor/tinymce/Shortcuts.js | 87 - tests/qunit/editor/tinymce/UndoManager.js | 491 ---- tests/qunit/editor/tinymce/WindowManager.js | 41 - .../editor/tinymce/caret/CaretBookmark.js | 137 - .../editor/tinymce/caret/CaretCandidate.js | 63 - .../editor/tinymce/caret/CaretContainer.js | 137 - .../editor/tinymce/caret/CaretPosition.js | 173 -- .../qunit/editor/tinymce/caret/CaretUtils.js | 264 -- .../qunit/editor/tinymce/caret/CaretWalker.js | 277 -- tests/qunit/editor/tinymce/caret/FakeCaret.js | 94 - tests/qunit/editor/tinymce/caret/LineUtils.js | 28 - .../qunit/editor/tinymce/caret/LineWalker.js | 88 - .../editor/tinymce/content/LinkTargets.js | 104 - .../editor/tinymce/data/ObservableObject.js | 51 - tests/qunit/editor/tinymce/dom/DOMUtils.js | 716 ----- tests/qunit/editor/tinymce/dom/Dimensions.js | 34 - tests/qunit/editor/tinymce/dom/DomQuery.js | 1034 -------- tests/qunit/editor/tinymce/dom/EventUtils.js | 443 ---- tests/qunit/editor/tinymce/dom/NodePath.js | 29 - tests/qunit/editor/tinymce/dom/NodeType.js | 81 - tests/qunit/editor/tinymce/dom/Range.js | 550 ---- tests/qunit/editor/tinymce/dom/Selection.js | 1141 -------- tests/qunit/editor/tinymce/dom/Serializer.js | 559 ---- tests/qunit/editor/tinymce/dom/TreeWalker.js | 109 - .../editor/tinymce/dom/TridentSelection.js | 543 ---- tests/qunit/editor/tinymce/dom/test.css | 120 - .../qunit/editor/tinymce/file/Conversions.js | 17 - .../qunit/editor/tinymce/file/ImageScanner.js | 63 - .../qunit/editor/tinymce/file/UploadStatus.js | 32 - tests/qunit/editor/tinymce/fmt/FontInfo.js | 75 - tests/qunit/editor/tinymce/fmt/Hooks.js | 71 - tests/qunit/editor/tinymce/fmt/Preview.js | 247 -- tests/qunit/editor/tinymce/geom/ClientRect.js | 79 - tests/qunit/editor/tinymce/geom/Rect.js | 92 - tests/qunit/editor/tinymce/html/DomParser.js | 579 ----- tests/qunit/editor/tinymce/html/Entities.js | 75 - tests/qunit/editor/tinymce/html/Node.js | 442 ---- tests/qunit/editor/tinymce/html/Obsolete.js | 262 -- tests/qunit/editor/tinymce/html/SaxParser.js | 742 ------ tests/qunit/editor/tinymce/html/Schema.js | 560 ---- tests/qunit/editor/tinymce/html/Serializer.js | 32 - tests/qunit/editor/tinymce/html/Styles.js | 184 -- tests/qunit/editor/tinymce/html/Writer.js | 170 -- tests/qunit/editor/tinymce/options.js | 94 - .../editor/tinymce/text/ExtendingChar.js | 8 - tests/qunit/editor/tinymce/text/Zwsp.js | 15 - .../qunit/editor/tinymce/ui/AbsoluteLayout.js | 31 - tests/qunit/editor/tinymce/ui/Button.js | 104 - tests/qunit/editor/tinymce/ui/Collection.js | 253 -- tests/qunit/editor/tinymce/ui/ColorButton.js | 102 - tests/qunit/editor/tinymce/ui/Control.js | 204 -- tests/qunit/editor/tinymce/ui/FilePicker.js | 260 -- tests/qunit/editor/tinymce/ui/FitLayout.js | 57 - tests/qunit/editor/tinymce/ui/FlexLayout.js | 884 ------- tests/qunit/editor/tinymce/ui/GridLayout.js | 212 -- tests/qunit/editor/tinymce/ui/MenuButton.js | 108 - tests/qunit/editor/tinymce/ui/Panel.js | 38 - tests/qunit/editor/tinymce/ui/Selector.js | 127 - tests/qunit/editor/tinymce/ui/SplitButton.js | 102 - tests/qunit/editor/tinymce/ui/TabPanel.js | 133 - tests/qunit/editor/tinymce/ui/TextBox.js | 30 - tests/qunit/editor/tinymce/ui/Window.js | 96 - .../editor/tinymce/ui/css/ui-overrides.css | 33 - tests/qunit/editor/tinymce/ui/img/raster.gif | Bin 56 -> 0 bytes tests/qunit/editor/tinymce/undo/Diff.js | 17 - .../editor/tinymce/undo/ForcedRootBlock.js | 54 - tests/qunit/editor/tinymce/undo/Fragments.js | 32 - tests/qunit/editor/tinymce/undo/Levels.js | 142 - tests/qunit/editor/tinymce/util/Color.js | 36 - tests/qunit/editor/tinymce/util/Delay.js | 130 - .../editor/tinymce/util/EventDispatcher.js | 255 -- tests/qunit/editor/tinymce/util/Fun.js | 49 - tests/qunit/editor/tinymce/util/I18n.js | 89 - tests/qunit/editor/tinymce/util/JSON.js | 31 - .../qunit/editor/tinymce/util/JSONRequest.js | 55 - .../qunit/editor/tinymce/util/LocalStorage.js | 99 - tests/qunit/editor/tinymce/util/Observable.js | 46 - tests/qunit/editor/tinymce/util/Promise.js | 40 - .../editor/tinymce/util/Quirks_webkit.js | 360 --- tests/qunit/editor/tinymce/util/Tools.js | 8 - tests/qunit/editor/tinymce/util/URI.js | 118 - tests/qunit/editor/tinymce/util/XHR.js | 38 - .../editor/tinymce/util/json_rpc_error.js | 1 - .../qunit/editor/tinymce/util/json_rpc_ok.js | 1 - tests/qunit/editor/tinymce/util/test.xml | 6 - tests/qunit/index.html | 2 +- .../js/tinymce/tinymce-obsolete.js | 286 ++ 116 files changed, 287 insertions(+), 25674 deletions(-) delete mode 100644 tests/qunit/editor/external-plugins/noneditable/plugin.js delete mode 100644 tests/qunit/editor/external-plugins/noneditable/plugin.min.js delete mode 100644 tests/qunit/editor/index.html delete mode 100644 tests/qunit/editor/js/init.js delete mode 100644 tests/qunit/editor/js/module_loader.js delete mode 100644 tests/qunit/editor/js/qunit/QUnit.LICENSE delete mode 100644 tests/qunit/editor/js/qunit/qunit.css delete mode 100644 tests/qunit/editor/js/qunit/qunit.js delete mode 100644 tests/qunit/editor/js/runner.js delete mode 100644 tests/qunit/editor/js/tinymce_loader.js delete mode 100644 tests/qunit/editor/js/utils.js delete mode 100644 tests/qunit/editor/tinymce/AddOnManager.js delete mode 100644 tests/qunit/editor/tinymce/Editor.js delete mode 100644 tests/qunit/editor/tinymce/EditorCommands.js delete mode 100644 tests/qunit/editor/tinymce/EditorCustomTheme.js delete mode 100644 tests/qunit/editor/tinymce/EditorManager.js delete mode 100644 tests/qunit/editor/tinymce/EditorUpload.js delete mode 100644 tests/qunit/editor/tinymce/Editor_rtl.js delete mode 100644 tests/qunit/editor/tinymce/EnterKey.js delete mode 100644 tests/qunit/editor/tinymce/FocusManager.js delete mode 100644 tests/qunit/editor/tinymce/ForceBlocks.js delete mode 100644 tests/qunit/editor/tinymce/Formatter_apply.js delete mode 100644 tests/qunit/editor/tinymce/Formatter_check.js delete mode 100644 tests/qunit/editor/tinymce/Formatter_remove.js delete mode 100644 tests/qunit/editor/tinymce/InsertContent.js delete mode 100644 tests/qunit/editor/tinymce/InsertContentForcedRootFalse.js delete mode 100644 tests/qunit/editor/tinymce/InsertList.js delete mode 100644 tests/qunit/editor/tinymce/NotificationManager.js delete mode 100644 tests/qunit/editor/tinymce/SelectionOverrides.js delete mode 100644 tests/qunit/editor/tinymce/Shortcuts.js delete mode 100644 tests/qunit/editor/tinymce/UndoManager.js delete mode 100644 tests/qunit/editor/tinymce/WindowManager.js delete mode 100644 tests/qunit/editor/tinymce/caret/CaretBookmark.js delete mode 100644 tests/qunit/editor/tinymce/caret/CaretCandidate.js delete mode 100644 tests/qunit/editor/tinymce/caret/CaretContainer.js delete mode 100644 tests/qunit/editor/tinymce/caret/CaretPosition.js delete mode 100644 tests/qunit/editor/tinymce/caret/CaretUtils.js delete mode 100644 tests/qunit/editor/tinymce/caret/CaretWalker.js delete mode 100644 tests/qunit/editor/tinymce/caret/FakeCaret.js delete mode 100644 tests/qunit/editor/tinymce/caret/LineUtils.js delete mode 100644 tests/qunit/editor/tinymce/caret/LineWalker.js delete mode 100644 tests/qunit/editor/tinymce/content/LinkTargets.js delete mode 100644 tests/qunit/editor/tinymce/data/ObservableObject.js delete mode 100644 tests/qunit/editor/tinymce/dom/DOMUtils.js delete mode 100644 tests/qunit/editor/tinymce/dom/Dimensions.js delete mode 100644 tests/qunit/editor/tinymce/dom/DomQuery.js delete mode 100644 tests/qunit/editor/tinymce/dom/EventUtils.js delete mode 100644 tests/qunit/editor/tinymce/dom/NodePath.js delete mode 100644 tests/qunit/editor/tinymce/dom/NodeType.js delete mode 100644 tests/qunit/editor/tinymce/dom/Range.js delete mode 100644 tests/qunit/editor/tinymce/dom/Selection.js delete mode 100644 tests/qunit/editor/tinymce/dom/Serializer.js delete mode 100644 tests/qunit/editor/tinymce/dom/TreeWalker.js delete mode 100644 tests/qunit/editor/tinymce/dom/TridentSelection.js delete mode 100644 tests/qunit/editor/tinymce/dom/test.css delete mode 100644 tests/qunit/editor/tinymce/file/Conversions.js delete mode 100644 tests/qunit/editor/tinymce/file/ImageScanner.js delete mode 100644 tests/qunit/editor/tinymce/file/UploadStatus.js delete mode 100644 tests/qunit/editor/tinymce/fmt/FontInfo.js delete mode 100644 tests/qunit/editor/tinymce/fmt/Hooks.js delete mode 100644 tests/qunit/editor/tinymce/fmt/Preview.js delete mode 100644 tests/qunit/editor/tinymce/geom/ClientRect.js delete mode 100644 tests/qunit/editor/tinymce/geom/Rect.js delete mode 100644 tests/qunit/editor/tinymce/html/DomParser.js delete mode 100644 tests/qunit/editor/tinymce/html/Entities.js delete mode 100644 tests/qunit/editor/tinymce/html/Node.js delete mode 100644 tests/qunit/editor/tinymce/html/Obsolete.js delete mode 100644 tests/qunit/editor/tinymce/html/SaxParser.js delete mode 100644 tests/qunit/editor/tinymce/html/Schema.js delete mode 100644 tests/qunit/editor/tinymce/html/Serializer.js delete mode 100644 tests/qunit/editor/tinymce/html/Styles.js delete mode 100644 tests/qunit/editor/tinymce/html/Writer.js delete mode 100644 tests/qunit/editor/tinymce/options.js delete mode 100644 tests/qunit/editor/tinymce/text/ExtendingChar.js delete mode 100644 tests/qunit/editor/tinymce/text/Zwsp.js delete mode 100644 tests/qunit/editor/tinymce/ui/AbsoluteLayout.js delete mode 100644 tests/qunit/editor/tinymce/ui/Button.js delete mode 100644 tests/qunit/editor/tinymce/ui/Collection.js delete mode 100644 tests/qunit/editor/tinymce/ui/ColorButton.js delete mode 100644 tests/qunit/editor/tinymce/ui/Control.js delete mode 100644 tests/qunit/editor/tinymce/ui/FilePicker.js delete mode 100644 tests/qunit/editor/tinymce/ui/FitLayout.js delete mode 100644 tests/qunit/editor/tinymce/ui/FlexLayout.js delete mode 100644 tests/qunit/editor/tinymce/ui/GridLayout.js delete mode 100644 tests/qunit/editor/tinymce/ui/MenuButton.js delete mode 100644 tests/qunit/editor/tinymce/ui/Panel.js delete mode 100644 tests/qunit/editor/tinymce/ui/Selector.js delete mode 100644 tests/qunit/editor/tinymce/ui/SplitButton.js delete mode 100644 tests/qunit/editor/tinymce/ui/TabPanel.js delete mode 100644 tests/qunit/editor/tinymce/ui/TextBox.js delete mode 100644 tests/qunit/editor/tinymce/ui/Window.js delete mode 100644 tests/qunit/editor/tinymce/ui/css/ui-overrides.css delete mode 100644 tests/qunit/editor/tinymce/ui/img/raster.gif delete mode 100644 tests/qunit/editor/tinymce/undo/Diff.js delete mode 100644 tests/qunit/editor/tinymce/undo/ForcedRootBlock.js delete mode 100644 tests/qunit/editor/tinymce/undo/Fragments.js delete mode 100644 tests/qunit/editor/tinymce/undo/Levels.js delete mode 100644 tests/qunit/editor/tinymce/util/Color.js delete mode 100644 tests/qunit/editor/tinymce/util/Delay.js delete mode 100644 tests/qunit/editor/tinymce/util/EventDispatcher.js delete mode 100644 tests/qunit/editor/tinymce/util/Fun.js delete mode 100644 tests/qunit/editor/tinymce/util/I18n.js delete mode 100644 tests/qunit/editor/tinymce/util/JSON.js delete mode 100644 tests/qunit/editor/tinymce/util/JSONRequest.js delete mode 100644 tests/qunit/editor/tinymce/util/LocalStorage.js delete mode 100644 tests/qunit/editor/tinymce/util/Observable.js delete mode 100644 tests/qunit/editor/tinymce/util/Promise.js delete mode 100644 tests/qunit/editor/tinymce/util/Quirks_webkit.js delete mode 100644 tests/qunit/editor/tinymce/util/Tools.js delete mode 100644 tests/qunit/editor/tinymce/util/URI.js delete mode 100644 tests/qunit/editor/tinymce/util/XHR.js delete mode 100644 tests/qunit/editor/tinymce/util/json_rpc_error.js delete mode 100644 tests/qunit/editor/tinymce/util/json_rpc_ok.js delete mode 100644 tests/qunit/editor/tinymce/util/test.xml create mode 100644 tests/qunit/wp-includes/js/tinymce/tinymce-obsolete.js 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 @@ - - - - - TinyMCE QUnit tests - - - - - - - - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/qunit/editor/js/init.js b/tests/qunit/editor/js/init.js deleted file mode 100644 index 0d47f0718d..0000000000 --- a/tests/qunit/editor/js/init.js +++ /dev/null @@ -1,122 +0,0 @@ -(function() { - var coverObjects = [], modulesExecuted = {}, log = [], currentModule; - - QUnit.config.reorder = false; - QUnit.config.hidepassed = true; - - window.editor = window.inlineEditor = null; - - var oldModule = module; - - QUnit.moduleStart(function(details) { - currentModule = details.name; - modulesExecuted[details.name] = true; - - tinymce.remove(); - document.getElementById('view').innerHTML = ''; - }); - - QUnit.moduleDone(function() { - tinymce.remove(); - window.editor = window.inlineEditor = null; - }); - - // Sauce labs - QUnit.testStart(function(testDetails) { - QUnit.log(function(details) { - if (!details.result) { - details.name = currentModule + ':' + testDetails.name; - log.push(details); - } - }); - }); - - QUnit.done(function(results) { - document.getElementById("view").style.display = 'none'; - - if (window.__$coverObject) { - coverObjects.push(window.__$coverObject); - - $('').on('click', function() { - window.open('coverage/index.html', 'coverage'); - }).appendTo(document.body); - } - - // Sauce labs - var tests = []; - for (var i = 0; i < log.length; i++) { - tests.push({ - name: log[i].name, - result: log[i].result, - expected: log[i].expected, - actual: log[i].actual, - source: log[i].source - }); - } - - results.tests = tests; - window.global_test_results = results; - }); - - window.module = function(name, settings) { - settings = settings || {}; - - if (settings.setupModule) { - QUnit.moduleStart(function(details) { - if (details.name == name) { - settings.setupModule(); - } - }); - } - - if (settings.teardownModule) { - QUnit.moduleDone(function(details) { - if (details.name == name) { - settings.teardownModule(); - } - }); - } - - oldModule(name, settings); - }; - - window.getCoverObject = function() { - var coverObject = {}, fileName, gaps, gap, count, targetModuleName; - var isScoped = document.location.search.indexOf('module=') != -1; - - for (var i = 0, length = coverObjects.length; i < length; i++) { - for (fileName in coverObjects[i]) { - gaps = coverObjects[i][fileName]; - - if (isScoped && fileName.indexOf('js/tinymce/classes') === 0) { - targetModuleName = "tinymce." + fileName.substr('js/tinymce/classes'.length + 1).replace(/\//g, '.'); - targetModuleName = targetModuleName.replace(/\.js$/, ''); - - if (!modulesExecuted[targetModuleName]) { - continue; - } - } - - if (!coverObject.hasOwnProperty(fileName)) { - coverObject[fileName] = gaps; - } else { - for (gap in gaps) { - if (gap === '__code') { - continue; - } - - count = gaps[gap]; - - if (!coverObject[fileName].hasOwnProperty(gap)) { - coverObject[fileName][gap] = count; - } else { - coverObject[fileName][gap] += count; - } - } - } - } - } - - return coverObject; - }; -})(); diff --git a/tests/qunit/editor/js/module_loader.js b/tests/qunit/editor/js/module_loader.js deleted file mode 100644 index 3bae8fb72e..0000000000 --- a/tests/qunit/editor/js/module_loader.js +++ /dev/null @@ -1,37 +0,0 @@ -(function(exports) { - exports.AMDLC_TESTS = true; - - function resolve(id) { - var i, target = exports, fragments = id.split(/[.\/]/); - - for (i = 0; i < fragments.length; i++) { - if (!target[fragments[i]]) { - return; - } - - target = target[fragments[i]]; - } - - return target; - } - - function require(ids, callback) { - var i, module, defs = [], privateModules = exports.privateModules || {}; - - for (i = 0; i < ids.length; i++) { - module = privateModules[ids[i]] || resolve(ids[i]); - - if (!module) { - throw 'module definition dependency not found: ' + ids[i]; - } - - defs.push(module); - } - - callback.apply(null, defs); - } - - exports.ModuleLoader = { - require: require - }; -})(this); diff --git a/tests/qunit/editor/js/qunit/QUnit.LICENSE b/tests/qunit/editor/js/qunit/QUnit.LICENSE deleted file mode 100644 index 1f718d9f29..0000000000 --- a/tests/qunit/editor/js/qunit/QUnit.LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2010 John Resig, http://jquery.com/ - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/tests/qunit/editor/js/qunit/qunit.css b/tests/qunit/editor/js/qunit/qunit.css deleted file mode 100644 index 93026e3ba3..0000000000 --- a/tests/qunit/editor/js/qunit/qunit.css +++ /dev/null @@ -1,237 +0,0 @@ -/*! - * QUnit 1.14.0 - * http://qunitjs.com/ - * - * Copyright 2013 jQuery Foundation and other contributors - * Released under the MIT license - * http://jquery.org/license - * - * Date: 2014-01-31T16:40Z - */ - -/** Font Family and Sizes */ - -#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { - font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; -} - -#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } -#qunit-tests { font-size: smaller; } - - -/** Resets */ - -#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { - margin: 0; - padding: 0; -} - - -/** Header */ - -#qunit-header { - padding: 0.5em 0 0.5em 1em; - - color: #8699A4; - background-color: #0D3349; - - font-size: 1.5em; - line-height: 1em; - font-weight: 400; - - border-radius: 5px 5px 0 0; -} - -#qunit-header a { - text-decoration: none; - color: #C2CCD1; -} - -#qunit-header a:hover, -#qunit-header a:focus { - color: #FFF; -} - -#qunit-testrunner-toolbar label { - display: inline-block; - padding: 0 0.5em 0 0.1em; -} - -#qunit-banner { - height: 5px; -} - -#qunit-testrunner-toolbar { - padding: 0.5em 0 0.5em 2em; - color: #5E740B; - background-color: #EEE; - overflow: hidden; -} - -#qunit-userAgent { - padding: 0.5em 0 0.5em 2.5em; - background-color: #2B81AF; - color: #FFF; - text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; -} - -#qunit-modulefilter-container { - float: right; -} - -/** Tests: Pass/Fail */ - -#qunit-tests { - list-style-position: inside; -} - -#qunit-tests li { - padding: 0.4em 0.5em 0.4em 2.5em; - border-bottom: 1px solid #FFF; - list-style-position: inside; -} - -#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { - display: none; -} - -#qunit-tests li strong { - cursor: pointer; -} - -#qunit-tests li a { - padding: 0.5em; - color: #C2CCD1; - text-decoration: none; -} -#qunit-tests li a:hover, -#qunit-tests li a:focus { - color: #000; -} - -#qunit-tests li .runtime { - float: right; - font-size: smaller; -} - -.qunit-assert-list { - margin-top: 0.5em; - padding: 0.5em; - - background-color: #FFF; - - border-radius: 5px; -} - -.qunit-collapsed { - display: none; -} - -#qunit-tests table { - border-collapse: collapse; - margin-top: 0.2em; -} - -#qunit-tests th { - text-align: right; - vertical-align: top; - padding: 0 0.5em 0 0; -} - -#qunit-tests td { - vertical-align: top; -} - -#qunit-tests pre { - margin: 0; - white-space: pre-wrap; - word-wrap: break-word; -} - -#qunit-tests del { - background-color: #E0F2BE; - color: #374E0C; - text-decoration: none; -} - -#qunit-tests ins { - background-color: #FFCACA; - color: #500; - text-decoration: none; -} - -/*** Test Counts */ - -#qunit-tests b.counts { color: #000; } -#qunit-tests b.passed { color: #5E740B; } -#qunit-tests b.failed { color: #710909; } - -#qunit-tests li li { - padding: 5px; - background-color: #FFF; - border-bottom: none; - list-style-position: inside; -} - -/*** Passing Styles */ - -#qunit-tests li li.pass { - color: #3C510C; - background-color: #FFF; - border-left: 10px solid #C6E746; -} - -#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } -#qunit-tests .pass .test-name { color: #366097; } - -#qunit-tests .pass .test-actual, -#qunit-tests .pass .test-expected { color: #999; } - -#qunit-banner.qunit-pass { background-color: #C6E746; } - -/*** Failing Styles */ - -#qunit-tests li li.fail { - color: #710909; - background-color: #FFF; - border-left: 10px solid #EE5757; - white-space: pre; -} - -#qunit-tests > li:last-child { - border-radius: 0 0 5px 5px; -} - -#qunit-tests .fail { color: #000; background-color: #EE5757; } -#qunit-tests .fail .test-name, -#qunit-tests .fail .module-name { color: #000; } - -#qunit-tests .fail .test-actual { color: #EE5757; } -#qunit-tests .fail .test-expected { color: #008000; } - -#qunit-banner.qunit-fail { background-color: #EE5757; } - - -/** Result */ - -#qunit-testresult { - padding: 0.5em 0.5em 0.5em 2.5em; - - color: #2B81AF; - background-color: #D2E0E6; - - border-bottom: 1px solid #FFF; -} -#qunit-testresult .module-name { - font-weight: 700; -} - -/** Fixture */ - -#qunit-fixture { - position: absolute; - top: -10000px; - left: -10000px; - width: 1000px; - height: 1000px; -} diff --git a/tests/qunit/editor/js/qunit/qunit.js b/tests/qunit/editor/js/qunit/qunit.js deleted file mode 100644 index 3aab2bb8fc..0000000000 --- a/tests/qunit/editor/js/qunit/qunit.js +++ /dev/null @@ -1,2293 +0,0 @@ -/*! - * QUnit 1.14.0 - * http://qunitjs.com/ - * - * Copyright 2013 jQuery Foundation and other contributors - * Released under the MIT license - * http://jquery.org/license - * - * Date: 2014-01-31T16:40Z - */ - -(function( window ) { - -var QUnit, - assert, - config, - onErrorFnPrev, - testId = 0, - fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""), - toString = Object.prototype.toString, - hasOwn = Object.prototype.hasOwnProperty, - // Keep a local reference to Date (GH-283) - Date = window.Date, - setTimeout = window.setTimeout, - clearTimeout = window.clearTimeout, - defined = { - document: typeof window.document !== "undefined", - setTimeout: typeof window.setTimeout !== "undefined", - sessionStorage: (function() { - var x = "qunit-test-string"; - try { - sessionStorage.setItem( x, x ); - sessionStorage.removeItem( x ); - return true; - } catch( e ) { - return false; - } - }()) - }, - /** - * Provides a normalized error string, correcting an issue - * with IE 7 (and prior) where Error.prototype.toString is - * not properly implemented - * - * Based on http://es5.github.com/#x15.11.4.4 - * - * @param {String|Error} error - * @return {String} error message - */ - errorString = function( error ) { - var name, message, - errorString = error.toString(); - if ( errorString.substring( 0, 7 ) === "[object" ) { - name = error.name ? error.name.toString() : "Error"; - message = error.message ? error.message.toString() : ""; - if ( name && message ) { - return name + ": " + message; - } else if ( name ) { - return name; - } else if ( message ) { - return message; - } else { - return "Error"; - } - } else { - return errorString; - } - }, - /** - * Makes a clone of an object using only Array or Object as base, - * and copies over the own enumerable properties. - * - * @param {Object} obj - * @return {Object} New object with only the own properties (recursively). - */ - objectValues = function( obj ) { - // Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392. - /*jshint newcap: false */ - var key, val, - vals = QUnit.is( "array", obj ) ? [] : {}; - for ( key in obj ) { - if ( hasOwn.call( obj, key ) ) { - val = obj[key]; - vals[key] = val === Object(val) ? objectValues(val) : val; - } - } - return vals; - }; - - -// Root QUnit object. -// `QUnit` initialized at top of scope -QUnit = { - - // call on start of module test to prepend name to all tests - module: function( name, testEnvironment ) { - config.currentModule = name; - config.currentModuleTestEnvironment = testEnvironment; - config.modules[name] = true; - }, - - asyncTest: function( testName, expected, callback ) { - if ( arguments.length === 2 ) { - callback = expected; - expected = null; - } - - QUnit.test( testName, expected, callback, true ); - }, - - test: function( testName, expected, callback, async ) { - var test, - nameHtml = "" + escapeText( testName ) + ""; - - if ( arguments.length === 2 ) { - callback = expected; - expected = null; - } - - if ( config.currentModule ) { - nameHtml = "" + escapeText( config.currentModule ) + ": " + nameHtml; - } - - test = new Test({ - nameHtml: nameHtml, - testName: testName, - expected: expected, - async: async, - callback: callback, - module: config.currentModule, - moduleTestEnvironment: config.currentModuleTestEnvironment, - stack: sourceFromStacktrace( 2 ) - }); - - if ( !validTest( test ) ) { - return; - } - - test.queue(); - }, - - // Specify the number of expected assertions to guarantee that failed test (no assertions are run at all) don't slip through. - expect: function( asserts ) { - if (arguments.length === 1) { - config.current.expected = asserts; - } else { - return config.current.expected; - } - }, - - start: function( count ) { - // QUnit hasn't been initialized yet. - // Note: RequireJS (et al) may delay onLoad - if ( config.semaphore === undefined ) { - QUnit.begin(function() { - // This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first - setTimeout(function() { - QUnit.start( count ); - }); - }); - return; - } - - config.semaphore -= count || 1; - // don't start until equal number of stop-calls - if ( config.semaphore > 0 ) { - return; - } - // ignore if start is called more often then stop - if ( config.semaphore < 0 ) { - config.semaphore = 0; - QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) ); - return; - } - // A slight delay, to avoid any current callbacks - if ( defined.setTimeout ) { - setTimeout(function() { - if ( config.semaphore > 0 ) { - return; - } - if ( config.timeout ) { - clearTimeout( config.timeout ); - } - - config.blocking = false; - process( true ); - }, 13); - } else { - config.blocking = false; - process( true ); - } - }, - - stop: function( count ) { - config.semaphore += count || 1; - config.blocking = true; - - if ( config.testTimeout && defined.setTimeout ) { - clearTimeout( config.timeout ); - config.timeout = setTimeout(function() { - QUnit.ok( false, "Test timed out" ); - config.semaphore = 1; - QUnit.start(); - }, config.testTimeout ); - } - } -}; - -// We use the prototype to distinguish between properties that should -// be exposed as globals (and in exports) and those that shouldn't -(function() { - function F() {} - F.prototype = QUnit; - QUnit = new F(); - // Make F QUnit's constructor so that we can add to the prototype later - QUnit.constructor = F; -}()); - -/** - * Config object: Maintain internal state - * Later exposed as QUnit.config - * `config` initialized at top of scope - */ -config = { - // The queue of tests to run - queue: [], - - // block until document ready - blocking: true, - - // when enabled, show only failing tests - // gets persisted through sessionStorage and can be changed in UI via checkbox - hidepassed: false, - - // by default, run previously failed tests first - // very useful in combination with "Hide passed tests" checked - reorder: true, - - // by default, modify document.title when suite is done - altertitle: true, - - // by default, scroll to top of the page when suite is done - scrolltop: true, - - // when enabled, all tests must call expect() - requireExpects: false, - - // add checkboxes that are persisted in the query-string - // when enabled, the id is set to `true` as a `QUnit.config` property - urlConfig: [ - { - id: "noglobals", - label: "Check for Globals", - tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." - }, - { - id: "notrycatch", - label: "No try-catch", - tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." - } - ], - - // Set of all modules. - modules: {}, - - // logging callback queues - begin: [], - done: [], - log: [], - testStart: [], - testDone: [], - moduleStart: [], - moduleDone: [] -}; - -// Initialize more QUnit.config and QUnit.urlParams -(function() { - var i, current, - location = window.location || { search: "", protocol: "file:" }, - params = location.search.slice( 1 ).split( "&" ), - length = params.length, - urlParams = {}; - - if ( params[ 0 ] ) { - for ( i = 0; i < length; i++ ) { - current = params[ i ].split( "=" ); - current[ 0 ] = decodeURIComponent( current[ 0 ] ); - - // allow just a key to turn on a flag, e.g., test.html?noglobals - current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; - if ( urlParams[ current[ 0 ] ] ) { - urlParams[ current[ 0 ] ] = [].concat( urlParams[ current[ 0 ] ], current[ 1 ] ); - } else { - urlParams[ current[ 0 ] ] = current[ 1 ]; - } - } - } - - QUnit.urlParams = urlParams; - - // String search anywhere in moduleName+testName - config.filter = urlParams.filter; - - // Exact match of the module name - config.module = urlParams.module; - - config.testNumber = []; - if ( urlParams.testNumber ) { - - // Ensure that urlParams.testNumber is an array - urlParams.testNumber = [].concat( urlParams.testNumber ); - for ( i = 0; i < urlParams.testNumber.length; i++ ) { - current = urlParams.testNumber[ i ]; - config.testNumber.push( parseInt( current, 10 ) ); - } - } - - // Figure out if we're running the tests from a server or not - QUnit.isLocal = location.protocol === "file:"; -}()); - -extend( QUnit, { - - config: config, - - // Initialize the configuration options - init: function() { - extend( config, { - stats: { all: 0, bad: 0 }, - moduleStats: { all: 0, bad: 0 }, - started: +new Date(), - updateRate: 1000, - blocking: false, - autostart: true, - autorun: false, - filter: "", - queue: [], - semaphore: 1 - }); - - var tests, banner, result, - qunit = id( "qunit" ); - - if ( qunit ) { - qunit.innerHTML = - "

" + escapeText( document.title ) + "

" + - "

" + - "
" + - "

" + - "
    "; - } - - tests = id( "qunit-tests" ); - banner = id( "qunit-banner" ); - result = id( "qunit-testresult" ); - - if ( tests ) { - tests.innerHTML = ""; - } - - if ( banner ) { - banner.className = ""; - } - - if ( result ) { - result.parentNode.removeChild( result ); - } - - if ( tests ) { - result = document.createElement( "p" ); - result.id = "qunit-testresult"; - result.className = "result"; - tests.parentNode.insertBefore( result, tests ); - result.innerHTML = "Running...
     "; - } - }, - - // Resets the test setup. Useful for tests that modify the DOM. - /* - DEPRECATED: Use multiple tests instead of resetting inside a test. - Use testStart or testDone for custom cleanup. - This method will throw an error in 2.0, and will be removed in 2.1 - */ - reset: function() { - var fixture = id( "qunit-fixture" ); - if ( fixture ) { - fixture.innerHTML = config.fixture; - } - }, - - // Safe object type checking - is: function( type, obj ) { - return QUnit.objectType( obj ) === type; - }, - - objectType: function( obj ) { - if ( typeof obj === "undefined" ) { - return "undefined"; - } - - // Consider: typeof null === object - if ( obj === null ) { - return "null"; - } - - var match = toString.call( obj ).match(/^\[object\s(.*)\]$/), - type = match && match[1] || ""; - - switch ( type ) { - case "Number": - if ( isNaN(obj) ) { - return "nan"; - } - return "number"; - case "String": - case "Boolean": - case "Array": - case "Date": - case "RegExp": - case "Function": - return type.toLowerCase(); - } - if ( typeof obj === "object" ) { - return "object"; - } - return undefined; - }, - - push: function( result, actual, expected, message ) { - if ( !config.current ) { - throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); - } - - var output, source, - details = { - module: config.current.module, - name: config.current.testName, - result: result, - message: message, - actual: actual, - expected: expected - }; - - message = escapeText( message ) || ( result ? "okay" : "failed" ); - message = "" + message + ""; - output = message; - - if ( !result ) { - expected = escapeText( QUnit.jsDump.parse(expected) ); - actual = escapeText( QUnit.jsDump.parse(actual) ); - output += ""; - - if ( actual !== expected ) { - output += ""; - output += ""; - } - - source = sourceFromStacktrace(); - - if ( source ) { - details.source = source; - output += ""; - } - - output += "
    Expected:
    " + expected + "
    Result:
    " + actual + "
    Diff:
    " + QUnit.diff( expected, actual ) + "
    Source:
    " + escapeText( source ) + "
    "; - } - - runLoggingCallbacks( "log", QUnit, details ); - - config.current.assertions.push({ - result: !!result, - message: output - }); - }, - - pushFailure: function( message, source, actual ) { - if ( !config.current ) { - throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); - } - - var output, - details = { - module: config.current.module, - name: config.current.testName, - result: false, - message: message - }; - - message = escapeText( message ) || "error"; - message = "" + message + ""; - output = message; - - output += ""; - - if ( actual ) { - output += ""; - } - - if ( source ) { - details.source = source; - output += ""; - } - - output += "
    Result:
    " + escapeText( actual ) + "
    Source:
    " + escapeText( source ) + "
    "; - - runLoggingCallbacks( "log", QUnit, details ); - - config.current.assertions.push({ - result: false, - message: output - }); - }, - - url: function( params ) { - params = extend( extend( {}, QUnit.urlParams ), params ); - var key, - querystring = "?"; - - for ( key in params ) { - if ( hasOwn.call( params, key ) ) { - querystring += encodeURIComponent( key ) + "=" + - encodeURIComponent( params[ key ] ) + "&"; - } - } - return window.location.protocol + "//" + window.location.host + - window.location.pathname + querystring.slice( 0, -1 ); - }, - - extend: extend, - id: id, - addEvent: addEvent, - addClass: addClass, - hasClass: hasClass, - removeClass: removeClass - // load, equiv, jsDump, diff: Attached later -}); - -/** - * @deprecated: Created for backwards compatibility with test runner that set the hook function - * into QUnit.{hook}, instead of invoking it and passing the hook function. - * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. - * Doing this allows us to tell if the following methods have been overwritten on the actual - * QUnit object. - */ -extend( QUnit.constructor.prototype, { - - // Logging callbacks; all receive a single argument with the listed properties - // run test/logs.html for any related changes - begin: registerLoggingCallback( "begin" ), - - // done: { failed, passed, total, runtime } - done: registerLoggingCallback( "done" ), - - // log: { result, actual, expected, message } - log: registerLoggingCallback( "log" ), - - // testStart: { name } - testStart: registerLoggingCallback( "testStart" ), - - // testDone: { name, failed, passed, total, runtime } - testDone: registerLoggingCallback( "testDone" ), - - // moduleStart: { name } - moduleStart: registerLoggingCallback( "moduleStart" ), - - // moduleDone: { name, failed, passed, total } - moduleDone: registerLoggingCallback( "moduleDone" ) -}); - -if ( !defined.document || document.readyState === "complete" ) { - config.autorun = true; -} - -if (document.location.search.indexOf('bedrock') !== -1) { - config.autorun = false; - config.autostart = false; -} - -QUnit.load = function() { - runLoggingCallbacks( "begin", QUnit, {} ); - - // Initialize the config, saving the execution queue - var banner, filter, i, j, label, len, main, ol, toolbar, val, selection, - urlConfigContainer, moduleFilter, userAgent, - numModules = 0, - moduleNames = [], - moduleFilterHtml = "", - urlConfigHtml = "", - oldconfig = extend( {}, config ); - - QUnit.init(); - extend(config, oldconfig); - - config.blocking = false; - - len = config.urlConfig.length; - - for ( i = 0; i < len; i++ ) { - val = config.urlConfig[i]; - if ( typeof val === "string" ) { - val = { - id: val, - label: val - }; - } - config[ val.id ] = QUnit.urlParams[ val.id ]; - if ( !val.value || typeof val.value === "string" ) { - urlConfigHtml += ""; - } else { - urlConfigHtml += ""; - } - } - for ( i in config.modules ) { - if ( config.modules.hasOwnProperty( i ) ) { - moduleNames.push(i); - } - } - numModules = moduleNames.length; - moduleNames.sort( function( a, b ) { - return a.localeCompare( b ); - }); - moduleFilterHtml += ""; - - // `userAgent` initialized at top of scope - userAgent = id( "qunit-userAgent" ); - if ( userAgent ) { - userAgent.innerHTML = navigator.userAgent; - } - - // `banner` initialized at top of scope - banner = id( "qunit-header" ); - if ( banner ) { - banner.innerHTML = "" + banner.innerHTML + " "; - } - - // `toolbar` initialized at top of scope - toolbar = id( "qunit-testrunner-toolbar" ); - if ( toolbar ) { - // `filter` initialized at top of scope - filter = document.createElement( "input" ); - filter.type = "checkbox"; - filter.id = "qunit-filter-pass"; - - addEvent( filter, "click", function() { - var tmp, - ol = id( "qunit-tests" ); - - if ( filter.checked ) { - ol.className = ol.className + " hidepass"; - } else { - tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; - ol.className = tmp.replace( / hidepass /, " " ); - } - if ( defined.sessionStorage ) { - if (filter.checked) { - sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); - } else { - sessionStorage.removeItem( "qunit-filter-passed-tests" ); - } - } - }); - - if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { - filter.checked = true; - // `ol` initialized at top of scope - ol = id( "qunit-tests" ); - ol.className = ol.className + " hidepass"; - } - toolbar.appendChild( filter ); - - // `label` initialized at top of scope - label = document.createElement( "label" ); - label.setAttribute( "for", "qunit-filter-pass" ); - label.setAttribute( "title", "Only show tests and assertions that fail. Stored in sessionStorage." ); - label.innerHTML = "Hide passed tests"; - toolbar.appendChild( label ); - - urlConfigContainer = document.createElement("span"); - urlConfigContainer.innerHTML = urlConfigHtml; - // For oldIE support: - // * Add handlers to the individual elements instead of the container - // * Use "click" instead of "change" for checkboxes - // * Fallback from event.target to event.srcElement - addEvents( urlConfigContainer.getElementsByTagName("input"), "click", function( event ) { - var params = {}, - target = event.target || event.srcElement; - params[ target.name ] = target.checked ? - target.defaultValue || true : - undefined; - window.location = QUnit.url( params ); - }); - addEvents( urlConfigContainer.getElementsByTagName("select"), "change", function( event ) { - var params = {}, - target = event.target || event.srcElement; - params[ target.name ] = target.options[ target.selectedIndex ].value || undefined; - window.location = QUnit.url( params ); - }); - toolbar.appendChild( urlConfigContainer ); - - if (numModules > 1) { - moduleFilter = document.createElement( "span" ); - moduleFilter.setAttribute( "id", "qunit-modulefilter-container" ); - moduleFilter.innerHTML = moduleFilterHtml; - addEvent( moduleFilter.lastChild, "change", function() { - var selectBox = moduleFilter.getElementsByTagName("select")[0], - selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value); - - window.location = QUnit.url({ - module: ( selectedModule === "" ) ? undefined : selectedModule, - // Remove any existing filters - filter: undefined, - testNumber: undefined - }); - }); - toolbar.appendChild(moduleFilter); - } - } - - // `main` initialized at top of scope - main = id( "qunit-fixture" ); - if ( main ) { - config.fixture = main.innerHTML; - } - - if ( config.autostart ) { - QUnit.start(); - } -}; - -if ( defined.document ) { - addEvent( window, "load", QUnit.load ); -} - -// `onErrorFnPrev` initialized at top of scope -// Preserve other handlers -onErrorFnPrev = window.onerror; - -// Cover uncaught exceptions -// Returning true will suppress the default browser handler, -// returning false will let it run. -window.onerror = function ( error, filePath, linerNr ) { - var ret = false; - if ( onErrorFnPrev ) { - ret = onErrorFnPrev( error, filePath, linerNr ); - } - - // Treat return value as window.onerror itself does, - // Only do our handling if not suppressed. - if ( ret !== true ) { - if ( QUnit.config.current ) { - if ( QUnit.config.current.ignoreGlobalErrors ) { - return true; - } - QUnit.pushFailure( error, filePath + ":" + linerNr ); - } else { - QUnit.test( "global failure", extend( function() { - QUnit.pushFailure( error, filePath + ":" + linerNr ); - }, { validTest: validTest } ) ); - } - return false; - } - - return ret; -}; - -function done() { - config.autorun = true; - - // Log the last module results - if ( config.previousModule ) { - runLoggingCallbacks( "moduleDone", QUnit, { - name: config.previousModule, - failed: config.moduleStats.bad, - passed: config.moduleStats.all - config.moduleStats.bad, - total: config.moduleStats.all - }); - } - delete config.previousModule; - - var i, key, - banner = id( "qunit-banner" ), - tests = id( "qunit-tests" ), - runtime = +new Date() - config.started, - passed = config.stats.all - config.stats.bad, - html = [ - "Tests completed in ", - runtime, - " milliseconds.
    ", - "", - passed, - " assertions of ", - config.stats.all, - " passed, ", - config.stats.bad, - " failed." - ].join( "" ); - - if ( banner ) { - banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); - } - - if ( tests ) { - id( "qunit-testresult" ).innerHTML = html; - } - - if ( config.altertitle && defined.document && document.title ) { - // show ✖ for good, ✔ for bad suite result in title - // use escape sequences in case file gets loaded with non-utf-8-charset - document.title = [ - ( config.stats.bad ? "\u2716" : "\u2714" ), - document.title.replace( /^[\u2714\u2716] /i, "" ) - ].join( " " ); - } - - // clear own sessionStorage items if all tests passed - if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { - // `key` & `i` initialized at top of scope - for ( i = 0; i < sessionStorage.length; i++ ) { - key = sessionStorage.key( i++ ); - if ( key.indexOf( "qunit-test-" ) === 0 ) { - sessionStorage.removeItem( key ); - } - } - } - - // scroll back to top to show results - if ( config.scrolltop && window.scrollTo ) { - window.scrollTo(0, 0); - } - - runLoggingCallbacks( "done", QUnit, { - failed: config.stats.bad, - passed: passed, - total: config.stats.all, - runtime: runtime - }); -} - -/** @return Boolean: true if this test should be ran */ -function validTest( test ) { - var include, - filter = config.filter && config.filter.toLowerCase(), - module = config.module && config.module.toLowerCase(), - fullName = ( test.module + ": " + test.testName ).toLowerCase(); - - // Internally-generated tests are always valid - if ( test.callback && test.callback.validTest === validTest ) { - delete test.callback.validTest; - return true; - } - - if ( config.testNumber.length > 0 ) { - if ( inArray( test.testNumber, config.testNumber ) < 0 ) { - return false; - } - } - - if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { - return false; - } - - if ( !filter ) { - return true; - } - - include = filter.charAt( 0 ) !== "!"; - if ( !include ) { - filter = filter.slice( 1 ); - } - - // If the filter matches, we need to honour include - if ( fullName.indexOf( filter ) !== -1 ) { - return include; - } - - // Otherwise, do the opposite - return !include; -} - -// so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) -// Later Safari and IE10 are supposed to support error.stack as well -// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack -function extractStacktrace( e, offset ) { - offset = offset === undefined ? 3 : offset; - - var stack, include, i; - - if ( e.stacktrace ) { - // Opera - return e.stacktrace.split( "\n" )[ offset + 3 ]; - } else if ( e.stack ) { - // Firefox, Chrome - stack = e.stack.split( "\n" ); - if (/^error$/i.test( stack[0] ) ) { - stack.shift(); - } - if ( fileName ) { - include = []; - for ( i = offset; i < stack.length; i++ ) { - if ( stack[ i ].indexOf( fileName ) !== -1 ) { - break; - } - include.push( stack[ i ] ); - } - if ( include.length ) { - return include.join( "\n" ); - } - } - return stack[ offset ]; - } else if ( e.sourceURL ) { - // Safari, PhantomJS - // hopefully one day Safari provides actual stacktraces - // exclude useless self-reference for generated Error objects - if ( /qunit.js$/.test( e.sourceURL ) ) { - return; - } - // for actual exceptions, this is useful - return e.sourceURL + ":" + e.line; - } -} -function sourceFromStacktrace( offset ) { - try { - throw new Error(); - } catch ( e ) { - return extractStacktrace( e, offset ); - } -} - -/** - * Escape text for attribute or text content. - */ -function escapeText( s ) { - if ( !s ) { - return ""; - } - s = s + ""; - // Both single quotes and double quotes (for attributes) - return s.replace( /['"<>&]/g, function( s ) { - switch( s ) { - case "'": - return "'"; - case "\"": - return """; - case "<": - return "<"; - case ">": - return ">"; - case "&": - return "&"; - } - }); -} - -function synchronize( callback, last ) { - config.queue.push( callback ); - - if ( config.autorun && !config.blocking ) { - process( last ); - } -} - -function process( last ) { - function next() { - process( last ); - } - var start = new Date().getTime(); - config.depth = config.depth ? config.depth + 1 : 1; - - while ( config.queue.length && !config.blocking ) { - if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { - config.queue.shift()(); - } else { - setTimeout( next, 13 ); - break; - } - } - config.depth--; - if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { - done(); - } -} - -function saveGlobal() { - config.pollution = []; - - if ( config.noglobals ) { - for ( var key in window ) { - if ( hasOwn.call( window, key ) ) { - // in Opera sometimes DOM element ids show up here, ignore them - if ( /^qunit-test-output/.test( key ) ) { - continue; - } - config.pollution.push( key ); - } - } - } -} - -function checkPollution() { - var newGlobals, - deletedGlobals, - old = config.pollution; - - saveGlobal(); - - newGlobals = diff( config.pollution, old ); - if ( newGlobals.length > 0 ) { - QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); - } - - deletedGlobals = diff( old, config.pollution ); - if ( deletedGlobals.length > 0 ) { - QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); - } -} - -// returns a new Array with the elements that are in a but not in b -function diff( a, b ) { - var i, j, - result = a.slice(); - - for ( i = 0; i < result.length; i++ ) { - for ( j = 0; j < b.length; j++ ) { - if ( result[i] === b[j] ) { - result.splice( i, 1 ); - i--; - break; - } - } - } - return result; -} - -function extend( a, b ) { - for ( var prop in b ) { - if ( hasOwn.call( b, prop ) ) { - // Avoid "Member not found" error in IE8 caused by messing with window.constructor - if ( !( prop === "constructor" && a === window ) ) { - if ( b[ prop ] === undefined ) { - delete a[ prop ]; - } else { - a[ prop ] = b[ prop ]; - } - } - } - } - - return a; -} - -/** - * @param {HTMLElement} elem - * @param {string} type - * @param {Function} fn - */ -function addEvent( elem, type, fn ) { - if ( elem.addEventListener ) { - - // Standards-based browsers - elem.addEventListener( type, fn, false ); - } else if ( elem.attachEvent ) { - - // support: IE <9 - elem.attachEvent( "on" + type, fn ); - } else { - - // Caller must ensure support for event listeners is present - throw new Error( "addEvent() was called in a context without event listener support" ); - } -} - -/** - * @param {Array|NodeList} elems - * @param {string} type - * @param {Function} fn - */ -function addEvents( elems, type, fn ) { - var i = elems.length; - while ( i-- ) { - addEvent( elems[i], type, fn ); - } -} - -function hasClass( elem, name ) { - return (" " + elem.className + " ").indexOf(" " + name + " ") > -1; -} - -function addClass( elem, name ) { - if ( !hasClass( elem, name ) ) { - elem.className += (elem.className ? " " : "") + name; - } -} - -function removeClass( elem, name ) { - var set = " " + elem.className + " "; - // Class name may appear multiple times - while ( set.indexOf(" " + name + " ") > -1 ) { - set = set.replace(" " + name + " " , " "); - } - // If possible, trim it for prettiness, but not necessarily - elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, ""); -} - -function id( name ) { - return defined.document && document.getElementById && document.getElementById( name ); -} - -function registerLoggingCallback( key ) { - return function( callback ) { - config[key].push( callback ); - }; -} - -// Supports deprecated method of completely overwriting logging callbacks -function runLoggingCallbacks( key, scope, args ) { - var i, callbacks; - if ( QUnit.hasOwnProperty( key ) ) { - QUnit[ key ].call(scope, args ); - } else { - callbacks = config[ key ]; - for ( i = 0; i < callbacks.length; i++ ) { - callbacks[ i ].call( scope, args ); - } - } -} - -// from jquery.js -function inArray( elem, array ) { - if ( array.indexOf ) { - return array.indexOf( elem ); - } - - for ( var i = 0, length = array.length; i < length; i++ ) { - if ( array[ i ] === elem ) { - return i; - } - } - - return -1; -} - -function Test( settings ) { - extend( this, settings ); - this.assertions = []; - this.testNumber = ++Test.count; -} - -Test.count = 0; - -Test.prototype = { - init: function() { - var a, b, li, - tests = id( "qunit-tests" ); - - if ( tests ) { - b = document.createElement( "strong" ); - b.innerHTML = this.nameHtml; - - // `a` initialized at top of scope - a = document.createElement( "a" ); - a.innerHTML = "Rerun"; - a.href = QUnit.url({ testNumber: this.testNumber }); - - li = document.createElement( "li" ); - li.appendChild( b ); - li.appendChild( a ); - li.className = "running"; - li.id = this.id = "qunit-test-output" + testId++; - - tests.appendChild( li ); - } - }, - setup: function() { - if ( - // Emit moduleStart when we're switching from one module to another - this.module !== config.previousModule || - // They could be equal (both undefined) but if the previousModule property doesn't - // yet exist it means this is the first test in a suite that isn't wrapped in a - // module, in which case we'll just emit a moduleStart event for 'undefined'. - // Without this, reporters can get testStart before moduleStart which is a problem. - !hasOwn.call( config, "previousModule" ) - ) { - if ( hasOwn.call( config, "previousModule" ) ) { - runLoggingCallbacks( "moduleDone", QUnit, { - name: config.previousModule, - failed: config.moduleStats.bad, - passed: config.moduleStats.all - config.moduleStats.bad, - total: config.moduleStats.all - }); - } - config.previousModule = this.module; - config.moduleStats = { all: 0, bad: 0 }; - runLoggingCallbacks( "moduleStart", QUnit, { - name: this.module - }); - } - - config.current = this; - - this.testEnvironment = extend({ - setup: function() {}, - teardown: function() {} - }, this.moduleTestEnvironment ); - - this.started = +new Date(); - runLoggingCallbacks( "testStart", QUnit, { - name: this.testName, - module: this.module - }); - - /*jshint camelcase:false */ - - - /** - * Expose the current test environment. - * - * @deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead. - */ - QUnit.current_testEnvironment = this.testEnvironment; - - /*jshint camelcase:true */ - - if ( !config.pollution ) { - saveGlobal(); - } - if ( config.notrycatch ) { - this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); - return; - } - try { - this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); - } catch( e ) { - QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); - } - }, - run: function() { - config.current = this; - - var running = id( "qunit-testresult" ); - - if ( running ) { - running.innerHTML = "Running:
    " + this.nameHtml; - } - - if ( this.async ) { - QUnit.stop(); - } - - this.callbackStarted = +new Date(); - - if ( config.notrycatch ) { - this.callback.call( this.testEnvironment, QUnit.assert ); - this.callbackRuntime = +new Date() - this.callbackStarted; - return; - } - - try { - this.callback.call( this.testEnvironment, QUnit.assert ); - this.callbackRuntime = +new Date() - this.callbackStarted; - } catch( e ) { - this.callbackRuntime = +new Date() - this.callbackStarted; - - QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) ); - // else next test will carry the responsibility - saveGlobal(); - - // Restart the tests if they're blocking - if ( config.blocking ) { - QUnit.start(); - } - } - }, - teardown: function() { - config.current = this; - if ( config.notrycatch ) { - if ( typeof this.callbackRuntime === "undefined" ) { - this.callbackRuntime = +new Date() - this.callbackStarted; - } - this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); - return; - } else { - try { - this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); - } catch( e ) { - QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); - } - } - checkPollution(); - }, - finish: function() { - config.current = this; - if ( config.requireExpects && this.expected === null ) { - QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack ); - } else if ( this.expected !== null && this.expected !== this.assertions.length ) { - QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack ); - } else if ( this.expected === null && !this.assertions.length ) { - QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack ); - } - - var i, assertion, a, b, time, li, ol, - test = this, - good = 0, - bad = 0, - tests = id( "qunit-tests" ); - - this.runtime = +new Date() - this.started; - config.stats.all += this.assertions.length; - config.moduleStats.all += this.assertions.length; - - if ( tests ) { - ol = document.createElement( "ol" ); - ol.className = "qunit-assert-list"; - - for ( i = 0; i < this.assertions.length; i++ ) { - assertion = this.assertions[i]; - - li = document.createElement( "li" ); - li.className = assertion.result ? "pass" : "fail"; - li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); - ol.appendChild( li ); - - if ( assertion.result ) { - good++; - } else { - bad++; - config.stats.bad++; - config.moduleStats.bad++; - } - } - - // store result when possible - if ( QUnit.config.reorder && defined.sessionStorage ) { - if ( bad ) { - sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); - } else { - sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); - } - } - - if ( bad === 0 ) { - addClass( ol, "qunit-collapsed" ); - } - - // `b` initialized at top of scope - b = document.createElement( "strong" ); - b.innerHTML = this.nameHtml + " (" + bad + ", " + good + ", " + this.assertions.length + ")"; - - addEvent(b, "click", function() { - var next = b.parentNode.lastChild, - collapsed = hasClass( next, "qunit-collapsed" ); - ( collapsed ? removeClass : addClass )( next, "qunit-collapsed" ); - }); - - addEvent(b, "dblclick", function( e ) { - var target = e && e.target ? e.target : window.event.srcElement; - if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { - target = target.parentNode; - } - if ( window.location && target.nodeName.toLowerCase() === "strong" ) { - window.location = QUnit.url({ testNumber: test.testNumber }); - } - }); - - // `time` initialized at top of scope - time = document.createElement( "span" ); - time.className = "runtime"; - time.innerHTML = this.runtime + " ms"; - - // `li` initialized at top of scope - li = id( this.id ); - li.className = bad ? "fail" : "pass"; - li.removeChild( li.firstChild ); - a = li.firstChild; - li.appendChild( b ); - li.appendChild( a ); - li.appendChild( time ); - li.appendChild( ol ); - - } else { - for ( i = 0; i < this.assertions.length; i++ ) { - if ( !this.assertions[i].result ) { - bad++; - config.stats.bad++; - config.moduleStats.bad++; - } - } - } - - runLoggingCallbacks( "testDone", QUnit, { - name: this.testName, - module: this.module, - failed: bad, - passed: this.assertions.length - bad, - total: this.assertions.length, - runtime: this.runtime, - // DEPRECATED: this property will be removed in 2.0.0, use runtime instead - duration: this.runtime - }); - - QUnit.reset(); - - config.current = undefined; - }, - - queue: function() { - var bad, - test = this; - - synchronize(function() { - test.init(); - }); - function run() { - // each of these can by async - synchronize(function() { - test.setup(); - }); - synchronize(function() { - test.run(); - }); - synchronize(function() { - test.teardown(); - }); - synchronize(function() { - test.finish(); - }); - } - - // `bad` initialized at top of scope - // defer when previous test run passed, if storage is available - bad = QUnit.config.reorder && defined.sessionStorage && - +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); - - if ( bad ) { - run(); - } else { - synchronize( run, true ); - } - } -}; - -// `assert` initialized at top of scope -// Assert helpers -// All of these must either call QUnit.push() or manually do: -// - runLoggingCallbacks( "log", .. ); -// - config.current.assertions.push({ .. }); -assert = QUnit.assert = { - /** - * Asserts rough true-ish result. - * @name ok - * @function - * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); - */ - ok: function( result, msg ) { - if ( !config.current ) { - throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); - } - result = !!result; - msg = msg || ( result ? "okay" : "failed" ); - - var source, - details = { - module: config.current.module, - name: config.current.testName, - result: result, - message: msg - }; - - msg = "" + escapeText( msg ) + ""; - - if ( !result ) { - source = sourceFromStacktrace( 2 ); - if ( source ) { - details.source = source; - msg += "
    Source:
    " +
    -					escapeText( source ) +
    -					"
    "; - } - } - runLoggingCallbacks( "log", QUnit, details ); - config.current.assertions.push({ - result: result, - message: msg - }); - }, - - /** - * Assert that the first two arguments are equal, with an optional message. - * Prints out both actual and expected values. - * @name equal - * @function - * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); - */ - equal: function( actual, expected, message ) { - /*jshint eqeqeq:false */ - QUnit.push( expected == actual, actual, expected, message ); - }, - - /** - * @name notEqual - * @function - */ - notEqual: function( actual, expected, message ) { - /*jshint eqeqeq:false */ - QUnit.push( expected != actual, actual, expected, message ); - }, - - /** - * @name propEqual - * @function - */ - propEqual: function( actual, expected, message ) { - actual = objectValues(actual); - expected = objectValues(expected); - QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); - }, - - /** - * @name notPropEqual - * @function - */ - notPropEqual: function( actual, expected, message ) { - actual = objectValues(actual); - expected = objectValues(expected); - QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); - }, - - /** - * @name deepEqual - * @function - */ - deepEqual: function( actual, expected, message ) { - QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); - }, - - /** - * @name notDeepEqual - * @function - */ - notDeepEqual: function( actual, expected, message ) { - QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); - }, - - /** - * @name strictEqual - * @function - */ - strictEqual: function( actual, expected, message ) { - QUnit.push( expected === actual, actual, expected, message ); - }, - - /** - * @name notStrictEqual - * @function - */ - notStrictEqual: function( actual, expected, message ) { - QUnit.push( expected !== actual, actual, expected, message ); - }, - - "throws": function( block, expected, message ) { - var actual, - expectedOutput = expected, - ok = false; - - // 'expected' is optional - if ( !message && typeof expected === "string" ) { - message = expected; - expected = null; - } - - config.current.ignoreGlobalErrors = true; - try { - block.call( config.current.testEnvironment ); - } catch (e) { - actual = e; - } - config.current.ignoreGlobalErrors = false; - - if ( actual ) { - - // we don't want to validate thrown error - if ( !expected ) { - ok = true; - expectedOutput = null; - - // expected is an Error object - } else if ( expected instanceof Error ) { - ok = actual instanceof Error && - actual.name === expected.name && - actual.message === expected.message; - - // expected is a regexp - } else if ( QUnit.objectType( expected ) === "regexp" ) { - ok = expected.test( errorString( actual ) ); - - // expected is a string - } else if ( QUnit.objectType( expected ) === "string" ) { - ok = expected === errorString( actual ); - - // expected is a constructor - } else if ( actual instanceof expected ) { - ok = true; - - // expected is a validation function which returns true is validation passed - } else if ( expected.call( {}, actual ) === true ) { - expectedOutput = null; - ok = true; - } - - QUnit.push( ok, actual, expectedOutput, message ); - } else { - QUnit.pushFailure( message, null, "No exception was thrown." ); - } - } -}; - -/** - * @deprecated since 1.8.0 - * Kept assertion helpers in root for backwards compatibility. - */ -extend( QUnit.constructor.prototype, assert ); - -/** - * @deprecated since 1.9.0 - * Kept to avoid TypeErrors for undefined methods. - */ -QUnit.constructor.prototype.raises = function() { - QUnit.push( false, false, false, "QUnit.raises has been deprecated since 2012 (fad3c1ea), use QUnit.throws instead" ); -}; - -/** - * @deprecated since 1.0.0, replaced with error pushes since 1.3.0 - * Kept to avoid TypeErrors for undefined methods. - */ -QUnit.constructor.prototype.equals = function() { - QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); -}; -QUnit.constructor.prototype.same = function() { - QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); -}; - -// Test for equality any JavaScript type. -// Author: Philippe Rathé -QUnit.equiv = (function() { - - // Call the o related callback with the given arguments. - function bindCallbacks( o, callbacks, args ) { - var prop = QUnit.objectType( o ); - if ( prop ) { - if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { - return callbacks[ prop ].apply( callbacks, args ); - } else { - return callbacks[ prop ]; // or undefined - } - } - } - - // the real equiv function - var innerEquiv, - // stack to decide between skip/abort functions - callers = [], - // stack to avoiding loops from circular referencing - parents = [], - parentsB = [], - - getProto = Object.getPrototypeOf || function ( obj ) { - /*jshint camelcase:false */ - return obj.__proto__; - }, - callbacks = (function () { - - // for string, boolean, number and null - function useStrictEquality( b, a ) { - /*jshint eqeqeq:false */ - if ( b instanceof a.constructor || a instanceof b.constructor ) { - // to catch short annotation VS 'new' annotation of a - // declaration - // e.g. var i = 1; - // var j = new Number(1); - return a == b; - } else { - return a === b; - } - } - - return { - "string": useStrictEquality, - "boolean": useStrictEquality, - "number": useStrictEquality, - "null": useStrictEquality, - "undefined": useStrictEquality, - - "nan": function( b ) { - return isNaN( b ); - }, - - "date": function( b, a ) { - return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); - }, - - "regexp": function( b, a ) { - return QUnit.objectType( b ) === "regexp" && - // the regex itself - a.source === b.source && - // and its modifiers - a.global === b.global && - // (gmi) ... - a.ignoreCase === b.ignoreCase && - a.multiline === b.multiline && - a.sticky === b.sticky; - }, - - // - skip when the property is a method of an instance (OOP) - // - abort otherwise, - // initial === would have catch identical references anyway - "function": function() { - var caller = callers[callers.length - 1]; - return caller !== Object && typeof caller !== "undefined"; - }, - - "array": function( b, a ) { - var i, j, len, loop, aCircular, bCircular; - - // b could be an object literal here - if ( QUnit.objectType( b ) !== "array" ) { - return false; - } - - len = a.length; - if ( len !== b.length ) { - // safe and faster - return false; - } - - // track reference to avoid circular references - parents.push( a ); - parentsB.push( b ); - for ( i = 0; i < len; i++ ) { - loop = false; - for ( j = 0; j < parents.length; j++ ) { - aCircular = parents[j] === a[i]; - bCircular = parentsB[j] === b[i]; - if ( aCircular || bCircular ) { - if ( a[i] === b[i] || aCircular && bCircular ) { - loop = true; - } else { - parents.pop(); - parentsB.pop(); - return false; - } - } - } - if ( !loop && !innerEquiv(a[i], b[i]) ) { - parents.pop(); - parentsB.pop(); - return false; - } - } - parents.pop(); - parentsB.pop(); - return true; - }, - - "object": function( b, a ) { - /*jshint forin:false */ - var i, j, loop, aCircular, bCircular, - // Default to true - eq = true, - aProperties = [], - bProperties = []; - - // comparing constructors is more strict than using - // instanceof - if ( a.constructor !== b.constructor ) { - // Allow objects with no prototype to be equivalent to - // objects with Object as their constructor. - if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || - ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { - return false; - } - } - - // stack constructor before traversing properties - callers.push( a.constructor ); - - // track reference to avoid circular references - parents.push( a ); - parentsB.push( b ); - - // be strict: don't ensure hasOwnProperty and go deep - for ( i in a ) { - loop = false; - for ( j = 0; j < parents.length; j++ ) { - aCircular = parents[j] === a[i]; - bCircular = parentsB[j] === b[i]; - if ( aCircular || bCircular ) { - if ( a[i] === b[i] || aCircular && bCircular ) { - loop = true; - } else { - eq = false; - break; - } - } - } - aProperties.push(i); - if ( !loop && !innerEquiv(a[i], b[i]) ) { - eq = false; - break; - } - } - - parents.pop(); - parentsB.pop(); - callers.pop(); // unstack, we are done - - for ( i in b ) { - bProperties.push( i ); // collect b's properties - } - - // Ensures identical properties name - return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); - } - }; - }()); - - innerEquiv = function() { // can take multiple arguments - var args = [].slice.apply( arguments ); - if ( args.length < 2 ) { - return true; // end transition - } - - return (function( a, b ) { - if ( a === b ) { - return true; // catch the most you can - } else if ( a === null || b === null || typeof a === "undefined" || - typeof b === "undefined" || - QUnit.objectType(a) !== QUnit.objectType(b) ) { - return false; // don't lose time with error prone cases - } else { - return bindCallbacks(a, callbacks, [ b, a ]); - } - - // apply transition with (1..n) arguments - }( args[0], args[1] ) && innerEquiv.apply( this, args.splice(1, args.length - 1 )) ); - }; - - return innerEquiv; -}()); - -/** - * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | - * http://flesler.blogspot.com Licensed under BSD - * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 - * - * @projectDescription Advanced and extensible data dumping for Javascript. - * @version 1.0.0 - * @author Ariel Flesler - * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} - */ -QUnit.jsDump = (function() { - function quote( str ) { - return "\"" + str.toString().replace( /"/g, "\\\"" ) + "\""; - } - function literal( o ) { - return o + ""; - } - function join( pre, arr, post ) { - var s = jsDump.separator(), - base = jsDump.indent(), - inner = jsDump.indent(1); - if ( arr.join ) { - arr = arr.join( "," + s + inner ); - } - if ( !arr ) { - return pre + post; - } - return [ pre, inner + arr, base + post ].join(s); - } - function array( arr, stack ) { - var i = arr.length, ret = new Array(i); - this.up(); - while ( i-- ) { - ret[i] = this.parse( arr[i] , undefined , stack); - } - this.down(); - return join( "[", ret, "]" ); - } - - var reName = /^function (\w+)/, - jsDump = { - // type is used mostly internally, you can fix a (custom)type in advance - parse: function( obj, type, stack ) { - stack = stack || [ ]; - var inStack, res, - parser = this.parsers[ type || this.typeOf(obj) ]; - - type = typeof parser; - inStack = inArray( obj, stack ); - - if ( inStack !== -1 ) { - return "recursion(" + (inStack - stack.length) + ")"; - } - if ( type === "function" ) { - stack.push( obj ); - res = parser.call( this, obj, stack ); - stack.pop(); - return res; - } - return ( type === "string" ) ? parser : this.parsers.error; - }, - typeOf: function( obj ) { - var type; - if ( obj === null ) { - type = "null"; - } else if ( typeof obj === "undefined" ) { - type = "undefined"; - } else if ( QUnit.is( "regexp", obj) ) { - type = "regexp"; - } else if ( QUnit.is( "date", obj) ) { - type = "date"; - } else if ( QUnit.is( "function", obj) ) { - type = "function"; - } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { - type = "window"; - } else if ( obj.nodeType === 9 ) { - type = "document"; - } else if ( obj.nodeType ) { - type = "node"; - } else if ( - // native arrays - toString.call( obj ) === "[object Array]" || - // NodeList objects - ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) - ) { - type = "array"; - } else if ( obj.constructor === Error.prototype.constructor ) { - type = "error"; - } else { - type = typeof obj; - } - return type; - }, - separator: function() { - return this.multiline ? this.HTML ? "
    " : "\n" : this.HTML ? " " : " "; - }, - // extra can be a number, shortcut for increasing-calling-decreasing - indent: function( extra ) { - if ( !this.multiline ) { - return ""; - } - var chr = this.indentChar; - if ( this.HTML ) { - chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); - } - return new Array( this.depth + ( extra || 0 ) ).join(chr); - }, - up: function( a ) { - this.depth += a || 1; - }, - down: function( a ) { - this.depth -= a || 1; - }, - setParser: function( name, parser ) { - this.parsers[name] = parser; - }, - // The next 3 are exposed so you can use them - quote: quote, - literal: literal, - join: join, - // - depth: 1, - // This is the list of parsers, to modify them, use jsDump.setParser - parsers: { - window: "[Window]", - document: "[Document]", - error: function(error) { - return "Error(\"" + error.message + "\")"; - }, - unknown: "[Unknown]", - "null": "null", - "undefined": "undefined", - "function": function( fn ) { - var ret = "function", - // functions never have name in IE - name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1]; - - if ( name ) { - ret += " " + name; - } - ret += "( "; - - ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); - return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); - }, - array: array, - nodelist: array, - "arguments": array, - object: function( map, stack ) { - /*jshint forin:false */ - var ret = [ ], keys, key, val, i; - QUnit.jsDump.up(); - keys = []; - for ( key in map ) { - keys.push( key ); - } - keys.sort(); - for ( i = 0; i < keys.length; i++ ) { - key = keys[ i ]; - val = map[ key ]; - ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); - } - QUnit.jsDump.down(); - return join( "{", ret, "}" ); - }, - node: function( node ) { - var len, i, val, - open = QUnit.jsDump.HTML ? "<" : "<", - close = QUnit.jsDump.HTML ? ">" : ">", - tag = node.nodeName.toLowerCase(), - ret = open + tag, - attrs = node.attributes; - - if ( attrs ) { - for ( i = 0, len = attrs.length; i < len; i++ ) { - val = attrs[i].nodeValue; - // IE6 includes all attributes in .attributes, even ones not explicitly set. - // Those have values like undefined, null, 0, false, "" or "inherit". - if ( val && val !== "inherit" ) { - ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" ); - } - } - } - ret += close; - - // Show content of TextNode or CDATASection - if ( node.nodeType === 3 || node.nodeType === 4 ) { - ret += node.nodeValue; - } - - return ret + open + "/" + tag + close; - }, - // function calls it internally, it's the arguments part of the function - functionArgs: function( fn ) { - var args, - l = fn.length; - - if ( !l ) { - return ""; - } - - args = new Array(l); - while ( l-- ) { - // 97 is 'a' - args[l] = String.fromCharCode(97+l); - } - return " " + args.join( ", " ) + " "; - }, - // object calls it internally, the key part of an item in a map - key: quote, - // function calls it internally, it's the content of the function - functionCode: "[code]", - // node calls it internally, it's an html attribute value - attribute: quote, - string: quote, - date: quote, - regexp: literal, - number: literal, - "boolean": literal - }, - // if true, entities are escaped ( <, >, \t, space and \n ) - HTML: false, - // indentation unit - indentChar: " ", - // if true, items in a collection, are separated by a \n, else just a space. - multiline: true - }; - - return jsDump; -}()); - -/* - * Javascript Diff Algorithm - * By John Resig (http://ejohn.org/) - * Modified by Chu Alan "sprite" - * - * Released under the MIT license. - * - * More Info: - * http://ejohn.org/projects/javascript-diff-algorithm/ - * - * Usage: QUnit.diff(expected, actual) - * - * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick brown fox jumped jumps over" - */ -QUnit.diff = (function() { - /*jshint eqeqeq:false, eqnull:true */ - function diff( o, n ) { - var i, - ns = {}, - os = {}; - - for ( i = 0; i < n.length; i++ ) { - if ( !hasOwn.call( ns, n[i] ) ) { - ns[ n[i] ] = { - rows: [], - o: null - }; - } - ns[ n[i] ].rows.push( i ); - } - - for ( i = 0; i < o.length; i++ ) { - if ( !hasOwn.call( os, o[i] ) ) { - os[ o[i] ] = { - rows: [], - n: null - }; - } - os[ o[i] ].rows.push( i ); - } - - for ( i in ns ) { - if ( hasOwn.call( ns, i ) ) { - if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) { - n[ ns[i].rows[0] ] = { - text: n[ ns[i].rows[0] ], - row: os[i].rows[0] - }; - o[ os[i].rows[0] ] = { - text: o[ os[i].rows[0] ], - row: ns[i].rows[0] - }; - } - } - } - - for ( i = 0; i < n.length - 1; i++ ) { - if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && - n[ i + 1 ] == o[ n[i].row + 1 ] ) { - - n[ i + 1 ] = { - text: n[ i + 1 ], - row: n[i].row + 1 - }; - o[ n[i].row + 1 ] = { - text: o[ n[i].row + 1 ], - row: i + 1 - }; - } - } - - for ( i = n.length - 1; i > 0; i-- ) { - if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && - n[ i - 1 ] == o[ n[i].row - 1 ]) { - - n[ i - 1 ] = { - text: n[ i - 1 ], - row: n[i].row - 1 - }; - o[ n[i].row - 1 ] = { - text: o[ n[i].row - 1 ], - row: i - 1 - }; - } - } - - return { - o: o, - n: n - }; - } - - return function( o, n ) { - o = o.replace( /\s+$/, "" ); - n = n.replace( /\s+$/, "" ); - - var i, pre, - str = "", - out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), - oSpace = o.match(/\s+/g), - nSpace = n.match(/\s+/g); - - if ( oSpace == null ) { - oSpace = [ " " ]; - } - else { - oSpace.push( " " ); - } - - if ( nSpace == null ) { - nSpace = [ " " ]; - } - else { - nSpace.push( " " ); - } - - if ( out.n.length === 0 ) { - for ( i = 0; i < out.o.length; i++ ) { - str += "" + out.o[i] + oSpace[i] + ""; - } - } - else { - if ( out.n[0].text == null ) { - for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { - str += "" + out.o[n] + oSpace[n] + ""; - } - } - - for ( i = 0; i < out.n.length; i++ ) { - if (out.n[i].text == null) { - str += "" + out.n[i] + nSpace[i] + ""; - } - else { - // `pre` initialized at top of scope - pre = ""; - - for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { - pre += "" + out.o[n] + oSpace[n] + ""; - } - str += " " + out.n[i].text + nSpace[i] + pre; - } - } - } - - return str; - }; -}()); - -// For browser, export only select globals -if ( typeof window !== "undefined" ) { - extend( window, QUnit.constructor.prototype ); - window.QUnit = QUnit; -} - -// For CommonJS environments, export everything -if ( typeof module !== "undefined" && module.exports ) { - module.exports = QUnit; -} - - -// Get a reference to the global object, like window in browsers -}( (function() { - return this; -})() )); diff --git a/tests/qunit/editor/js/runner.js b/tests/qunit/editor/js/runner.js deleted file mode 100644 index c42d1dacf8..0000000000 --- a/tests/qunit/editor/js/runner.js +++ /dev/null @@ -1,148 +0,0 @@ -/* - * PhantomJS Runner QUnit Plugin 1.2.0 - * - * PhantomJS binaries: http://phantomjs.org/download.html - * Requires PhantomJS 1.6+ (1.7+ recommended) - * - * Run with: - * phantomjs runner.js [url-of-your-qunit-testsuite] - * - * e.g. - * phantomjs runner.js http://localhost/qunit/test/index.html - */ - -/*global phantom:false, require:false, console:false, window:false, QUnit:false */ - -(function() { - 'use strict'; - - var url, page, timeout, - args = require('system').args; - - // arg[0]: scriptName, args[1...]: arguments - if (args.length < 2 || args.length > 3) { - console.error('Usage:\n phantomjs runner.js [url-of-your-qunit-testsuite] [timeout-in-seconds]'); - phantom.exit(1); - } - - url = args[1]; - page = require('webpage').create(); - if (args[2] !== undefined) { - timeout = parseInt(args[2], 10); - } - - // Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`) - page.onConsoleMessage = function(msg) { - console.log(msg); - }; - - page.onInitialized = function() { - page.evaluate(addLogging); - }; - - page.onCallback = function(message) { - var result, - failed; - - if (message) { - if (message.name === 'QUnit.done') { - result = message.data; - failed = !result || !result.total || result.failed; - - if (!result.total) { - console.error('No tests were executed. Are you loading tests asynchronously?'); - } - - phantom.exit(failed ? 1 : 0); - } - } - }; - - page.open(url, function(status) { - if (status !== 'success') { - console.error('Unable to access network: ' + status); - phantom.exit(1); - } else { - // Cannot do this verification with the 'DOMContentLoaded' handler because it - // will be too late to attach it if a page does not have any script tags. - var qunitMissing = page.evaluate(function() { return (typeof QUnit === 'undefined' || !QUnit); }); - if (qunitMissing) { - console.error('The `QUnit` object is not present on this page.'); - phantom.exit(1); - } - - // Set a timeout on the test running, otherwise tests with async problems will hang forever - if (typeof timeout === 'number') { - setTimeout(function() { - console.error('The specified timeout of ' + timeout + ' seconds has expired. Aborting...'); - phantom.exit(1); - }, timeout * 1000); - } - - // Do nothing... the callback mechanism will handle everything! - } - }); - - function addLogging() { - window.document.addEventListener('DOMContentLoaded', function() { - var currentTestAssertions = []; - - QUnit.log(function(details) { - var response; - - // Ignore passing assertions - if (details.result) { - return; - } - - response = details.message || ''; - - if (typeof details.expected !== 'undefined') { - if (response) { - response += ', '; - } - - response += 'expected: ' + details.expected + ', but was: ' + details.actual; - } - - if (details.source) { - response += "\n" + details.source; - } - - currentTestAssertions.push('Failed assertion: ' + response); - }); - - QUnit.testDone(function(result) { - var i, - len, - name = ''; - - if (result.module) { - name += result.module + ': '; - } - name += result.name; - - if (result.failed) { - console.log('\n' + 'Test failed: ' + name); - - for (i = 0, len = currentTestAssertions.length; i < len; i++) { - console.log(' ' + currentTestAssertions[i]); - } - } - - currentTestAssertions.length = 0; - }); - - QUnit.done(function(result) { - console.log('\n' + 'Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.'); - - if (typeof window.callPhantom === 'function') { - window.callPhantom({ - 'name': 'QUnit.done', - 'data': result - }); - } - }); - }, false); - } -})(); \ No newline at end of file diff --git a/tests/qunit/editor/js/tinymce_loader.js b/tests/qunit/editor/js/tinymce_loader.js deleted file mode 100644 index fae4529b23..0000000000 --- a/tests/qunit/editor/js/tinymce_loader.js +++ /dev/null @@ -1,9 +0,0 @@ -// Edited for WordPres -document.write(''); - -var wpPlugins = 'charmap colorpicker hr lists media paste tabfocus textcolor ' + - 'fullscreen wordpress wpautoresize wpeditimage wpgallery wplink wpdialogs wpview'; - -var $ = window.jQuery; - -getUserSetting = setUserSetting = function() {} diff --git a/tests/qunit/editor/js/utils.js b/tests/qunit/editor/js/utils.js deleted file mode 100644 index b886e8d3b9..0000000000 --- a/tests/qunit/editor/js/utils.js +++ /dev/null @@ -1,493 +0,0 @@ -(function() { - function fontFace(face) { - if (tinymce.isOpera) { - return "'" + face + "'"; - } - - return face; - } - - function findContainer(selector) { - var container; - if (tinymce.is(selector, 'string')) { - container = editor.dom.select(selector)[0]; - } else { - container = selector; - } - if (container.firstChild) { - container = container.firstChild; - } - return container; - } - - function setSelection(startSelector, startOffset, endSelector, endOffset) { - if (!endSelector) { - endSelector = startSelector; - endOffset = startOffset; - } - var startContainer = findContainer(startSelector); - var endContainer = findContainer(endSelector); - var rng = editor.dom.createRng(); - - function setRange(container, offset, start) { - offset = offset || 0; - - if (offset === 'after') { - if (start) { - rng.setStartAfter(container); - } else { - rng.setEndAfter(container); - } - return; - } else if (offset === 'afterNextCharacter') { - container = container.nextSibling; - offset = 1; - } - if (start) { - rng.setStart(container, offset); - } else { - rng.setEnd(container, offset); - } - } - - setRange(startContainer, startOffset, true); - setRange(endContainer, endOffset, false); - editor.selection.setRng(rng); - } - - function assertRange(actual, expected) { - deepEqual({ - startContainer: actual.startContainer, - startOffset: actual.startOffset, - endContainer: actual.endContainer, - endOffset: actual.endOffset - }, { - startContainer: expected.startContainer, - startOffset: expected.startOffset, - endContainer: expected.endContainer, - endOffset: expected.endOffset - }); - } - - function createRange(startContainer, startOffset, endContainer, endOffset) { - var rng = tinymce.DOM.createRng(); - - rng.setStart(startContainer, startOffset); - - if (endContainer) { - rng.setEnd(endContainer, endOffset); - } - - return rng; - } - - function assertCaretPosition(actual, expected, message) { - if (expected === null) { - strictEqual(actual, expected, message || 'Expected null.'); - return; - } - - if (actual === null) { - strictEqual(actual, expected, message || 'Didn\'t expect null.'); - return; - } - - deepEqual({ - container: actual.container(), - offset: actual.offset() - }, { - container: expected.container(), - offset: expected.offset() - }, message); - } - - function trimContent(content) { - return content.replace(/^

     <\/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 char

    ab[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 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 char

    ab[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>|]+data-mce-bogus[^>]+><\/div>/gi, ''); - html = html.replace(/ style="([^"]+)"/gi, function(val1, val2) { - val2 = val2.replace(/;$/, ''); - return ' style="' + val2.replace(/\:([^ ])/g, ': $1') + ';"'; - }); - - return html; - } - - function normalizeHtml(html) { - var writer = new tinymce.html.Writer(); - - new tinymce.html.SaxParser({ - validate: false, - comment: writer.comment, - cdata: writer.cdata, - text: writer.text, - end: writer.end, - pi: writer.pi, - doctype: writer.doctype, - - start: function(name, attrs, empty) { - attrs.sort(function(a, b) { - if (a.name === b.name) { - return 0; - } - - return a.name > b.name ? 1 : -1; - }); - - writer.start(name, attrs, empty); - } - }).parse(html); - - return writer.getContent(); - } - - /** - * Measures the x, y, w, h of the specified element/control relative to the view element. - */ - function rect(ctrl) { - var outerRect, innerRect; - - if (ctrl.nodeType) { - innerRect = ctrl.getBoundingClientRect(); - } else { - innerRect = ctrl.getEl().getBoundingClientRect(); - } - - outerRect = document.getElementById('view').getBoundingClientRect(); - - return [ - Math.round(innerRect.left - outerRect.left), - Math.round(innerRect.top - outerRect.top), - Math.round(innerRect.right - innerRect.left), - Math.round(innerRect.bottom - innerRect.top) - ]; - } - - function size(ctrl) { - return rect(ctrl).slice(2); - } - - function resetScroll(elm) { - elm.scrollTop = 0; - elm.scrollLeft = 0; - } - - // Needed since fonts render differently on different platforms - function nearlyEqualRects(rect1, rect2, diff) { - diff = diff || 1; - - for (var i = 0; i < 4; i++) { - if (Math.abs(rect1[i] - rect2[i]) > diff) { - deepEqual(rect1, rect2); - return; - } - } - - ok(true); - } - - function getFrontmostWindow() { - return editor.windowManager.windows[editor.windowManager.windows.length - 1]; - } - - function pressKey(evt) { - var dom = editor.dom, target = editor.selection.getNode(); - - if (typeof evt == "number") { - evt = {keyCode: evt}; - } - - evt = tinymce.extend({keyCode: 37}, evt); - - dom.fire(target, 'keydown', evt); - dom.fire(target, 'keypress', evt); - dom.fire(target, 'keyup', evt); - } - - function pressArrowKey(evt) { - var dom = editor.dom, target = editor.selection.getNode(); - - evt = tinymce.extend({keyCode: 37}, evt); - - dom.fire(target, 'keydown', evt); - dom.fire(target, 'keypress', evt); - dom.fire(target, 'keyup', evt); - } - - function pressEnter(evt) { - var dom = editor.dom, target = editor.selection.getNode(); - - evt = tinymce.extend({keyCode: 13}, evt); - - dom.fire(target, 'keydown', evt); - dom.fire(target, 'keypress', evt); - dom.fire(target, 'keyup', evt); - } - - function trimBrsOnIE(html) { - return html.replace(/]*>/gi, ''); - } - - function patch(proto, name, patchFunc) { - var originalFunc = proto[name]; - var originalFuncs = proto.__originalFuncs; - - if (!originalFuncs) { - proto.__originalFuncs = originalFuncs = {}; - } - - if (!originalFuncs[name]) { - originalFuncs[name] = originalFunc; - } else { - originalFunc = originalFuncs[name]; - } - - proto[name] = function() { - var args = Array.prototype.slice.call(arguments); - args.unshift(originalFunc); - return patchFunc.apply(this, args); - }; - } - - function unpatch(proto, name) { - var originalFuncs = proto.__originalFuncs; - - if (!originalFuncs) { - return; - } - - if (name) { - proto[name] = originalFuncs[name]; - delete originalFuncs[name]; - } else { - for (var key in originalFuncs) { - proto[key] = originalFuncs[key]; - } - - delete proto.__originalFuncs; - } - } - - function triggerElementChange(element){ - var evt; - - if ("createEvent" in document) { - evt = document.createEvent("HTMLEvents"); - evt.initEvent("change", false, true); - element.dispatchEvent(evt); - } else { - element.fireEvent("onchange"); - } - } - - window.Utils = { - fontFace: fontFace, - findContainer: findContainer, - setSelection: setSelection, - trimContent: trimContent, - fakeKeyEvent: fakeKeyEvent, - normalizeRng: normalizeRng, - type: type, - cleanHtml: cleanHtml, - normalizeHtml: normalizeHtml, - rect: rect, - size: size, - resetScroll: resetScroll, - nearlyEqualRects: nearlyEqualRects, - getFrontmostWindow: getFrontmostWindow, - pressKey: pressKey, - pressArrowKey: pressArrowKey, - pressEnter: pressEnter, - trimBrsOnIE: trimBrsOnIE, - patch: patch, - unpatch: unpatch, - triggerElementChange: triggerElementChange, - createRange: createRange, - assertRange: assertRange, - assertCaretPosition: assertCaretPosition - }; -})(); diff --git a/tests/qunit/editor/tinymce/AddOnManager.js b/tests/qunit/editor/tinymce/AddOnManager.js deleted file mode 100644 index f0e0a2404a..0000000000 --- a/tests/qunit/editor/tinymce/AddOnManager.js +++ /dev/null @@ -1,39 +0,0 @@ -module("tinymce.AddOnManager", { - teardown: function() { - Utils.unpatch(tinymce.dom.ScriptLoader.ScriptLoader); - tinymce.AddOnManager.languageLoad = true; - tinymce.AddOnManager.language = 'en'; - } -}); - -test('requireLangPack', function() { - var languagePackUrl; - - Utils.patch(tinymce.dom.ScriptLoader.ScriptLoader, 'add', function(origFunc, url) { - languagePackUrl = url; - }); - - function getLanguagePackUrl(language, languages) { - languagePackUrl = null; - tinymce.AddOnManager.language = language; - tinymce.AddOnManager.PluginManager.requireLangPack('plugin', languages); - return languagePackUrl; - } - - tinymce.AddOnManager.PluginManager.urls.plugin = '/root'; - - equal(getLanguagePackUrl('sv_SE'), '/root/langs/sv_SE.js'); - equal(getLanguagePackUrl('sv_SE', 'sv,en,us'), '/root/langs/sv.js'); - equal(getLanguagePackUrl('sv_SE', 'sv_SE,en_US'), '/root/langs/sv_SE.js'); - equal(getLanguagePackUrl('sv'), '/root/langs/sv.js'); - equal(getLanguagePackUrl('sv', 'sv'), '/root/langs/sv.js'); - equal(getLanguagePackUrl('sv', 'sv,en,us'), '/root/langs/sv.js'); - equal(getLanguagePackUrl('sv', 'en,sv,us'), '/root/langs/sv.js'); - equal(getLanguagePackUrl('sv', 'en,us,sv'), '/root/langs/sv.js'); - strictEqual(getLanguagePackUrl('sv', 'en,us'), null); - strictEqual(getLanguagePackUrl(null, 'en,us'), null); - strictEqual(getLanguagePackUrl(null), null); - - tinymce.AddOnManager.languageLoad = false; - strictEqual(getLanguagePackUrl('sv', 'sv'), null); -}); diff --git a/tests/qunit/editor/tinymce/Editor.js b/tests/qunit/editor/tinymce/Editor.js deleted file mode 100644 index b503922652..0000000000 --- a/tests/qunit/editor/tinymce/Editor.js +++ /dev/null @@ -1,527 +0,0 @@ -module("tinymce.Editor", { - setupModule: function() { - document.getElementById('view').innerHTML = '
    '; - QUnit.stop(); - - tinymce.init({ - selector: "#elm1", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - entities: 'raw', - indent: 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,display' - }, - custom_elements: 'custom1,~custom2', - extended_valid_elements: 'custom1,custom2,script[*]', - init_instance_callback: function(ed) { - window.editor = ed; - - if (window.inlineEditor) { - QUnit.start(); - } - } - }); - - tinymce.init({ - selector: "#elm2", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - entities: 'raw', - indent: false, - inline: true, - init_instance_callback: function(ed) { - window.inlineEditor = ed; - - if (window.editor) { - QUnit.start(); - } - } - }); - }, - - teardown: function() { - Utils.unpatch(editor.getDoc()); - inlineEditor.show(); - editor.show(); - } -}); - -test('Event: change', function() { - var level, lastLevel; - - editor.on('change', function(e) { - level = e.level; - lastLevel = e.lastLevel; - }); - - editor.setContent(''); - editor.insertContent('a'); - equal(level.content.toLowerCase(), '

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

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

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

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.settings.relative_urls = false; - editor.settings.remove_script_host = false; - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); - - editor.setContent('test'); - equal(editor.getContent(), '

    test

    '); -}); - -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
    456'); - editor.dom.replace(p, editor.getBody().firstChild); - - equal(editor.getContent(), '

    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('
    '); - editor.settings.disable_nodechange = false; - editor.nodeChanged(); - editor.settings.disable_nodechange = true; - equal(editor.getContent(), "

    \u00a0

    "); -}); - -test('custom elements', function() { - editor.setContent('c1c1'); - equal(editor.getContent(), 'c1

    c1

    '); -}); - -test('Store/restore tabindex', function() { - editor.setContent('abc'); - equal(editor.getContent({format: 'raw'}).toLowerCase(), '

    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('


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


    '); - delete editor.settings.padd_empty_with_br; -}); - -test('Padd empty elements with br on insert at caret', function() { - editor.settings.padd_empty_with_br = true; - editor.setContent('

    a

    '); - Utils.setSelection('p', 1); - editor.insertContent('

    b

    '); - equal(editor.getContent(), '

    a

    b


    '); - delete editor.settings.padd_empty_with_br; -}); - -test('Preserve whitespace pre elements', function() { - editor.setContent('
     
    '); - 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('
    '); - editor.focus(); - rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 0); - editor.selection.setRng(rng); - editor.execCommand('mceInsertContent', false, 'x'); - equal(getContent(), '

    x


    '); -}); - -test('mceInsertContent HR at end of H1', function() { - editor.setContent('

    abc

    '); - Utils.setSelection('h1', 3); - editor.execCommand('mceInsertContent', false, '
    '); - equal(editor.selection.getNode(), editor.getBody().lastChild); - equal(editor.selection.getNode().nodeName, 'H1'); - equal(getContent(), '

    abc


    \u00a0

    '); -}); - -test('mceInsertContent HR at end of H1 with P sibling', function() { - editor.setContent('

    abc

    def

    '); - Utils.setSelection('h1', 3); - editor.execCommand('mceInsertContent', false, '
    '); - equal(editor.selection.getNode(), editor.getBody().lastChild); - equal(editor.selection.getNode().nodeName, 'P'); - equal(getContent(), '

    abc


    def

    '); -}); - -test('mceInsertContent HR at end of H1 with inline elements with P sibling', function() { - editor.setContent('

    abc

    def

    '); - Utils.setSelection('strong', 3); - editor.execCommand('mceInsertContent', false, '
    '); - equal(editor.selection.getNode(), editor.getBody().lastChild); - equal(editor.selection.getNode().nodeName, 'P'); - equal(getContent(), '

    abc


    def

    '); -}); - -test('mceInsertContent empty block', function() { - editor.setContent('

    abc

    '); - Utils.setSelection('h1', 1); - editor.execCommand('mceInsertContent', false, '

    '); - equal(editor.selection.getNode(), editor.getBody().childNodes[1]); - equal(editor.selection.getNode().nodeName, 'P'); - equal(getContent(), '

    a

    \u00a0

    bc

    '); -}); - -test('mceInsertContent table at end of H1 with P sibling', function() { - editor.setContent('

    abc

    def

    '); - Utils.setSelection('h1', 3); - editor.execCommand('mceInsertContent', false, '
    '); - equal(editor.selection.getNode().nodeName, 'TD'); - equal(getContent(), '

    abc

    \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('

    1234

    '); - rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('h1')[0].firstChild, 1); - rng.setEnd(editor.dom.select('h1')[0].firstChild, 3); - editor.selection.setRng(rng); - editor.execCommand('mceInsertContent', false, '

    abc

    '); - equal(getContent(), '

    1

    abc

    4

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

    abc

    '); - equal(getContent(), '

    abc

    '); - rng = Utils.normalizeRng(editor.selection.getRng(true)); - ok(rng.collapsed); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startOffset, 1); - equal(rng.endContainer.nodeName, 'P'); - equal(rng.endOffset, 1); - equal(rng.startContainer.innerHTML, 'abc'); -}); - -test('mceInsertContent - text inside empty p', function() { - var rng; - - expect(7); - - editor.getBody().innerHTML = '

    '; - Utils.setSelection('p', 0); - editor.execCommand('mceInsertContent', false, 'abc'); - equal(editor.getBody().innerHTML.toLowerCase().replace(/^
    /, ''), '

    abc

    '); // Opera inserts a BR at the beginning of contents if the P is empty - rng = Utils.normalizeRng(editor.selection.getRng(true)); - ok(rng.collapsed); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startOffset, 1); - equal(rng.endContainer.nodeName, 'P'); - equal(rng.endOffset, 1); - equal(rng.startContainer.innerHTML, 'abc'); -}); - -test('mceInsertContent - text inside empty p with br caret node', function() { - var rng; - - expect(7); - - editor.getBody().innerHTML = '


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

    abc

    '); - rng = Utils.normalizeRng(editor.selection.getRng(true)); - ok(rng.collapsed); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startOffset, 1); - equal(rng.endContainer.nodeName, 'P'); - equal(rng.endOffset, 1); - equal(rng.startContainer.innerHTML, 'abc'); -}); - -test('mceInsertContent - image inside p', function() { - var rng; - - expect(6); - - editor.setContent('

    1

    '); - rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].firstChild, 1); - editor.selection.setRng(rng); - editor.execCommand('mceInsertContent', false, ''); - equal(editor.getContent(), '

    '); - rng = Utils.normalizeRng(editor.selection.getRng(true)); - ok(rng.collapsed); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startOffset, 1); - equal(rng.endContainer.nodeName, 'P'); - equal(rng.endOffset, 1); -}); - -test('mceInsertContent - legacy content', function() { - var rng; - - expect(1); - - // Convert legacy content - editor.setContent('

    1

    '); - rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].firstChild, 1); - editor.selection.setRng(rng); - editor.execCommand('mceInsertContent', false, 'strikefont'); - equal(editor.getContent(), '

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

    1


    3

    '); - rng = Utils.normalizeRng(editor.selection.getRng(true)); - ok(rng.collapsed); - equal(rng.startContainer, editor.getBody().lastChild); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startOffset, 0); - equal(rng.endContainer.nodeName, 'P'); - equal(rng.endOffset, 0); -}); - -test('mceInsertContent - forced root block', function() { - expect(1); - - // Forced root block - editor.getBody().innerHTML = ''; - editor.execCommand('mceInsertContent', false, 'test123'); - // Opera adds an extra paragraph since it adds a BR at the end of the contents pass though this for now since it's an minority browser - equal(editor.getContent().replace(/

    \u00a0<\/p>/g, ''), '

    test123

    '); -}); - -test('mceInsertContent - mixed inline content inside td', function() { - expect(1); - - // Forced root block - editor.getBody().innerHTML = '
    X
    '; - Utils.setSelection('td', 0, 'td', 0); - editor.execCommand('mceInsertContent', false, 'test123'); - equal(editor.getContent(), '
    test123X
    '); -}); - -test('mceInsertContent - invalid insertion with spans on page', function(){ - var startingContent = '

    123 testing span later in document

    ', - insertedContent = '
    • u
    • l
    '; - editor.setContent(startingContent); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('p')[0].firstChild, 0); - rng.setEnd(editor.dom.select('p')[0].firstChild, 0); - editor.selection.setRng(rng); - editor.execCommand('mceInsertContent', false, insertedContent); - - equal(editor.getContent(), insertedContent + startingContent); -}); - -test('mceInsertContent - text with space before at start of block', function() { - editor.getBody().innerHTML = '

    a

    '; - Utils.setSelection('p', 0); - editor.execCommand('mceInsertContent', false, ' b'); - equal(editor.getContent(), '

    \u00a0ba

    '); -}); - -test('mceInsertContent - text with space after at end of block', function() { - editor.getBody().innerHTML = '

    a

    '; - Utils.setSelection('p', 1); - editor.execCommand('mceInsertContent', false, 'b '); - equal(editor.getContent(), '

    ab\u00a0

    '); -}); - -test('mceInsertContent - text with space before/after at middle of block', function() { - editor.getBody().innerHTML = '

    ac

    '; - Utils.setSelection('p', 1); - editor.execCommand('mceInsertContent', false, ' b '); - equal(editor.getContent(), '

    a b c

    '); -}); - -test('mceInsertContent - inline element with space before/after at middle of block', function() { - editor.getBody().innerHTML = '

    ac

    '; - Utils.setSelection('p', 1); - editor.execCommand('mceInsertContent', false, ' b '); - equal(editor.getContent(), '

    a b c

    '); -}); - -test('mceInsertContent - block element with space before/after at middle of block', function() { - editor.getBody().innerHTML = '

    ac

    '; - Utils.setSelection('p', 1); - editor.execCommand('mceInsertContent', false, '

    b

    '); - equal(editor.getContent(), '

    a

    b

    c

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

    test 123

    "); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('Italic'); - equal(editor.getContent(), "

    test 123

    "); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('Underline'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('Strikethrough'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('FontName', false, 'Arial'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('FontSize', false, '7'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('ForeColor', false, '#FF0000'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('HiliteColor', false, '#FF0000'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('testtest'); - equal(editor.getContent(), '

    testtest

    '); - - editor.setContent('

    test 123

    '); - equal(editor.getContent(), '

    test 123

    '); -}); - -test('Formatting commands (alignInline)', function() { - expect(7); - - editor.setContent('

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('JustifyLeft'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('JustifyCenter'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('JustifyRight'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent('

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('JustifyFull'); - equal(editor.getContent(), '

    test 123

    '); - - editor.setContent(''); - editor.selection.select(editor.dom.select('img')[0]); - editor.execCommand('JustifyLeft'); - equal(editor.getContent(), '

    '); - - editor.setContent(''); - editor.selection.select(editor.dom.select('img')[0]); - editor.execCommand('JustifyCenter'); - equal(editor.getContent(), '

    '); - - editor.setContent(''); - editor.selection.select(editor.dom.select('img')[0]); - editor.execCommand('JustifyRight'); - equal(editor.getContent(), '

    '); -}); - -test('mceBlockQuote', function() { - expect(2); - - editor.focus(); - editor.setContent('

    test 123

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

    test123

    '); - - editor.setContent('

    test 123

    test 123

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

    test123

    test123

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

    test 123

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

    test 123

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

    test 123

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

    test 123

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

    test 123

    '); - - editor.execCommand('SelectAll'); - editor.execCommand('FormatBlock', false, 'h5'); - equal(editor.getContent(), '
    test 123
    '); - - editor.execCommand('SelectAll'); - editor.execCommand('FormatBlock', false, 'h6'); - equal(editor.getContent(), '
    test 123
    '); - - editor.execCommand('SelectAll'); - - try { - editor.execCommand('FormatBlock', false, 'div'); - } catch (ex) { - //t.log('Failed: ' + ex.message); - } - - equal(editor.getContent(), '
    test 123
    '); - - editor.execCommand('SelectAll'); - editor.execCommand('FormatBlock', false, 'address'); - equal(editor.getContent(), '
    test 123
    '); - - editor.execCommand('SelectAll'); - editor.execCommand('FormatBlock', false, 'pre'); - equal(editor.getContent(), '
    test 123
    '); -}); - -test('mceInsertLink (relative)', function() { - expect(1); - - editor.setContent('test 123'); - editor.execCommand('SelectAll'); - editor.execCommand('mceInsertLink', false, 'test'); - equal(editor.getContent(), '

    test 123

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

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('mceInsertLink', false, 'http://www.site.com'); - equal(editor.getContent(), '

    test 123

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

    test 123

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

    test 123

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

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('mceInsertLink', false, {href : '"&<>', 'class' : 'test'}); - equal(editor.getContent(), '

    test 123

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

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('mceInsertLink', false, {href : 'foo bar'}); - equal(editor.getContent(), '

    test 123

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

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

    '); -}); - -test('mceInsertLink (link adjacent text)', function() { - var rng; - - expect(1); - - editor.setContent('

    ab

    '); - - rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild.lastChild, 0); - rng.setEnd(editor.getBody().firstChild.lastChild, 1); - editor.selection.setRng(rng); - - editor.execCommand('mceInsertLink', false, 'link'); - equal(editor.getContent(), '

    ab

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

    abc

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

    abc

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

    12

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

    12

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

    12

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

    12

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

    12

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

    12

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

    test

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

    test

    '); -}); - -test('mceInsertLink bug #7331', function() { - editor.setContent('
    A
    B
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.$('td')[1].firstChild, 0); - rng.setEnd(editor.getBody(), 1); - editor.selection.setRng(rng); - editor.execCommand('mceInsertLink', false, {href: 'x'}); - equal(editor.getContent(), '
    A
    B
    '); -}); - -test('unlink', function() { - editor.setContent('

    test 123

    '); - editor.execCommand('SelectAll'); - editor.execCommand('unlink'); - equal(editor.getContent(), '

    test 123

    '); -}); - -test('unlink - unselected a[href] with childNodes', function() { - editor.setContent('

    test

    '); - 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
    '); - editor.execCommand('SelectAll'); - editor.execCommand('Indent'); - equal(editor.getContent(), '
    test
    '); - - editor.setContent('
    test
    '); - editor.execCommand('SelectAll'); - editor.execCommand('Indent'); - editor.execCommand('Indent'); - equal(editor.getContent(), '
    test
    '); - - editor.setContent('
    test
    '); - editor.execCommand('SelectAll'); - editor.execCommand('Indent'); - editor.execCommand('Indent'); - editor.execCommand('Outdent'); - equal(editor.getContent(), '
    test
    '); - - editor.setContent('
    test
    '); - editor.execCommand('SelectAll'); - editor.execCommand('Outdent'); - equal(editor.getContent(), '
    test
    '); -}); - -test('RemoveFormat', function() { - expect(4); - - editor.setContent('

    test 123 123 123

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

    test 123 123 123

    '); - - editor.setContent('

    test 123 123 123

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

    test 123 123 123

    '); - - editor.setContent('

    testtest 123123 123

    '); - editor.selection.select(editor.dom.get('x')); - editor.execCommand('RemoveFormat'); - equal(editor.getContent(), '

    testtest 123123 123

    '); - - editor.setContent('

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

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

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

    '); -}); - -if (tinymce.Env.ceFalse) { - test('SelectAll', function() { - editor.setContent('

    a

    b

    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

    '); - - editor.setContent('

    123

    '); - Utils.setSelection('p', 0); - editor.execCommand('InsertLineBreak'); - equal(editor.getContent(), '


    123

    '); - - editor.setContent('

    123

    '); - Utils.setSelection('p', 3); - editor.execCommand('InsertLineBreak'); - equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? '

    123

    ' : '

    123

    '); -}); diff --git a/tests/qunit/editor/tinymce/EditorCustomTheme.js b/tests/qunit/editor/tinymce/EditorCustomTheme.js deleted file mode 100644 index aa8ad3215a..0000000000 --- a/tests/qunit/editor/tinymce/EditorCustomTheme.js +++ /dev/null @@ -1,43 +0,0 @@ -ModuleLoader.require([ -], function() { - module("tinymce.EditorCustomTheme", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - entities: 'raw', - indent: false, - theme: function (editor, targetnode) { - var editorContainer = document.createElement('div'); - editorContainer.id = 'editorContainer'; - - var iframeContainer = document.createElement('div'); - iframeContainer.id = 'iframeContainer'; - - editorContainer.appendChild(iframeContainer); - targetnode.parentNode.insertBefore(editorContainer, targetnode); - - return { - iframeContainer: iframeContainer, - editorContainer: editorContainer - }; - }, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - } - }); - - test('getContainer/getContentAreaContainer', function() { - QUnit.equal(editor.getContainer().id, 'editorContainer', 'Should be the new editorContainer element'); - QUnit.equal(editor.getContainer().nodeType, 1, 'Should be an element'); - QUnit.equal(editor.getContentAreaContainer().id, 'iframeContainer', 'Should be the new iframeContainer element'); - QUnit.equal(editor.getContentAreaContainer().nodeType, 1, 'Should be an element'); - }); -}); diff --git a/tests/qunit/editor/tinymce/EditorManager.js b/tests/qunit/editor/tinymce/EditorManager.js deleted file mode 100644 index 3e94b510e3..0000000000 --- a/tests/qunit/editor/tinymce/EditorManager.js +++ /dev/null @@ -1,207 +0,0 @@ -module("tinymce.EditorManager", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - skin: false - }).then(function(editors) { - window.editor = editors[0]; - QUnit.start(); - }); - } -}); - -test('get', function() { - strictEqual(tinymce.get().length, 1); - strictEqual(tinymce.get(0), tinymce.activeEditor); - strictEqual(tinymce.get(1), null); - strictEqual(tinymce.get("noid"), null); - strictEqual(tinymce.get(undefined), null); - strictEqual(tinymce.get()[0], tinymce.activeEditor); - strictEqual(tinymce.get(tinymce.activeEditor.id), tinymce.activeEditor); -}); - -test('addI18n/translate', function() { - tinymce.addI18n('en', { - 'from': 'to' - }); - - equal(tinymce.translate('from'), 'to'); -}); - -test('triggerSave', function() { - var saveCount = 0; - - window.editor.on('SaveContent', function() { - saveCount++; - }); - - tinymce.triggerSave(); - equal(saveCount, 1); -}); - -test('Re-init on same id', function() { - tinymce.init({selector: "#" + tinymce.activeEditor.id}); - strictEqual(tinymce.get().length, 1); -}); - -asyncTest('Externally destroyed editor', function() { - tinymce.remove(); - - tinymce.init({ - selector: "textarea", - init_instance_callback: function(editor1) { - tinymce.util.Delay.setTimeout(function() { - // Destroy the editor by setting innerHTML common ajax pattern - document.getElementById('view').innerHTML = ''; - - // Re-init the editor will have the same id - tinymce.init({ - selector: "textarea", - init_instance_callback: function(editor2) { - QUnit.start(); - - strictEqual(tinymce.get().length, 1); - strictEqual(editor1.id, editor2.id); - ok(editor1.destroyed, "First editor instance should be destroyed"); - } - }); - }, 0); - } - }); -}); - -asyncTest('Init/remove on same id', function() { - var textArea = document.createElement('textarea'); - document.getElementById('view').appendChild(textArea); - - tinymce.init({ - selector: "#view textarea", - init_instance_callback: function() { - tinymce.util.Delay.setTimeout(function() { - QUnit.start(); - - strictEqual(tinymce.get().length, 2); - strictEqual(tinymce.get(1), tinymce.activeEditor); - tinymce.remove('#' + tinymce.get(1).id); - strictEqual(tinymce.get().length, 1); - strictEqual(tinymce.get(0), tinymce.activeEditor); - textArea.parentNode.removeChild(textArea); - }, 0); - } - }); - - strictEqual(tinymce.get().length, 2); -}); - -asyncTest('Init editor async with proper editors state', function() { - var unloadUrl = function (url) { - tinymce.dom.ScriptLoader.ScriptLoader.remove(url); - tinymce.ThemeManager.remove(name); - }; - - var unloadTheme = function(name) { - unloadUrl(tinymce.baseURI.toAbsolute('themes/' + name + '/theme.min.js')); - unloadUrl(tinymce.baseURI.toAbsolute('themes/' + name + '/theme.js')); - }; - - tinymce.remove(); - - var init = function() { - tinymce.init({ - selector: "textarea", - init_instance_callback: function() { - tinymce.util.Delay.setTimeout(function() { - QUnit.start(); - }, 0); - } - }); - }; - - unloadTheme("modern"); - strictEqual(tinymce.get().length, 0); - - init(); - strictEqual(tinymce.get().length, 1); - - init(); - strictEqual(tinymce.get().length, 1); -}); - -test('overrideDefaults', function() { - var oldBaseURI, oldBaseUrl, oldSuffix; - - oldBaseURI = tinymce.baseURI; - oldBaseUrl = tinymce.baseURL; - oldSuffix = tinymce.suffix; - - tinymce.overrideDefaults({ - test: 42, - base_url: "http://www.tinymce.com/base/", - suffix: "x", - external_plugins: { - "plugina": "//domain/plugina.js", - "pluginb": "//domain/pluginb.js" - }, - plugin_base_urls: { - testplugin: 'http://custom.ephox.com/dir/testplugin' - } - }); - - strictEqual(tinymce.baseURI.path, "/base"); - strictEqual(tinymce.baseURL, "http://www.tinymce.com/base"); - strictEqual(tinymce.suffix, "x"); - strictEqual(new tinymce.Editor('ed1', {}, tinymce).settings.test, 42); - strictEqual(tinymce.PluginManager.urls.testplugin, 'http://custom.ephox.com/dir/testplugin'); - - deepEqual(new tinymce.Editor('ed2', { - external_plugins: { - "plugina": "//domain/plugina2.js", - "pluginc": "//domain/pluginc.js" - }, - plugin_base_urls: { - testplugin: 'http://custom.ephox.com/dir/testplugin' - } - }, tinymce).settings.external_plugins, { - "plugina": "//domain/plugina2.js", - "pluginb": "//domain/pluginb.js", - "pluginc": "//domain/pluginc.js" - }); - - deepEqual(new tinymce.Editor('ed3', {}, tinymce).settings.external_plugins, { - "plugina": "//domain/plugina.js", - "pluginb": "//domain/pluginb.js" - }); - - tinymce.baseURI = oldBaseURI; - tinymce.baseURL = oldBaseUrl; - tinymce.suffix = oldSuffix; - - tinymce.overrideDefaults({}); -}); - -test('Init inline editor on invalid targets', function() { - var invalidNames; - - invalidNames = ( - 'area base basefont br col frame hr img input isindex link meta param embed source wbr track ' + - 'colgroup option tbody tfoot thead tr script noscript style textarea video audio iframe object menu' - ); - - tinymce.remove(); - - tinymce.each(invalidNames.split(' '), function (invalidName) { - var elm = tinymce.DOM.add(document.body, invalidName, {'class': 'targetEditor'}, null); - - tinymce.init({ - selector: invalidName + '.targetEditor', - inline: true - }); - - strictEqual(tinymce.get().length, 0, 'Should not have created an editor'); - tinymce.DOM.remove(elm); - }); -}); diff --git a/tests/qunit/editor/tinymce/EditorUpload.js b/tests/qunit/editor/tinymce/EditorUpload.js deleted file mode 100644 index 6e80355133..0000000000 --- a/tests/qunit/editor/tinymce/EditorUpload.js +++ /dev/null @@ -1,324 +0,0 @@ -ModuleLoader.require([ - "tinymce/file/Conversions", - "tinymce/Env" -], function(Conversions, Env) { - var testBlobDataUri; - - if (!tinymce.Env.fileApi) { - return; - } - - module("tinymce.EditorUpload", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - skin: false, - entities: 'raw', - indent: false, - automatic_uploads: false, - init_instance_callback: function(ed) { - var canvas, context; - - window.editor = ed; - - canvas = document.createElement("canvas"); - canvas.width = 320; - canvas.height = 200; - - context = canvas.getContext("2d"); - context.fillStyle = "#ff0000"; - context.fillRect(0, 0, 160, 100); - context.fillStyle = "#00ff00"; - context.fillRect(160, 0, 160, 100); - context.fillStyle = "#0000ff"; - context.fillRect(0, 100, 160, 100); - context.fillStyle = "#ff00ff"; - context.fillRect(160, 100, 160, 100); - - testBlobDataUri = canvas.toDataURL(); - - Conversions.uriToBlob(testBlobDataUri).then(function() { - QUnit.start(); - }); - } - }); - }, - - teardown: function() { - editor.editorUpload.destroy(); - editor.settings.automatic_uploads = false; - delete editor.settings.images_replace_blob_uris; - delete editor.settings.images_dataimg_filter; - } - }); - - function imageHtml(uri) { - return tinymce.DOM.createHTML('img', {src: uri}); - } - - function assertResult(uploadedBlobInfo, result) { - QUnit.strictEqual(result.length, 1); - QUnit.strictEqual(result[0].status, true); - QUnit.ok(result[0].element.src.indexOf(uploadedBlobInfo.id() + '.png') !== -1); - QUnit.equal('

    ', editor.getContent()); - - return result; - } - - function hasBlobAsSource(elm) { - return elm.src.indexOf('blob:') === 0; - } - - asyncTest('_scanForImages', function() { - editor.setContent(imageHtml(testBlobDataUri)); - - editor._scanForImages().then(function(result) { - var blobInfo = result[0].blobInfo; - - QUnit.equal("data:" + blobInfo.blob().type + ";base64," + blobInfo.base64(), testBlobDataUri); - QUnit.equal(Utils.normalizeHtml(editor.getBody().innerHTML), '

    '); - QUnit.equal('

    ', editor.getContent()); - QUnit.strictEqual(editor.editorUpload.blobCache.get(blobInfo.id()), blobInfo); - }).then(QUnit.start); - }); - - asyncTest('replace uploaded blob uri with result uri (copy/paste of an uploaded blob uri)', function() { - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_upload_handler = function(data, success) { - success('file.png'); - }; - - editor._scanForImages().then(function(result) { - var blobUri = result[0].blobInfo.blobUri(); - - editor.uploadImages(function() { - editor.setContent(imageHtml(blobUri)); - QUnit.strictEqual(hasBlobAsSource(editor.$('img')[0]), false); - QUnit.strictEqual(editor.getContent(), '

    '); - QUnit.start(); - }); - }); - }); - - asyncTest('don\'t replace uploaded blob uri with result uri (copy/paste of an uploaded blob uri) since blob uris are retained', function() { - editor.settings.images_replace_blob_uris = false; - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_upload_handler = function(data, success) { - success('file.png'); - }; - - editor._scanForImages().then(function(result) { - var blobUri = result[0].blobInfo.blobUri(); - - editor.uploadImages(function() { - editor.setContent(imageHtml(blobUri)); - QUnit.strictEqual(hasBlobAsSource(editor.$('img')[0]), true); - QUnit.strictEqual(editor.getContent(), '

    '); - QUnit.start(); - }); - }); - }); - - asyncTest('uploadImages (callback)', function() { - var uploadedBlobInfo; - - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_upload_handler = function(data, success) { - uploadedBlobInfo = data; - success(data.id() + '.png'); - }; - - editor.uploadImages(function(result) { - assertResult(uploadedBlobInfo, result); - - editor.uploadImages(function(result) { - QUnit.strictEqual(result.length, 0); - QUnit.start(); - }); - }); - }); - - asyncTest('uploadImages (promise)', function() { - var uploadedBlobInfo; - - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_upload_handler = function(data, success) { - uploadedBlobInfo = data; - success(data.id() + '.png'); - }; - - editor.uploadImages().then(function(result) { - assertResult(uploadedBlobInfo, result); - }).then(function() { - uploadedBlobInfo = null; - - return editor.uploadImages().then(function(result) { - QUnit.strictEqual(result.length, 0); - QUnit.strictEqual(uploadedBlobInfo, null); - QUnit.start(); - }); - }); - }); - - asyncTest('uploadImages retain blob urls after upload', function() { - var uploadedBlobInfo; - - function assertResult(result) { - QUnit.strictEqual(result[0].status, true); - QUnit.ok(hasBlobAsSource(result[0].element), 'Not a blob url'); - QUnit.equal('

    ', editor.getContent()); - - return result; - } - - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_replace_blob_uris = false; - editor.settings.images_upload_handler = function(data, success) { - uploadedBlobInfo = data; - success(data.id() + '.png'); - }; - - editor.uploadImages(assertResult).then(assertResult).then(function() { - uploadedBlobInfo = null; - - return editor.uploadImages(function() {}).then(function(result) { - QUnit.strictEqual(result.length, 0); - QUnit.strictEqual(uploadedBlobInfo, null); - }); - }).then(QUnit.start); - }); - - asyncTest('uploadConcurrentImages', function() { - var uploadCount = 0, callCount = 0; - - function done(result) { - callCount++; - - if (callCount == 2) { - QUnit.start(); - equal(uploadCount, 1, 'Should only be one upload.'); - } - - equal(editor.getContent(), '

    '); - equal(result[0].element, editor.$('img')[0]); - equal(result[0].status, true); - } - - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_upload_handler = function(data, success) { - uploadCount++; - - setTimeout(function() { - success('myimage.png'); - }, 0); - }; - - editor.uploadImages(done); - editor.uploadImages(done); - }); - - asyncTest('uploadConcurrentImages (fail)', function() { - var uploadCount = 0, callCount = 0; - - function done(result) { - callCount++; - - if (callCount == 2) { - QUnit.start(); - // This is in exact since the status of the image can be pending or failed meaing it should try again - ok(uploadCount >= 1, 'Should at least be one.'); - } - - equal(result[0].element, editor.$('img')[0]); - equal(result[0].status, false); - } - - editor.setContent(imageHtml(testBlobDataUri)); - - editor.settings.images_upload_handler = function(data, success, failure) { - uploadCount++; - - setTimeout(function() { - failure('Error'); - }, 0); - }; - - editor.uploadImages(done); - editor.uploadImages(done); - }); - - asyncTest('Don\'t upload transparent image', function() { - var uploadCount = 0; - - function done() { - QUnit.start(); - equal(uploadCount, 0, 'Should not upload.'); - } - - editor.setContent(imageHtml(Env.transparentSrc)); - - editor.settings.images_upload_handler = function(data, success) { - uploadCount++; - success('url'); - }; - - editor.uploadImages(done); - }); - - asyncTest('Don\'t upload bogus image', function() { - var uploadCount = 0; - - function done() { - QUnit.start(); - equal(uploadCount, 0, 'Should not upload.'); - } - - editor.getBody().innerHTML = ''; - - editor.settings.images_upload_handler = function(data, success) { - uploadCount++; - success('url'); - }; - - editor.uploadImages(done); - }); - - asyncTest('Don\'t upload filtered image', function() { - var uploadCount = 0; - - function done() { - QUnit.start(); - equal(uploadCount, 0, 'Should not upload.'); - } - - editor.getBody().innerHTML = ( - '' - ); - - editor.settings.images_dataimg_filter = function(img) { - return !img.hasAttribute('data-skip'); - }; - - editor.settings.images_upload_handler = function(data, success) { - uploadCount++; - success('url'); - }; - - editor.uploadImages(done); - }); - - test('Retain blobs not in blob cache', function() { - editor.getBody().innerHTML = ''; - QUnit.equal('

    ', editor.getContent()); - }); -}); diff --git a/tests/qunit/editor/tinymce/Editor_rtl.js b/tests/qunit/editor/tinymce/Editor_rtl.js deleted file mode 100644 index 00909161a5..0000000000 --- a/tests/qunit/editor/tinymce/Editor_rtl.js +++ /dev/null @@ -1,55 +0,0 @@ -ModuleLoader.require([ - "tinymce/util/I18n", - "tinymce/ui/Control" -], function(I18n, Control) { - var scriptLoadedRtlState = {}; - - module("tinymce.Editor_rtl", { - setupModule: function() { - QUnit.stop(); - - tinymce.addI18n('ar', { - "Bold": "Bold test", - "_dir": "rtl" - }); - - tinymce.init({ - selector: "textarea", - toolbar: 'bold italic underline', - setup: function (editor) { - var beforeEventRtl = editor.rtl; - - editor.on('ScriptsLoaded', function () { - // We will know the rtl mode and code after all scripts have been loaded - scriptLoadedRtlState = { - beforeRtl: beforeEventRtl, - afterRtl: editor.rtl, - code: I18n.getCode() - }; - }); - }, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - }, - - teardown: function() { - I18n.rtl = false; - I18n.setCode('en'); - Control.rtl = false; - } - }); - - test('UI rendered in RTL mode', function() { - QUnit.equal(tinymce.activeEditor.getContainer().className.indexOf('mce-rtl') !== -1, true, 'Should have a mce-rtl class'); - QUnit.equal(tinymce.activeEditor.rtl, true, 'Should have the rtl property set'); - }); - - test('Rtl mode property set on editor instance and I18n global', function() { - QUnit.equal(scriptLoadedRtlState.beforeRtl, undefined, 'Should be undefined since we dont know the rtl mode yet'); - QUnit.equal(scriptLoadedRtlState.afterRtl, true, 'Should be true since we now know the rtl mode'); - QUnit.equal(scriptLoadedRtlState.code, 'ar', 'Should be "ar" since the code hass been changed during loading'); - }); -}); diff --git a/tests/qunit/editor/tinymce/EnterKey.js b/tests/qunit/editor/tinymce/EnterKey.js deleted file mode 100644 index bd6e9608d4..0000000000 --- a/tests/qunit/editor/tinymce/EnterKey.js +++ /dev/null @@ -1,1121 +0,0 @@ -module("tinymce.EnterKey", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - indent: false, - skin: false, - entities: 'raw', - schema: 'html5', - extended_valid_elements: 'div[id|style|contenteditable],span[id|style|contenteditable],#dt,#dd', - 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,position,top,left' - }, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - }, - - teardown: function() { - editor.settings.forced_root_block = 'p'; - editor.settings.forced_root_block_attrs = null; - editor.settings.end_container_on_empty_block = false; - editor.settings.br_in_pre = true; - editor.settings.keep_styles = true; - delete editor.settings.force_p_newlines; - } -}); - -test('Enter at end of H1', function() { - editor.setContent('

    abc

    '); - Utils.setSelection('h1', 3); - Utils.pressEnter(); - equal(editor.getContent(), '

    abc

    \u00a0

    '); - equal(editor.selection.getRng(true).startContainer.nodeName, 'P'); -}); - -test('Enter in midde of H1', function() { - editor.setContent('

    abcd

    '); - Utils.setSelection('h1', 2); - Utils.pressEnter(); - equal(editor.getContent(), '

    ab

    cd

    '); - equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'H1'); -}); - -test('Enter before text after EM', 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('

    '); - editor.selection.setCursorLocation(editor.getBody().firstChild, 0); - Utils.pressEnter(); - equal(editor.getContent(), '

    \u00a0

    '); -}); - -test('Enter before first wrapped IMG in P', function() { - editor.setContent('

    '); - editor.selection.setCursorLocation(editor.getBody().firstChild.firstChild, 0); - Utils.pressEnter(); - equal(editor.getBody().firstChild.innerHTML, (tinymce.isIE && tinymce.Env.ie < 11) ? '' : '
    '); - equal(editor.getContent(), '

    \u00a0

    '); -}); - -test('Enter before last IMG 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, 'IMG'); -}); - -test('Enter before last IMG 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, 'IMG'); -}); - -test('Enter after last IMG in P', function() { - editor.setContent('

    abc

    '); - editor.selection.setCursorLocation(editor.getBody().firstChild, 2); - Utils.pressEnter(); - equal(editor.getContent(), '

    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(/]+|)>| /g, ''), '

    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(/]+|)>| /g, ''), '

    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(/]+|)>| /g, ''), '

    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(/]+|)>| /g, ''), '

    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('

    abcd

    efgh

    '); - Utils.setSelection('h1', 2, 'p', 2); - Utils.pressEnter(); - equal(editor.getContent(), '

    abgh

    '); - equal(editor.selection.getNode().nodeName, 'H1'); -}); - -test('Enter at end of H1 in HGROUP', function() { - editor.setContent('

    abc

    '); - Utils.setSelection('h1', 3); - Utils.pressEnter(); - equal(editor.getContent(), '

    abc

    \u00a0

    '); - equal(editor.selection.getRng(true).startContainer.nodeName, 'H1'); -}); - -test('Enter inside empty TD', function() { - editor.getBody().innerHTML = '
    '; - Utils.setSelection('td', 0); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/]+|)>| /g, ''), '

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Shift+Enter inside STRONG inside TD with BR', function() { - editor.getBody().innerHTML = '
    d e
    '; - Utils.setSelection('strong', 1); - Utils.pressEnter({shiftKey: true}); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    d e

    '); - equal(editor.selection.getNode().nodeName, 'STRONG'); -}); - -test('Enter inside middle of text node in body', function() { - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 2); - Utils.pressEnter(); - equal(editor.getContent(), '

    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) ? '
    1. a
    ' : '

    1. a
    '; - Utils.setSelection('li', 0); - Utils.pressEnter(); - equal(editor.getContent(), '

    \u00a0

    1. a
    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside empty li at the end of ol', function() { - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. a
    ' : '
    1. a

    '; - Utils.setSelection('li:last', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. a

    \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) ? '
    1. a
    2. b
    ' : '
    1. a

    2. b
    '; - Utils.setSelection('li:nth-child(2)', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
    1. a

    \u00a0

    1. b
    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Shift+Enter inside empty li in beginning of ol', function() { - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. a
    ' : '

    1. a
    '; - Utils.setSelection('li', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '

    \u00a0

    1. a
    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Shift+Enter inside empty li at the end of ol', function() { - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. a
    ' : '
    1. a

    '; - Utils.setSelection('li:last', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
    1. a

    \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) ? '
    1. a
    2. b
    ' : '
    1. a

    2. b
    '; - Utils.setSelection('li:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. a

    1. b
    '); - equal(editor.selection.getNode().nodeName, 'BODY'); -}); - -test('Enter inside empty li in beginning of ol with forced_root_block: false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. a
    ' : '

    1. a
    '; - Utils.setSelection('li', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. a
    '); - equal(editor.selection.getNode().nodeName, 'BODY'); -}); - -test('Enter inside empty li at the end of ol with forced_root_block: false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. a
    ' : '
    1. a

    '; - Utils.setSelection('li:last', 0); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    1. a

    '); - equal(editor.selection.getNode().nodeName, 'BODY'); -}); - -test('Enter inside empty li in the middle of ol', function() { - editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. a
    2. b
    ' : '
    1. a

    2. b
    '; - Utils.setSelection('li:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. a

    \u00a0

    1. b
    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -// Nested lists in LI elements - -test('Enter inside empty LI in beginning of OL in LI', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a' + - '
        ' + - '

      1. ' + - '
      2. a
      3. ' + - '
      ' + - '
    2. ' + - '
    ' - ); - - Utils.setSelection('li li', 0); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a
    2. ' + - '
    3. ' + - '
        ' + - '
      1. a
      2. ' + - '
      ' + - '
    4. ' + - '
    ' - ); - - equal(editor.selection.getNode().nodeName, 'LI'); -}); - -test('Enter inside empty LI in middle of OL in LI', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a' + - '
        ' + - '
      1. a
      2. ' + - '

      3. ' + - '
      4. b
      5. ' + - '
      ' + - '
    2. ' + - '
    ' - ); - - Utils.setSelection('li li:nth-child(2)', 0); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a' + - '
        ' + - '
      1. a
      2. ' + - '
      ' + - '
    2. ' + - '
    3. \u00a0' + - '
        ' + - '
      1. b
      2. ' + - '
      ' + - '
    4. ' + - '
    ' - ); - - // Ignore on IE 7, 8 this is a known bug not worth fixing - if (!tinymce.Env.ie || tinymce.Env.ie > 8) { - equal(editor.selection.getNode().nodeName, 'LI'); - } -}); - -test('Enter inside empty LI in end of OL in LI', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a' + - '
        ' + - '
      1. a
      2. ' + - '

      3. ' + - '
      ' + - '
    2. ' + - '
    ' - ); - - Utils.setSelection('li li:last', 0); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a' + - '
        ' + - '
      1. a
      2. ' + - '
      ' + - '
    2. ' + - '
    3. ' + - '
    ' - ); - - equal(editor.selection.getNode().nodeName, 'LI'); -}); - -// Nested lists in OL elements - -// Ignore on IE 7, 8 this is a known bug not worth fixing -if (!tinymce.Env.ie || tinymce.Env.ie > 8) { - test('Enter before nested list', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a' + - '
        ' + - '
      • b
      • ' + - '
      • c
      • ' + - '
      ' + - '
    2. ' + - '
    ' - ); - - Utils.setSelection('ol > li', 1); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a
    2. ' + - '
    3. \u00a0' + - '
        ' + - '
      • b
      • ' + - '
      • c
      • ' + - '
      ' + - '
    4. ' + - '
    ' - ); - - equal(editor.selection.getNode().nodeName, 'LI'); - }); -} - -test('Enter inside empty LI in beginning of OL in OL', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a
    2. ' + - '
        ' + - '

      1. ' + - '
      2. a
      3. ' + - '
      ' + - '
    ' - ); - - Utils.setSelection('ol ol li', 0); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a
    2. ' + - '
    3. ' + - '
        ' + - '
      1. a
      2. ' + - '
      ' + - '
    ' - ); - - equal(editor.selection.getNode().nodeName, 'LI'); -}); - -test('Enter inside empty LI in middle of OL in OL', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a
    2. ' + - '
        ' + - '
      1. a
      2. ' + - '

      3. ' + - '
      4. b
      5. ' + - '
      ' + - '
    ' - ); - - Utils.setSelection('ol ol li:nth-child(2)', 0); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a
    2. ' + - '
        ' + - '
      1. a
      2. ' + - '
      ' + - '
    3. ' + - '
        ' + - '
      1. b
      2. ' + - '
      ' + - '
    ' - ); - - equal(editor.selection.getNode().nodeName, 'LI'); -}); - -test('Enter inside empty LI in end of OL in OL', function() { - editor.getBody().innerHTML = Utils.trimBrsOnIE( - '
      ' + - '
    1. a
    2. ' + - '
        ' + - '
      1. a
      2. ' + - '

      3. ' + - '
      ' + - '
    ' - ); - - Utils.setSelection('ol ol li:last', 0); - editor.focus(); - Utils.pressEnter(); - - equal(editor.getContent(), - '
      ' + - '
    1. a
    2. ' + - '
        ' + - '
      1. a
      2. ' + - '
      ' + - '
    3. ' + - '
    ' - ); - - equal(editor.selection.getNode().nodeName, 'LI'); -}); - -test('Enter at beginning of first DT inside DL', function() { - editor.getBody().innerHTML = '
    a
    '; - Utils.setSelection('dt', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    \u00a0
    a
    '); - equal(editor.selection.getNode().nodeName, 'DT'); -}); - -test('Enter at beginning of first DD inside DL', function() { - editor.getBody().innerHTML = '
    a
    '; - Utils.setSelection('dd', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    \u00a0
    a
    '); - equal(editor.selection.getNode().nodeName, 'DD'); -}); - -test('Enter at beginning of middle DT inside DL', function() { - editor.getBody().innerHTML = '
    a
    b
    c
    '; - Utils.setSelection('dt:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    a
    \u00a0
    b
    c
    '); - equal(editor.selection.getNode().nodeName, 'DT'); -}); - -test('Enter at beginning of middle DD inside DL', function() { - editor.getBody().innerHTML = '
    a
    b
    c
    '; - Utils.setSelection('dd:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    a
    \u00a0
    b
    c
    '); - equal(editor.selection.getNode().nodeName, 'DD'); -}); - -test('Enter at end of last DT inside DL', function() { - editor.getBody().innerHTML = '
    a
    '; - Utils.setSelection('dt', 1); - Utils.pressEnter(); - equal(editor.getContent(), '
    a
    \u00a0
    '); - equal(editor.selection.getNode().nodeName, 'DT'); -}); - -test('Enter at end of last DD inside DL', function() { - editor.getBody().innerHTML = '
    a
    '; - Utils.setSelection('dd', 1); - Utils.pressEnter(); - equal(editor.getContent(), '
    a
    \u00a0
    '); - equal(editor.selection.getNode().nodeName, 'DD'); -}); - -test('Enter at end of last empty DT inside DL', function() { - editor.getBody().innerHTML = '
    a
    '; - Utils.setSelection('dt:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    a

    \u00a0

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter at end of last empty DD inside DL', function() { - editor.getBody().innerHTML = '
    a
    '; - Utils.setSelection('dd:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    a

    \u00a0

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter at beginning of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 0); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. abcd

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Enter inside middle of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 2); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. ab

    2. cd

    '); - - // Ignore on IE 7, 8 this is a known bug not worth fixing - if (!tinymce.Env.ie || tinymce.Env.ie > 8) { - equal(editor.selection.getNode().nodeName, 'P'); - } -}); - -test('Enter at end of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 4); - Utils.pressEnter(); - equal(editor.getContent(), '
    1. abcd

    '); - equal(editor.selection.getNode().nodeName, 'LI'); -}); - - -test('Shift+Enter at beginning of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 0); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '

    1. abcd

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Shift+Enter inside middle of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 2); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
    1. ab
      cd

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Shift+Enter at end of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 4); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), (tinymce.isIE && tinymce.Env.ie < 11) ? '
    1. abcd

    ' : '
    1. abcd

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - - -test('Ctrl+Enter at beginning of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 0); - Utils.pressEnter({ctrlKey: true}); - equal(editor.getContent(), '
    1. \u00a0

      abcd

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Ctrl+Enter inside middle of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 2); - Utils.pressEnter({ctrlKey: true}); - equal(editor.getContent(), '
    1. ab

      cd

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Ctrl+Enter at end of P inside LI', function() { - editor.getBody().innerHTML = '
    1. abcd

    '; - Utils.setSelection('p', 4); - Utils.pressEnter({ctrlKey: true}); - equal(editor.getContent(), '
    1. abcd

      \u00a0

    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - - -test('Enter in the middle of text in P with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = '

    abc

    '; - Utils.setSelection('p', 2); - Utils.pressEnter(); - equal(editor.getContent(), '

    ab
    c

    '); -}); - -test('Enter at the end of text in 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(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? '

    abc

    ' : '

    abc

    '); -}); - -test('Enter at the middle of text in BODY with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 2); - editor.focus(); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), 'ab
    cd'); -}); - -test('Enter at the beginning of text in BODY with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 0); - editor.focus(); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    abcd'); -}); - -test('Enter at the end of text in BODY with forced_root_block set to false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 4); - editor.focus(); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? 'abcd
    ' : 'abcd

    '); -}); - -test('Enter in empty P at the end 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


    '; - Utils.setSelection('p:last', 0); - Utils.pressEnter(); - equal(editor.getContent(), '

    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

    ' : '


    abc

    '; - Utils.setSelection('p', 0); - Utils.pressEnter(); - equal(editor.getContent(), '

    \u00a0

    abc

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

    123

    ' : '

    abc


    123

    '; - Utils.setSelection('p:nth-child(2)', 0); - Utils.pressEnter(); - equal(editor.getContent(), '

    abc

    \u00a0

    123

    '); -}); - -test('Enter inside empty P with empty P siblings', function() { - // Tests that a workaround for an IE bug is working correctly - editor.getBody().innerHTML = '

    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 = '

    a

    '; - Utils.setSelection('h1', 1); - Utils.pressEnter(); - equal(editor.getContent(), '

    a

    \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

    '); -}); - -test('Shift+Enter in the middle of P', function() { - 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', function() { - editor.getBody().innerHTML = '

    abcd

    '; - Utils.setSelection('p', 4); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), (tinymce.isIE && tinymce.Env.ie < 11) ? '

    abcd

    ' : '

    abcd

    '); -}); - -test('Shift+Enter in the middle of B with a BR after it', function() { - editor.getBody().innerHTML = '

    abcd

    '; - Utils.setSelection('b', 2); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '

    ab
    cd

    '); -}); - -test('Shift+Enter at the end of B with a BR after it', function() { - editor.getBody().innerHTML = '

    abcd

    '; - Utils.setSelection('b', 4); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '

    abcd

    '); -}); - -test('Enter in beginning of PRE', function() { - editor.getBody().innerHTML = '
    abc
    '; - Utils.setSelection('pre', 0); - Utils.pressEnter(); - equal(editor.getContent(), '

    abc
    '); -}); - -test('Enter in the middle of PRE', function() { - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('pre', 2); - Utils.pressEnter(); - equal(editor.getContent(), '
    ab
    cd
    '); -}); - -test('Enter at the end of PRE', function() { - editor.getBody().innerHTML = '
    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
    '); - Utils.setSelection('div', 4); - Utils.pressEnter(); - equal(editor.getContent(), '

    abcd

    \u00a0

    '); -}); - -test('Enter in div inside contentEditable:false div', function() { - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('div div', 2); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    abcd
    '); -}); - -test('Enter in div with contentEditable:true inside contentEditable:false div', function() { - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('div div', 2); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '

    ab

    cd

    '); -}); - -test('Enter in span with contentEditable:true inside contentEditable:false div', function() { - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('span', 2); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    abcd
    '); -}); - -test('Shift+Enter in span with contentEditable:true inside contentEditable:false div', function() { - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('span', 2); - Utils.pressEnter({shiftKey: true}); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    ab
    cd
    '); -}); - -test('Enter in span with contentEditable:true inside contentEditable:false div and forced_root_block: false', function() { - editor.settings.forced_root_block = false; - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('span', 2); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    ab
    cd
    '); -}); - -test('Enter in em within contentEditable:true div inside contentEditable:false div', function() { - editor.getBody().innerHTML = '
    abcd
    '; - Utils.setSelection('em', 2); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '

    ab

    cd

    '); -}); - -test('Enter at end of text in a span inside a P and keep_styles: false', function() { - editor.settings.keep_styles = false; - editor.getBody().innerHTML = '

    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 = '
    • text
    '; - Utils.setSelection('li', 2); - Utils.pressEnter({shiftKey: true}); - equal(editor.getContent(), '
    • te
      xt
    '); -}); - -test('Enter when forced_root_block: false and force_p_newlines: true', function() { - editor.settings.forced_root_block = false; - editor.settings.force_p_newlines = true; - editor.getBody().innerHTML = 'text'; - Utils.setSelection('body', 2); - Utils.pressEnter(); - equal(editor.getContent(), '

    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

    '; - Utils.setSelection('p', 1); - Utils.pressEnter(); - equal(editor.getContent(), '

    a


    b

    '); - - var rng = editor.selection.getRng(true); - equal(rng.startContainer.nodeName, 'P'); - equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'BR'); -}); - -// Ignore on IE 7, 8 this is a known bug not worth fixing -if (!tinymce.Env.ie || tinymce.Env.ie > 8) { - test('Enter before BR between DIVs', function() { - editor.getBody().innerHTML = '
    abc

    d
    '; - var rng = editor.dom.createRng(); - rng.setStartBefore(editor.dom.select('br')[0]); - rng.setEndBefore(editor.dom.select('br')[0]); - editor.selection.setRng(rng); - Utils.pressEnter(); - equal(editor.getContent(), '
    abc

    \u00a0

    \u00a0

    d
    '); - }); -} - -// Only test these on modern browsers -if (window.getSelection) { - test('Enter behind table element', function() { - var rng = editor.dom.createRng(); - - editor.getBody().innerHTML = '
    x
    '; - rng.setStartAfter(editor.getBody().lastChild); - rng.setEndAfter(editor.getBody().lastChild); - editor.selection.setRng(rng); - - Utils.pressEnter(); - equal(editor.getContent(), '
    x

    \u00a0

    '); - }); - - test('Enter before table element', function() { - var rng = editor.dom.createRng(); - - editor.getBody().innerHTML = '
    x
    '; - rng.setStartBefore(editor.getBody().lastChild); - rng.setEndBefore(editor.getBody().lastChild); - editor.selection.setRng(rng); - - Utils.pressEnter(); - equal(editor.getContent(), '

    \u00a0

    x
    '); - }); - - test('Enter behind table followed by a p', function() { - var rng = editor.dom.createRng(); - - editor.getBody().innerHTML = '
    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
    '; - rng.setStartBefore(editor.getBody().lastChild); - rng.setStartBefore(editor.getBody().lastChild); - editor.selection.setRng(rng); - - Utils.pressEnter(); - equal(editor.getContent(), '

    x

    \u00a0

    x
    '); - }); - - test('Enter twice before table element', function(){ - var rng = editor.dom.createRng(); - - editor.getBody().innerHTML = '
    x
    '; - rng.setStartBefore(editor.getBody().lastChild); - rng.setEndBefore(editor.getBody().lastChild); - editor.selection.setRng(rng); - - Utils.pressEnter(); - Utils.pressEnter(); - equal(editor.getContent(), '

    \u00a0

    \u00a0

    x
    '); - }); - - test('Enter after span with space', function() { - editor.setContent('

    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 = '
    x
    '; - editor.selection.select(editor.dom.select('div')[0]); - editor.selection.collapse(true); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '


    x
    '); - equal(editor.selection.getNode().nodeName, 'P'); - }); - - test('Enter after cE=false div', function() { - editor.getBody().innerHTML = '
    x
    '; - editor.selection.select(editor.dom.select('div')[0]); - editor.selection.collapse(false); - Utils.pressEnter(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    x


    '); - equal(editor.selection.getNode().nodeName, 'P'); - }); -} - diff --git a/tests/qunit/editor/tinymce/FocusManager.js b/tests/qunit/editor/tinymce/FocusManager.js deleted file mode 100644 index 204e5695a3..0000000000 --- a/tests/qunit/editor/tinymce/FocusManager.js +++ /dev/null @@ -1,46 +0,0 @@ -ModuleLoader.require([ - "tinymce/FocusManager", - "tinymce/dom/DOMUtils" -], function (FocusManager, DOMUtils) { - var DOM = DOMUtils.DOM; - - module("tinymce.FocusManager", { - 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(); - } - }); - } - }); - - test('isEditorUIElement on valid element', function () { - var uiElm = DOM.create('div', {'class': 'mce-abc'}, null); - equal(FocusManager.isEditorUIElement(uiElm), true, 'Should be true since mce- is a ui prefix'); - }); - - test('isEditorUIElement on invalid element', function () { - var noUiElm = DOM.create('div', {'class': 'mcex-abc'}, null); - equal(FocusManager.isEditorUIElement(noUiElm), false, 'Should be true since mcex- is not a ui prefix'); - }); - - test('_isUIElement on valid element', function () { - var uiElm1 = DOM.create('div', {'class': 'mce-abc'}, null); - var uiElm2 = DOM.create('div', {'class': 'mcex-abc'}, null); - var noUiElm = DOM.create('div', {'class': 'mcey-abc'}, null); - editor.settings.custom_ui_selector = '.mcex-abc'; - equal(FocusManager._isUIElement(editor, uiElm1), true, 'Should be true since mce- is a ui prefix'); - equal(FocusManager._isUIElement(editor, uiElm2), true, 'Should be true since mcex- is a ui prefix'); - equal(FocusManager._isUIElement(editor, noUiElm), false, 'Should be true since mcey- is not a ui prefix'); - delete editor.settings.custom_ui_selector; - }); -}); diff --git a/tests/qunit/editor/tinymce/ForceBlocks.js b/tests/qunit/editor/tinymce/ForceBlocks.js deleted file mode 100644 index cd99bbe182..0000000000 --- a/tests/qunit/editor/tinymce/ForceBlocks.js +++ /dev/null @@ -1,87 +0,0 @@ -module("tinymce.ForceBlocks", { - autostart: false, - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - indent: false, - 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; - QUnit.start(); - } - }); - }, - - teardown: function() { - editor.settings.forced_root_block = 'p'; - editor.settings.forced_root_block_attrs = null; - } -}); - -test('Wrap single root text node in P', function() { - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 2); - Utils.pressArrowKey(); - equal(Utils.cleanHtml(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
    '; - Utils.setSelection('body', 2); - Utils.pressArrowKey(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '

    abcd

    x
    '); - equal(editor.selection.getNode().nodeName, 'P'); -}); - -test('Wrap root em in P but not table sibling', function() { - editor.getBody().innerHTML = 'abcd
    x
    '; - Utils.setSelection('em', 2); - Utils.pressArrowKey(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '

    abcd

    x
    '); - equal(editor.selection.getNode().nodeName, 'EM'); -}); - -test('Wrap single root text node in DIV', function() { - editor.settings.forced_root_block = 'div'; - editor.getBody().innerHTML = 'abcd'; - Utils.setSelection('body', 2); - Utils.pressArrowKey(); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    abcd
    '); - equal(editor.selection.getNode().nodeName, 'DIV'); -}); - -test('Remove empty root text nodes', function() { - var body = editor.getBody(); - - editor.settings.forced_root_block = 'div'; - editor.getBody().innerHTML = 'abcd
    abcd
    '; - body.insertBefore(editor.getDoc().createTextNode(''), body.firstChild); - body.appendChild(editor.getDoc().createTextNode('')); - - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody().childNodes[1], 1); - rng.setEnd(editor.getBody().childNodes[1], 1); - editor.selection.setRng(rng); - - Utils.pressArrowKey(); - equal(Utils.cleanHtml(body.innerHTML), '
    abcd
    abcd
    '); - equal(editor.selection.getNode().nodeName, 'DIV'); - equal(body.childNodes.length, 2); -}); diff --git a/tests/qunit/editor/tinymce/Formatter_apply.js b/tests/qunit/editor/tinymce/Formatter_apply.js deleted file mode 100644 index f52148767d..0000000000 --- a/tests/qunit/editor/tinymce/Formatter_apply.js +++ /dev/null @@ -1,1795 +0,0 @@ -module("tinymce.Formatter - Apply", { - setupModule: function() { - document.getElementById('view').innerHTML = '
    '; - QUnit.stop(); - - tinymce.init({ - selector: "#elm1", - external_plugins: { noneditable: '../../../../tests/qunit/editor/external-plugins/noneditable/plugin.min.js' }, // WP - add_unload_trigger: false, - skin: false, - indent: false, - extended_valid_elements: 'b[id|style|title],i[id|style|title],span[id|class|style|title|contenteditable],font[face|size]', - forced_root_block: '', - 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(); - window.editor = ed; - } - }); - } -}); - -function getContent() { - return editor.getContent().toLowerCase().replace(/[\r]+/g, ''); -} - -test('apply inline to a list', function() { - editor.formatter.register('format', { - inline: 'b', - toggle: false - }); - editor.getBody().innerHTML = '

    1234

    • first element
    • second element

    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

    • first element
    • second element

    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
    ', 'Block element on selected text'); -}); - -test('Block element on partially 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, 1); - rng.setEnd(editor.dom.select('p')[0].firstChild, 3); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '
    1234
    ', 'Block element on partially selected text'); -}); - -test('Block element on selected element', function() { - editor.formatter.register('format', { - block: 'div' - }); - 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
    ', 'Block element on selected element'); -}); - -test('Block element on selected elements', function() { - editor.formatter.register('format', { - block: 'div' - }); - editor.getBody().innerHTML = '

    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
    ', 'Block element on selected elements'); -}); - -test('Block element on selected elements with attributes', function() { - editor.formatter.register('format', { - block: 'div', - attributes: { - 'title': 'test' - } - }); - editor.getBody().innerHTML = '

    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
    ', 'Block element on selected elements with attributes'); -}); - -test('Block element on nested element', function() { - editor.formatter.register('format', { - block: 'p' - }); - editor.getBody().innerHTML = '

    1234

    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('h1')[0].firstChild, 0); - rng.setEnd(editor.dom.select('h1')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '

    1234

    ', 'Block element on nested element'); -}); - -test('Block element on selected non wrapped text 1', function() { - editor.formatter.register('format', { - block: 'div' - }); - editor.getBody().innerHTML = '1234'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 0); - rng.setEnd(editor.getBody().firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '
    1234
    ', 'Block element on selected non wrapped text 1'); -}); - -test('Block element on selected non wrapped text 2', function() { - editor.formatter.register('format', { - block: 'div' - }); - editor.getBody().innerHTML = '1234
    4567
    8910'; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 0); - rng.setEnd(editor.getBody().lastChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '
    1234
    4567
    8910
    ', 'Block element on selected non wrapped text 2'); -}); - -test('Block element on selected non wrapped text 3', function() { - editor.formatter.register('format', { - block: 'div' - }); - editor.getBody().innerHTML = '
    1234

    4567
    8910
    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 7); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '
    1234
    4567
    8910
    ', 'Block element on selected non wrapped text 3'); -}); - -test('Block element wrapper 1', function() { - editor.formatter.register('format', { - block: 'blockquote', - wrapper: 1 - }); - editor.getBody().innerHTML = '

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

    1234

    5678

    ', 'Block element wrapper 1'); -}); - -test('Block element wrapper 2', function() { - editor.formatter.register('format', { - block: 'blockquote', - wrapper: 1 - }); - editor.getBody().innerHTML = '

    1234

    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('h1')[0].firstChild, 0); - rng.setEnd(editor.dom.select('h1')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '

    1234

    ', 'Block element wrapper 2'); -}); - -test('Block element wrapper 3', function() { - editor.formatter.register('format', { - block: 'blockquote', - wrapper: 1 - }); - editor.getBody().innerHTML = '

    1234


    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody(), 0); - rng.setEnd(editor.getBody(), 3); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '

    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

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

    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('div')[0], 1); - rng.setEnd(editor.dom.select('div')[0], 2); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '

    1234

    test

    1234

    ', 'Apply format on single element parent that matches a selector'); -}); - -test('Apply format on multiple elements that matches a selector 2', function() { - editor.formatter.register('format', { - selector: 'p', - attributes: { - title: 'test' - }, - styles: { - 'color': '#ff0000' - }, - classes: 'a b c' - }); - editor.getBody().innerHTML = '

    1234

    test

    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

    test

    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 = '
    text
    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('div')[0], 0); - rng.setEnd(editor.dom.select('div')[0], 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '
    text
    ', 'Apply format on single element that matches a selector'); -}); - -test('Format on single div that matches a selector', function() { - editor.formatter.register('format', { - inline: 'span', - selector: 'div', - attributes: { - title: 'test' - }, - styles: { - 'color': '#ff0000' - }, - classes: 'a b c' - }); - editor.getBody().innerHTML = '
    text
    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('div')[0], 0); - rng.setEnd(editor.dom.select('div')[0], 1); - editor.selection.setRng(rng); - editor.formatter.apply('format'); - equal(getContent(), '
    text
    ', 'Apply format on single element that matches a selector'); -}); - -test('Bold and italics is applied to text that is not highlighted', function() { - var rng = editor.dom.createRng(); - editor.setContent('

    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('
    • text
      • nested
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('li')[0].firstChild, 0); - rng.setEnd(editor.dom.select('li')[0].firstChild, 1); - editor.selection.setRng(rng); - editor.formatter.apply("h1"); - equal(editor.getContent(), '
    • text

      • nested
    ', "heading should not automatically apply to sublists"); -}); - -test("Applying formats on a list including child nodes", function(){ - editor.formatter.register('format', {inline: 'strong'}); - editor.setContent('
    1. a
    2. b
      • c
      • d
        1. e
        2. f
    3. g
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('li')[0].firstChild, 0); - rng.setEnd(editor.dom.select('li')[6].firstChild, 1); - editor.selection.setRng(rng); - editor.formatter.apply("format"); - equal(editor.getContent(), '
    1. a
    2. b
      • c
      • d
        1. e
        2. f
    3. g
    ', "should be applied to all sublists"); -}); - -test('Block format on li element', function() { - editor.setContent('
    • text
      • nested
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('li')[0].firstChild, 0); - rng.setEnd(editor.dom.select('li')[1].firstChild, 1); - editor.selection.setRng(rng); - editor.formatter.apply("h1"); - equal(editor.getContent(), '
    • text

      • nested

    ', "heading should automatically apply to sublists, when selection spans the sublist"); -}); - -test('Block on li element 2', function() { - editor.setContent('
    • before
      • nested
      after
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('li')[0].lastChild, 1); - rng.setEnd(editor.dom.select('li')[0].lastChild, 2); - editor.selection.setRng(rng); - editor.formatter.apply("h1"); - equal(editor.getContent(), '
    • before
      • nested

      after

    ', "heading should automatically apply to sublists, when selection spans the sublist"); -}); - -test('Block on li element 3', function() { - editor.setContent('
    • before
      • nested
      after
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('li')[1].firstChild, 0); - rng.setEnd(editor.dom.select('li')[0].lastChild, 1); - editor.selection.setRng(rng); - editor.formatter.apply("h1"); - equal(editor.getContent(), '
    • before
      • nested

      after

    ', "heading should automatically apply to sublists, when selection spans the sublist"); -}); - -test('Block on li element 4', function() { - editor.setContent('
    • before
      • nested
      after
    '); - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('li')[0].firstChild, 0); - rng.setEnd(editor.dom.select('li')[0].lastChild, 1); - editor.selection.setRng(rng); - editor.formatter.apply("h1"); - equal(editor.getContent(), '
    • before

      • nested

      after

    ', "heading should apply correctly when selection is after a sublist"); -}); - -test('Underline colors 1', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - 'color': '#ff0000' - } - }); - 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('
    • one
      • two
    '); - editor.formatter.register('format', { - inline: 'b' - }); - Utils.setSelection('ul li li', 1, 'ul li li', 1); - editor.formatter.apply('format'); - equal(editor.getContent(), '
    • one
      • two
    '); -}); - -test('Selector format on whole contents', 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

    '); -}); - -test('Del element replacing block', function() { - editor.setContent('

    a

    '); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.register('format', { - block: 'del' - }); - editor.formatter.apply('format'); - equal(getContent(), 'a'); -}); - -test('Del element as inline', function() { - editor.setContent('

    a

    '); - Utils.setSelection('p', 0, 'p', 1); - editor.formatter.register('format', { - inline: 'del' - }); - editor.formatter.apply('format'); - equal(getContent(), '

    a

    '); -}); - -test('Align specified table element with collapsed: false and selection collapsed', function() { - editor.setContent('
    a
    '); - Utils.setSelection('td', 0, 'td', 0); - editor.formatter.register('format', { - selector: 'table', - collapsed: false, - styles: { - 'float': 'right' - } - }); - editor.formatter.apply('format', {}, editor.getBody().firstChild); - equal(getContent(), '
    a
    '); -}); - -test('Align nested table cell to same as parent', function() { - editor.setContent( - '' + - '' + - '' + - '' + - '' + - '' + - '
    a' + - '' + - '' + - '' + - '' + - '' + - '' + - '
    b
    ' + - '
    ' - ); - - Utils.setSelection('b', 0); - - editor.formatter.register('format', { - selector: 'td', - styles: { - 'text-align': 'right' - } - }); - - editor.formatter.apply('format', {}, editor.$('td td')[0]); - - equal( - getContent(), - '' + - '' + - '' + - '' + - '' + - '' + - '
    a' + - '' + - '' + - '' + - '' + - '' + - '' + - '
    b
    ' + - '
    ' - ); -}); - -test('Apply ID format to around existing bookmark node', function() { - editor.getBody().innerHTML = '

    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
    '); - Utils.setSelection('td', 1, 'td', 1); - editor.formatter.register('format', { - block: 'h1' - }); - editor.formatter.apply('format'); - equal(getContent(), '

    abc

    123
    '); -}); - -test('Bug #6471 - Merge left/right style properties', function() { - editor.formatter.register('format', { - inline: 'span', - styles: { - fontWeight: 'bold' - } - }); - editor.setContent('

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

    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("
    one
    two
    "); - editor.focus(); - Utils.setSelection('#a', 0, '#b', 0); - editor.execCommand('formatBlock', false, 'h1'); - equal(getContent(), '

    one

    two
    '); -}); - -test('Format selection over fragments', 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

    '; - var rng = editor.dom.createRng(); - rng.setStart(editor.dom.select('h1')[0].firstChild, 0); - rng.setEnd(editor.dom.select('h1')[0].firstChild, 4); - editor.selection.setRng(rng); - editor.formatter.remove('format'); - equal(getContent(), '

    text

    ', 'Remove block format'); -}); - -test('Remove wrapper block format', function() { - editor.formatter.register('format', {block : 'blockquote', wrapper : true}); - editor.getBody().innerHTML = '

    text

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

    ', '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
    '); - editor.formatter.register('format', {inline: 'b'}); - Utils.setSelection('b', 2, 'b', 2); - editor.formatter.remove('format'); - equal(editor.getContent(), '
    one two
    '); -}); - -test('contentEditable: false on start and contentEditable: true on end', function() { - if (tinymce.Env.ie) { - ok("Skipped since IE doesn't support selection of parts of a cE=false element", true); - return; - } - - editor.formatter.register('format', {inline: 'b'}); - editor.setContent('

    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

    def

    '); - Utils.setSelection('h1:nth-child(2)', 0, 'h1:nth-child(2)', 3); - editor.formatter.remove('format'); - equal(editor.getContent(), '

    abc

    def

    ', 'H1 is still not h1'); -}); - -test('remove format on del using removeformat format', function() { - editor.getBody().innerHTML = '

    abc

    '; - Utils.setSelection('del', 0, 'del', 3); - editor.formatter.remove('removeformat'); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '

    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('
    • 12
    '); - editor.focus(); - Utils.setSelection('li', 0); - InsertContent.insertAtCaret(editor, {content: '
    • a
    ', paste: true}); - equal(editor.getContent(), '
    • a
    • 12
    '); - assertSelection('li:nth-child(2)', 0); - }); - - test('insertAtCaret - ul with multiple items at beginning of li', function() { - editor.setContent('
    • 12
    '); - editor.focus(); - Utils.setSelection('li', 0); - InsertContent.insertAtCaret(editor, {content: '
    • a
    • b
    ', paste: true}); - equal(editor.getContent(), '
    • a
    • b
    • 12
    '); - assertSelection('li:nth-child(3)', 0); - }); - - test('insertAtCaret - ul at end of li', function() { - editor.setContent('
    • 12
    '); - editor.focus(); - Utils.setSelection('li', 2); - InsertContent.insertAtCaret(editor, {content: '
    • a
    ', paste: true}); - equal(editor.getContent(), '
    • 12
    • a
    '); - assertSelection('li:nth-child(2)', 1); - }); - - test('insertAtCaret - ul with multiple items at end of li', function() { - editor.setContent('
    • 12
    '); - editor.focus(); - Utils.setSelection('li', 2); - InsertContent.insertAtCaret(editor, {content: '
    • a
    • b
    • c
    ', paste: true}); - equal(editor.getContent(), '
    • 12
    • a
    • b
    • c
    '); - assertSelection('li:nth-child(4)', 1); - }); - - test('insertAtCaret - ul with multiple items in middle of li', function() { - editor.setContent('
    • 12
    '); - editor.focus(); - Utils.setSelection('li', 1); - InsertContent.insertAtCaret(editor, {content: '
    • a
    • b
    ', paste: true}); - equal(editor.getContent(), '
    • 1
    • a
    • b
    • 2
    '); - assertSelection('li:nth-child(4)', 1); - }); - - test('insertAtCaret - ul in middle of li with formatting', function() { - editor.setContent('
    • 12
    '); - editor.focus(); - Utils.setSelection('strong', 1); - InsertContent.insertAtCaret(editor, {content: '
    • a
    ', paste: true}); - equal(editor.getContent(), '
    • 1
    • a
    • 2
    '); - assertSelection('li:nth-child(3) strong', 1); - }); - - test('insertAtCaret - ul at beginning of li with empty end li', function() { - editor.setContent('
    • 12
    '); - editor.focus(); - Utils.setSelection('li', 0); - InsertContent.insertAtCaret(editor, {content: '
    • a
    ', paste: true}); - equal(editor.getContent(), '
    • a
    • 12
    '); - assertSelection('li:nth-child(2)', 0); - }); - - test('insertAtCaret - merge inline elements', function() { - editor.setContent('abc'); - editor.focus(); - Utils.setSelection('em', 1); - InsertContent.insertAtCaret(editor, {content: '123', merge: true}); - equal(editor.getContent(), '

    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(/
    /g, ''); - }; - - test('insertAtCaret - selected image with bogus div', function() { - editor.getBody().innerHTML = '
    x
    '; - editor.focus(); - // editor.selection.setCursorLocation(editor.getBody(), 0); - editor.selection.select(editor.dom.select('img')[0]); - InsertContent.insertAtCaret(editor, 'a'); - equal(trimBrs(editor.getBody().innerHTML), 'a
    x
    '); - }); - - test('insertAtCaret - selected text with bogus div', function() { - editor.getBody().innerHTML = 'a
    x
    '; - editor.focus(); - var rng = editor.dom.createRng(); - rng.setStart(editor.getBody().firstChild, 0); - rng.setEnd(editor.getBody().firstChild, 1); - editor.selection.setRng(rng); - InsertContent.insertAtCaret(editor, 'b'); - equal(trimBrs(editor.getBody().innerHTML), 'b
    x
    '); - }); -}); diff --git a/tests/qunit/editor/tinymce/InsertList.js b/tests/qunit/editor/tinymce/InsertList.js deleted file mode 100644 index df6e38c8ca..0000000000 --- a/tests/qunit/editor/tinymce/InsertList.js +++ /dev/null @@ -1,41 +0,0 @@ -ModuleLoader.require([ - "tinymce/InsertList", - "tinymce/html/Node", - "tinymce/html/DomParser", - "tinymce/dom/DOMUtils" -], function(InsertList, Node, DomParser, DOMUtils) { - module("tinymce.InsertList", {}); - - var createFragment = function(html) { - var parser = new DomParser({validate: false}); - var fragment = parser.parse(html); - - return fragment; - }; - - var createDomFragment = function(html) { - return DOMUtils.DOM.createFragment(html); - }; - - test('isListFragment', function() { - equal(InsertList.isListFragment(createFragment('
    • x
    ')), true); - equal(InsertList.isListFragment(createFragment('
    1. x
    ')), true); - equal(InsertList.isListFragment(createFragment('
    • x
    ')), true); - equal(InsertList.isListFragment(createFragment('
    • x
    ')), true); - equal(InsertList.isListFragment(createFragment('
    ')), false); - }); - - test('listItems', function() { - var list = createDomFragment('
    • a
    • b
    • c
    ').firstChild; - - equal(InsertList.listItems(list).length, 3); - equal(InsertList.listItems(list)[0].nodeName, 'LI'); - }); - - test('trimListItems', function() { - var list = createDomFragment('
    • a
    • b
    ').firstChild; - - equal(InsertList.listItems(list).length, 3); - equal(InsertList.trimListItems(InsertList.listItems(list)).length, 2); - }); -}); diff --git a/tests/qunit/editor/tinymce/NotificationManager.js b/tests/qunit/editor/tinymce/NotificationManager.js deleted file mode 100644 index 02132d4418..0000000000 --- a/tests/qunit/editor/tinymce/NotificationManager.js +++ /dev/null @@ -1,109 +0,0 @@ -ModuleLoader.require([ - 'tinymce/util/Tools' -], function(Tools) { - module("tinymce.NotificationManager", { - 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(); - } - }); - }, - teardown: function() { - var notifications = [].concat(editor.notificationManager.notifications); - - Tools.each(notifications, function(notification) { - notification.close(); - }); - } - }); - - - test('Should not add duplicate text message', function() { - expect(4); - - var testMsg1 = {type: 'default', text: 'test default message'}; - var testMsg2 = {type: 'warning', text: 'test warning message'}; - var testMsg3 = {type: 'error', text: 'test error message'}; - var testMsg4 = {type: 'info', text: 'test info message'}; - var notifications = editor.notificationManager.notifications; - - editor.notificationManager.open(testMsg1); - - equal(notifications.length, 1, 'Should have one message after one added.'); - - editor.notificationManager.open(testMsg1); - - equal(notifications.length, 1, 'Should not add message if duplicate.'); - - editor.notificationManager.open(testMsg2); - editor.notificationManager.open(testMsg3); - editor.notificationManager.open(testMsg4); - - equal(notifications.length, 4, 'Non duplicate messages should get added.'); - - editor.notificationManager.open(testMsg2); - editor.notificationManager.open(testMsg3); - editor.notificationManager.open(testMsg4); - - equal(notifications.length, 4, 'Should work for all text message types.'); - }); - - test('Should add duplicate progressBar messages', function() { - expect(2); - var testMsg1 = {text: 'test progressBar message', progressBar: true}; - var notifications = editor.notificationManager.notifications; - - editor.notificationManager.open(testMsg1); - - equal(notifications.length, 1, 'Should have one message after one added.'); - - editor.notificationManager.open(testMsg1); - editor.notificationManager.open(testMsg1); - editor.notificationManager.open(testMsg1); - - equal(notifications.length, 4, 'Duplicate should be added for progressBar message.'); - }); - - asyncTest('Should add duplicate timeout messages', function() { - expect(2); - var checkClosed = function () { - if (notifications.length === 0) { - start(); - } - }; - var testMsg1 = {text: 'test timeout message', timeout: 1}; - var notifications = editor.notificationManager.notifications; - - editor.notificationManager.open(testMsg1).on('close', checkClosed); - - equal(notifications.length, 1, 'Should have one message after one added.'); - - editor.notificationManager.open(testMsg1).on('close', checkClosed); - - equal(notifications.length, 2, 'Duplicate should be added for timeout message.'); - }); - - test('Should not open notifcation if editor is removed', function() { - var testMsg1 = {type: 'default', text: 'test progressBar message'}; - - editor.remove(); - - try { - editor.notificationManager.open(testMsg1); - ok(true, 'Should execute without throwing.') - } catch (e) { - ok(false, 'Should never throw exception.'); - } - }); - -}); diff --git a/tests/qunit/editor/tinymce/SelectionOverrides.js b/tests/qunit/editor/tinymce/SelectionOverrides.js deleted file mode 100644 index 17ac0daa98..0000000000 --- a/tests/qunit/editor/tinymce/SelectionOverrides.js +++ /dev/null @@ -1,357 +0,0 @@ -ModuleLoader.require([ - "tinymce/caret/CaretPosition", - "tinymce/caret/CaretContainer", - "tinymce/util/VK", - "tinymce/text/Zwsp" -], function(CaretPosition, CaretContainer, VK, Zwsp) { - module("tinymce.SelectionOverrides", { - 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 pressKey(key) { - return function() { - Utils.pressKey({keyCode: key}); - }; - } - - function exitPreTest(arrow, offset, expectedContent) { - return function() { - editor.setContent('
    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('
    1
    2
    3
    '); - Utils.setSelection('div div', 1); - - Utils.type('\b'); - equal(Utils.cleanHtml(editor.getBody().innerHTML), '
    1

    3
    '); - equal(editor.selection.getRng().startContainer, editor.$('div div')[0]); - }); - - test('backspace from block to after cE=false inline', 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


    '; - Utils.setSelection('p:nth-child(2)', 0); - - backspace(); - equal(editor.getContent(), '

    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('

    link

    '); - 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
    ' - ); - - var firstTd = editor.dom.select('td')[0]; - var rect = editor.dom.getRect(firstTd); - - editor.fire('mousedown', { - target: firstTd, - clientX: rect.x + rect.w, - clientY: rect.y + 10 - }); - - // Since we can't do a real click we need to check if it gets sucked in towards the cE=false block - equal(editor.selection.getNode().nodeName !== 'P', true); - }); - - test('offscreen copy of cE=false block remains offscreen', function() { - if (tinymce.isIE || tinymce.isGecko || tinymce.isOpera) { - editor.setContent( - '' + - '' + - '
    12
    ' - ); - - editor.selection.select(editor.dom.select('table')[0]); - var offscreenSelection = editor.dom.select('.mce-offscreen-selection')[0]; - - ok(offscreenSelection.offsetLeft !== undefined, 'The offscreen selection\'s left border is undefined'); - ok(offscreenSelection.offsetLeft < 0, 'The offscreen selection\'s left border is onscreen'); - ok(offscreenSelection.offsetWidth + offscreenSelection.offsetLeft < 0, - 'The cE=false offscreen selection is visible on-screen. Right edge: ' + - offscreenSelection.offsetLeft + '+' + offscreenSelection.offsetWidth + '=' + - (offscreenSelection.offsetLeft + offscreenSelection.offsetWidth) + 'px' - ); - } else { - // Chrome and Safari behave correctly, and PhantomJS also declares itself as WebKit but does not - // put the off-screen selection off-screen, so fails the above tests. However, it has no visible UI, - // so everything is off-screen anyway :-) - ok(true, 'Not a tested browser - Chrome & Safari work, PhantomJS does not put the selection off screen'); - } - }); -}); diff --git a/tests/qunit/editor/tinymce/Shortcuts.js b/tests/qunit/editor/tinymce/Shortcuts.js deleted file mode 100644 index dc7c722432..0000000000 --- a/tests/qunit/editor/tinymce/Shortcuts.js +++ /dev/null @@ -1,87 +0,0 @@ -module("tinymce.Shortcuts", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - disable_nodechange: true, - indent: false, - skin: false, - entities: 'raw', - schema: 'html5', - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - } -}); - -test('Shortcuts formats', function() { - function assertShortcut(shortcut, args, assertState) { - var called = false; - - editor.shortcuts.add(shortcut, '', function() { - called = true; - }); - - args = tinymce.extend({ - ctrlKey: false, - altKey: false, - shiftKey: false, - metaKey: false - }, args); - - editor.fire('keydown', args); - - if (assertState) { - ok(called, 'Shortcut wasn\'t called: ' + shortcut); - } else { - ok(!called, 'Shortcut was called when it shouldn\'t have been: ' + shortcut); - } - } - - assertShortcut('ctrl+d', {ctrlKey: true, keyCode: 68}, true); - assertShortcut('ctrl+d', {altKey: true, keyCode: 68}, false); - - if (tinymce.Env.mac) { - assertShortcut('meta+d', {metaKey: true, keyCode: 68}, true); - assertShortcut('access+d', {ctrlKey: true, altKey: true, keyCode: 68}, true); - assertShortcut('meta+d', {ctrlKey: true, keyCode: 68}, false); - assertShortcut('access+d', {shiftKey: true, altKey: true, keyCode: 68}, false); - } else { - assertShortcut('meta+d', {ctrlKey: true, keyCode: 68}, true); - assertShortcut('access+d', {shiftKey: true, altKey: true, keyCode: 68}, true); - assertShortcut('meta+d', {metaKey: true, keyCode: 68}, false); - assertShortcut('access+d', {ctrlKey: true, altKey: true, keyCode: 68}, false); - } - - assertShortcut('ctrl+shift+d', {ctrlKey: true, shiftKey: true, keyCode: 68}, true); - assertShortcut('ctrl+shift+alt+d', {ctrlKey: true, shiftKey: true, altKey: true, keyCode: 68}, true); - assertShortcut('ctrl+221', {ctrlKey: true, keyCode: 221}, true); -}); - -test('Remove', function() { - var called = false, eventArgs; - - eventArgs = { - ctrlKey: true, - keyCode: 68, - altKey: false, - shiftKey: false, - metaKey: false - }; - - editor.shortcuts.add('ctrl+d', '', function() { - called = true; - }); - - editor.fire('keydown', eventArgs); - ok(called, 'Shortcut wasn\'t called when it should have been.'); - - called = false; - editor.shortcuts.remove('ctrl+d'); - editor.fire('keydown', eventArgs); - ok(!called, 'Shortcut was called when it shouldn\'t.'); -}); diff --git a/tests/qunit/editor/tinymce/UndoManager.js b/tests/qunit/editor/tinymce/UndoManager.js deleted file mode 100644 index ad4beb5511..0000000000 --- a/tests/qunit/editor/tinymce/UndoManager.js +++ /dev/null @@ -1,491 +0,0 @@ -module("tinymce.UndoManager", { - setupModule: function() { - QUnit.stop(); - - tinymce.init({ - selector: "textarea", - add_unload_trigger: false, - skin: false, - init_instance_callback: function(ed) { - window.editor = ed; - QUnit.start(); - } - }); - } -}); - -test('Initial states', function() { - expect(3); - - ok(!editor.undoManager.hasUndo()); - ok(!editor.undoManager.hasRedo()); - ok(!editor.undoManager.typing); -}); - -test('One undo level', function() { - editor.undoManager.clear(); - editor.setContent('test'); - - expect(3); - - editor.focus(); - editor.execCommand('SelectAll'); - editor.execCommand('Bold'); - - ok(editor.undoManager.hasUndo()); - ok(!editor.undoManager.hasRedo()); - ok(!editor.undoManager.typing); -}); - -test('Two undo levels', function() { - editor.undoManager.clear(); - editor.setContent('test'); - - expect(3); - - editor.execCommand('SelectAll'); - editor.execCommand('Bold'); - editor.execCommand('SelectAll'); - editor.execCommand('Italic'); - - ok(editor.undoManager.hasUndo()); - ok(!editor.undoManager.hasRedo()); - ok(!editor.undoManager.typing); -}); - -test('No undo levels and one redo', function() { - editor.undoManager.clear(); - editor.setContent('test'); - - expect(3); - - editor.execCommand('SelectAll'); - editor.execCommand('Bold'); - editor.undoManager.undo(); - - ok(!editor.undoManager.hasUndo()); - ok(editor.undoManager.hasRedo()); - ok(!editor.undoManager.typing); -}); - -test('One undo levels and one redo', function() { - editor.undoManager.clear(); - editor.setContent('test'); - - expect(3); - - editor.execCommand('SelectAll'); - editor.execCommand('Bold'); - editor.execCommand('SelectAll'); - editor.execCommand('Italic'); - editor.undoManager.undo(); - - ok(editor.undoManager.hasUndo()); - ok(editor.undoManager.hasRedo()); - ok(!editor.undoManager.typing); -}); - -test('Typing state', function() { - var selectAllFlags; - - editor.undoManager.clear(); - editor.setContent('test'); - - ok(!editor.undoManager.typing); - - editor.dom.fire(editor.getBody(), 'keydown', {keyCode: 65}); - ok(editor.undoManager.typing); - - editor.dom.fire(editor.getBody(), 'keydown', {keyCode: 13}); - ok(!editor.undoManager.typing); - - selectAllFlags = {keyCode: 65, ctrlKey: false, altKey: false, shiftKey: false}; - - if (tinymce.Env.mac) { - selectAllFlags.metaKey = true; - } else { - selectAllFlags.ctrlKey = true; - } - - editor.dom.fire(editor.getBody(), 'keydown', selectAllFlags); - ok(!editor.undoManager.typing); -}); - -test('Undo and add new level', function() { - editor.undoManager.clear(); - editor.setContent('test'); - - expect(3); - - editor.execCommand('SelectAll'); - editor.execCommand('Bold'); - editor.undoManager.undo(); - editor.execCommand('SelectAll'); - editor.execCommand('Italic'); - - ok(editor.undoManager.hasUndo()); - ok(!editor.undoManager.hasRedo()); - ok(!editor.undoManager.typing); -}); - -test('Events', function() { - var add, undo, redo; - - editor.undoManager.clear(); - editor.setContent('test'); - - expect(6); - - editor.on('AddUndo', function(e) { - add = e.level; - }); - - editor.on('Undo', function(e) { - undo = e.level; - }); - - editor.on('Redo', function(e) { - redo = e.level; - }); - - editor.execCommand('SelectAll'); - editor.execCommand('Bold'); - ok(add.content); - ok(add.bookmark); - - editor.undoManager.undo(); - ok(undo.content); - ok(undo.bookmark); - - editor.undoManager.redo(); - ok(redo.content); - ok(redo.bookmark); -}); - -test('No undo/redo cmds on Undo/Redo shortcut', function() { - var evt, commands = [], added = false; - - editor.undoManager.clear(); - editor.setContent('test'); - - editor.on('BeforeExecCommand', function(e) { - commands.push(e.command); - }); - - editor.on('BeforeAddUndo', function() { - added = true; - }); - - evt = { - keyCode: 90, - metaKey: tinymce.Env.mac, - ctrlKey: !tinymce.Env.mac, - shiftKey: false, - altKey: false - }; - - editor.dom.fire(editor.getBody(), 'keydown', evt); - editor.dom.fire(editor.getBody(), 'keypress', evt); - editor.dom.fire(editor.getBody(), 'keyup', evt); - - strictEqual(added, false); - deepEqual(commands, ["Undo"]); -}); - -test('Transact', function() { - var count = 0, level; - - editor.undoManager.clear(); - - editor.on('BeforeAddUndo', function() { - count++; - }); - - level = editor.undoManager.transact(function() { - editor.undoManager.add(); - editor.undoManager.add(); - }); - - equal(count, 1); - equal(level !== null, true); -}); - -test('Transact no change', function() { - editor.undoManager.add(); - - var level = editor.undoManager.transact(function() { - }); - - equal(level, null); -}); - -test('Transact with change', function() { - editor.undoManager.add(); - - var level = editor.undoManager.transact(function() { - editor.setContent('x'); - }); - - equal(level !== null, true); -}); - -test('Transact nested', function() { - var count = 0; - - editor.undoManager.clear(); - - editor.on('BeforeAddUndo', function() { - count++; - }); - - editor.undoManager.transact(function() { - editor.undoManager.add(); - - editor.undoManager.transact(function() { - editor.undoManager.add(); - }); - }); - - equal(count, 1); -}); - -test('Transact exception', function() { - var count = 0; - - editor.undoManager.clear(); - - editor.on('BeforeAddUndo', function() { - count++; - }); - - throws( - function() { - editor.undoManager.transact(function() { - throw new Error("Test"); - }); - }, - - "Test" - ); - - editor.undoManager.add(); - - equal(count, 1); -}); - -test('Extra with changes', function() { - var data; - - editor.undoManager.clear(); - editor.setContent('

    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
    ' - ); - - editor.undoManager.add(); - equal(count, 1); - equal(Utils.cleanHtml(lastLevel.content), - 'test' + - '' + - '
    x
    ' - ); - - editor.getBody().innerHTML = ( - '\u200B' + - '\uFEFF' + - '
    ' + - '
    x
    ' + - '' + - '
    ' + - 'test' + - '\u200B' + - '' + - '
    x
    ' - ); - - editor.undoManager.add(); - equal(count, 2); - equal(Utils.cleanHtml(lastLevel.content), - '
    ' + - 'test' + - '\u200B' + - '' + - '
    x
    ' - ); -}); - -test('Undo added when typing and losing focus', function() { - var lastLevel; - - editor.on('BeforeAddUndo', function(e) { - lastLevel = e.level; - }); - - editor.undoManager.clear(); - editor.setContent("

    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('



    '); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(getRoot().firstChild.firstChild)), 'p[0]/br[0],before'); - equal(CaretBookmark.create(getRoot(), CaretPosition.before(getRoot().lastChild.firstChild)), 'p[1]/br[0],before'); - }); - - test('create deep 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('abc'); - assertCaretPosition(CaretBookmark.resolve(getRoot(), 'h-2X[0]/text()[0],2'), createTextPos(getRoot().childNodes[0].firstChild, 2)); - }); - - test('resolve deep element index', 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
    ')[0]), true); - equal(CaretCandidate.isCaretCandidate($('')[0]), false); - equal(CaretCandidate.isCaretCandidate($('')[0]), false); - equal(CaretCandidate.isCaretCandidate(document.createComment('text')), false); - equal(CaretCandidate.isCaretCandidate($('')[0]), false); - equal(CaretCandidate.isCaretCandidate(document.createTextNode(Zwsp.ZWSP)), false); - }); - - test('isInEditable', function() { - setupHtml('abcX'); - equal(CaretCandidate.isInEditable($('span span', getRoot())[0].firstChild, getRoot()), false); - equal(CaretCandidate.isInEditable($('span span', getRoot())[0], getRoot()), true); - equal(CaretCandidate.isInEditable($('span', getRoot())[0], getRoot()), true); - equal(CaretCandidate.isInEditable(getRoot().firstChild, getRoot()), true); - }); - - test('isAtomic', function() { - $.each(["img", "input", "textarea", "hr"], function(index, name) { - equal(CaretCandidate.isAtomic(document.createElement(name)), true); - }); - - equal(CaretCandidate.isAtomic(document.createTextNode('text')), false); - equal(CaretCandidate.isAtomic($('
    X
    ')[0]), false); - equal(CaretCandidate.isAtomic($('X')[0]), true); - equal(CaretCandidate.isAtomic($('XYZ')[0]), false); - }); - - test('isEditableCaretCandidate', function() { - setupHtml('abcxxX'); - equal(CaretCandidate.isEditableCaretCandidate(getRoot().firstChild, getRoot()), true); - equal(CaretCandidate.isEditableCaretCandidate($('b', getRoot())[0]), false); - equal(CaretCandidate.isEditableCaretCandidate($('span', getRoot())[0]), true); - equal(CaretCandidate.isEditableCaretCandidate($('span span', getRoot())[0]), false); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/CaretContainer.js b/tests/qunit/editor/tinymce/caret/CaretContainer.js deleted file mode 100644 index 8e57e81860..0000000000 --- a/tests/qunit/editor/tinymce/caret/CaretContainer.js +++ /dev/null @@ -1,137 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/CaretContainer", - "tinymce/dom/DomQuery", - "tinymce/text/Zwsp" -], function(Env, CaretContainer, $, Zwsp) { - module("tinymce.caret.CaretContainer"); - - if (!Env.ceFalse) { - return; - } - - function setViewHtml(html) { - var child, rootElm = getRoot(); - - // IE leaves zwsp in the dom on innerHTML - while ((child = rootElm.firstChild)) { - rootElm.removeChild(child); - } - - rootElm.innerHTML = html; - } - - function getRoot() { - return document.getElementById('view'); - } - - test('isCaretContainer', function() { - equal(CaretContainer.isCaretContainer(document.createTextNode('text')), false); - equal(CaretContainer.isCaretContainer($('')[0]), false); - equal(CaretContainer.isCaretContainer($('')[0]), true); - equal(CaretContainer.isCaretContainer($('x')[0].firstChild), true); - equal(CaretContainer.isCaretContainer(document.createTextNode(Zwsp.ZWSP)), true); - }); - - test('isCaretContainerBlock', function() { - equal(CaretContainer.isCaretContainerBlock(document.createTextNode('text')), false); - equal(CaretContainer.isCaretContainerBlock($('')[0]), false); - equal(CaretContainer.isCaretContainerBlock($('')[0]), true); - equal(CaretContainer.isCaretContainerBlock($('a')[0].firstChild), true); - equal(CaretContainer.isCaretContainerBlock(document.createTextNode(Zwsp.ZWSP)), false); - }); - - test('isCaretContainerInline', function() { - equal(CaretContainer.isCaretContainerInline(document.createTextNode('text')), false); - equal(CaretContainer.isCaretContainerInline($('')[0]), false); - equal(CaretContainer.isCaretContainerInline($('')[0]), false); - equal(CaretContainer.isCaretContainerInline($('a')[0].firstChild), false); - equal(CaretContainer.isCaretContainerInline(document.createTextNode(Zwsp.ZWSP)), true); - }); - - test('insertInline before element', function() { - setViewHtml('1'); - equal(CaretContainer.insertInline(getRoot().firstChild, true), getRoot().firstChild); - equal(CaretContainer.isCaretContainerInline(getRoot().firstChild), true); - }); - - test('insertInline after element', function() { - setViewHtml('1'); - equal(CaretContainer.insertInline(getRoot().firstChild, false), getRoot().lastChild); - equal(CaretContainer.isCaretContainerInline(getRoot().lastChild), true); - }); - - test('insertInline between elements', function() { - setViewHtml('11'); - equal(CaretContainer.insertBlock('p', getRoot().lastChild, true), getRoot().childNodes[1]); - equal(CaretContainer.isCaretContainerBlock(getRoot().childNodes[1]), true); - }); - - test('insertInline before element with ZWSP', function() { - setViewHtml('abc' + Zwsp.ZWSP + '1'); - equal(CaretContainer.insertInline(getRoot().lastChild, true), getRoot().childNodes[1]); - equal(CaretContainer.isCaretContainerInline(getRoot().firstChild), false); - equal(CaretContainer.isCaretContainerInline(getRoot().childNodes[1]), true); - }); - - test('insertInline after element with ZWSP', function() { - setViewHtml('1' + Zwsp.ZWSP + 'abc'); - equal(CaretContainer.insertInline(getRoot().firstChild, false), getRoot().childNodes[1]); - equal(CaretContainer.isCaretContainerInline(getRoot().lastChild), false); - equal(CaretContainer.isCaretContainerInline(getRoot().childNodes[1]), true); - }); - - test('insertBlock before element', function() { - setViewHtml('1'); - equal(CaretContainer.insertBlock('p', getRoot().firstChild, true), getRoot().firstChild); - equal(CaretContainer.isCaretContainerBlock(getRoot().firstChild), true); - }); - - test('insertBlock after element', function() { - setViewHtml('1'); - equal(CaretContainer.insertBlock('p', getRoot().firstChild, false), getRoot().lastChild); - equal(CaretContainer.isCaretContainerBlock(getRoot().lastChild), true); - }); - - test('insertBlock between elements', function() { - setViewHtml('11'); - equal(CaretContainer.insertInline(getRoot().lastChild, true), getRoot().childNodes[1]); - equal(CaretContainer.isCaretContainerInline(getRoot().childNodes[1]), true); - }); - - test('remove', function() { - setViewHtml('1'); - - CaretContainer.insertInline(getRoot().firstChild, true); - equal(CaretContainer.isCaretContainerInline(getRoot().firstChild), true); - - CaretContainer.remove(getRoot().firstChild); - equal(CaretContainer.isCaretContainerInline(getRoot().firstChild), false); - }); - - test('startsWithCaretContainer', function() { - setViewHtml(Zwsp.ZWSP + 'abc'); - equal(CaretContainer.startsWithCaretContainer(getRoot().firstChild), true); - }); - - test('endsWithCaretContainer', function() { - setViewHtml('abc' + Zwsp.ZWSP); - equal(CaretContainer.endsWithCaretContainer(getRoot().firstChild), true); - }); - - test('hasContent', function() { - setViewHtml('1'); - var caretContainerBlock = CaretContainer.insertBlock('p', getRoot().firstChild, true); - equal(CaretContainer.hasContent(caretContainerBlock), false); - caretContainerBlock.insertBefore(document.createTextNode('a'), caretContainerBlock.firstChild); - equal(CaretContainer.hasContent(caretContainerBlock), true); - }); - - test('showCaretContainerBlock', function() { - setViewHtml('1'); - var caretContainerBlock = CaretContainer.insertBlock('p', getRoot().firstChild, true); - caretContainerBlock.insertBefore(document.createTextNode('a'), caretContainerBlock.firstChild); - CaretContainer.showCaretContainerBlock(caretContainerBlock); - equal(caretContainerBlock.outerHTML, '

    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' + - '
    1
    ' + - '
    2
    ' + - '
    2
    ' + - '' + - '' + - '' + - '

    123

    ' + - '
    ' - ); - - equal(new CaretPosition(getRoot().firstChild.firstChild, 0).getClientRects().length, 1); - equal(new CaretPosition(getRoot(), 1).getClientRects().length, 1); - equal(new CaretPosition(getRoot(), 2).getClientRects().length, 2); - equal(new CaretPosition(getRoot(), 3).getClientRects().length, 2); - equal(new CaretPosition(getRoot(), 4).getClientRects().length, 2); - equal(new CaretPosition(getRoot(), 5).getClientRects().length, 1); - equal(new CaretPosition(getRoot(), 6).getClientRects().length, 1); - equal(new CaretPosition(getRoot(), 7).getClientRects().length, 1); - equal(new CaretPosition(getRoot(), 8).getClientRects().length, 1); - equal(new CaretPosition(getRoot(), 9).getClientRects().length, 0); - }); - - test('getClientRects between inline node and cE=false', function() { - setupHtml( - 'def' + - 'ghi' - ); - - equal(new CaretPosition(getRoot(), 1).getClientRects().length, 1); - }); - - test('getClientRects at last visible character', function() { - setupHtml('a '); - - equal(new CaretPosition(getRoot().firstChild.firstChild, 1).getClientRects().length, 1); - }); - - test('getClientRects at extending character', function() { - setupHtml('a\u0301b'); - - equal(new CaretPosition(getRoot().firstChild, 0).getClientRects().length, 1); - equal(new CaretPosition(getRoot().firstChild, 1).getClientRects().length, 0); - equal(new CaretPosition(getRoot().firstChild, 2).getClientRects().length, 1); - }); - - test('getClientRects at whitespace character', function() { - setupHtml(' a '); - - equal(new CaretPosition(getRoot().firstChild, 0).getClientRects().length, 0); - equal(new CaretPosition(getRoot().firstChild, 1).getClientRects().length, 0); - equal(new CaretPosition(getRoot().firstChild, 2).getClientRects().length, 1); - equal(new CaretPosition(getRoot().firstChild, 3).getClientRects().length, 1); - equal(new CaretPosition(getRoot().firstChild, 4).getClientRects().length, 0); - equal(new CaretPosition(getRoot().firstChild, 5).getClientRects().length, 0); - }); - - test('getNode', function() { - setupHtml('abc'); - - equal(new CaretPosition(getRoot().firstChild.firstChild, 0).getNode(), getRoot().firstChild.firstChild); - equal(new CaretPosition(getRoot(), 1).getNode(), getRoot().childNodes[1]); - equal(new CaretPosition(getRoot(), 2).getNode(), getRoot().childNodes[2]); - equal(new CaretPosition(getRoot(), 3).getNode(), getRoot().childNodes[2]); - }); - - test('getNode (before)', function() { - setupHtml('abc'); - - equal(new CaretPosition(getRoot().firstChild.firstChild, 0).getNode(true), getRoot().firstChild.firstChild); - equal(new CaretPosition(getRoot(), 1).getNode(true), getRoot().childNodes[0]); - equal(new CaretPosition(getRoot(), 2).getNode(true), getRoot().childNodes[1]); - equal(new CaretPosition(getRoot(), 3).getNode(true), getRoot().childNodes[2]); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/CaretUtils.js b/tests/qunit/editor/tinymce/caret/CaretUtils.js deleted file mode 100644 index 8b35a8114f..0000000000 --- a/tests/qunit/editor/tinymce/caret/CaretUtils.js +++ /dev/null @@ -1,264 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/CaretUtils", - "tinymce/caret/CaretPosition", - "tinymce/text/Zwsp" -], function(Env, CaretUtils, CaretPosition, Zwsp) { - module("tinymce.caret.CaretUtils"); - - if (!Env.ceFalse) { - return; - } - - var assertRange = Utils.assertRange, - createRange = Utils.createRange, - ZWSP = Zwsp.ZWSP; - - function getRoot() { - return document.getElementById('view'); - } - - function replaceWithZwsp(node) { - for (var i = 0; i < node.childNodes.length; i++) { - var childNode = node.childNodes[i]; - - if (childNode.nodeType === 3) { - childNode.nodeValue = childNode.nodeValue.replace(/__ZWSP__/, ZWSP); - } else { - replaceWithZwsp(childNode); - } - } - } - - function setupHtml(html) { - var child, rootElm = getRoot(); - - // IE leaves zwsp in the dom on innerHTML - while ((child = rootElm.firstChild)) { - rootElm.removeChild(child); - } - - // IE messes zwsp up on innerHTML so we need to first set markers then replace then using dom operations - rootElm.innerHTML = html.replace(new RegExp(ZWSP, 'g'), '__ZWSP__'); - replaceWithZwsp(rootElm); - } - - function findElm(selector) { - return tinymce.$(selector, getRoot())[0]; - } - - test('isForwards', function() { - equal(CaretUtils.isForwards(1), true); - equal(CaretUtils.isForwards(10), true); - equal(CaretUtils.isForwards(0), false); - equal(CaretUtils.isForwards(-1), false); - equal(CaretUtils.isForwards(-10), false); - }); - - test('isBackwards', function() { - equal(CaretUtils.isBackwards(1), false); - equal(CaretUtils.isBackwards(10), false); - equal(CaretUtils.isBackwards(0), false); - equal(CaretUtils.isBackwards(-1), true); - equal(CaretUtils.isBackwards(-10), true); - }); - - test('findNode', function() { - setupHtml('abc123def'); - - function isBold(node) { - return node.nodeName == 'B'; - } - - function isText(node) { - return node.nodeType == 3; - } - - equal(CaretUtils.findNode(getRoot(), 1, isBold, getRoot()), getRoot().firstChild); - equal(CaretUtils.findNode(getRoot(), 1, isText, getRoot()), getRoot().firstChild.firstChild); - equal(CaretUtils.findNode(getRoot().childNodes[1], 1, isBold, getRoot().childNodes[1]), null); - equal(CaretUtils.findNode(getRoot().childNodes[1], 1, isText, getRoot().childNodes[1]).nodeName, '#text'); - equal(CaretUtils.findNode(getRoot(), -1, isBold, getRoot()), getRoot().childNodes[1]); - equal(CaretUtils.findNode(getRoot(), -1, isText, getRoot()), getRoot().lastChild); - }); - - test('getEditingHost', function() { - setupHtml(''); - - equal(CaretUtils.getEditingHost(getRoot(), getRoot()), getRoot()); - equal(CaretUtils.getEditingHost(getRoot().firstChild, getRoot()), getRoot()); - equal(CaretUtils.getEditingHost(getRoot().firstChild.firstChild, getRoot()), getRoot().firstChild); - }); - - test('getParentBlock', function() { - setupHtml('

    abc

    '); - - strictEqual(CaretUtils.getParentBlock(findElm('p:first')), findElm('p:first')); - strictEqual(CaretUtils.getParentBlock(findElm('td:first').firstChild), findElm('td:first')); - strictEqual(CaretUtils.getParentBlock(findElm('td:first')), findElm('td:first')); - strictEqual(CaretUtils.getParentBlock(findElm('table')), findElm('table')); - }); - - test('isInSameBlock', function() { - setupHtml('

    abc

    defghj

    '); - - strictEqual(CaretUtils.isInSameBlock( - CaretPosition(findElm('p:first').firstChild, 0), - CaretPosition(findElm('p:last').firstChild, 0) - ), false); - - strictEqual(CaretUtils.isInSameBlock( - CaretPosition(findElm('p:first').firstChild, 0), - CaretPosition(findElm('p:first').firstChild, 0) - ), true); - - strictEqual(CaretUtils.isInSameBlock( - CaretPosition(findElm('p:last').firstChild, 0), - CaretPosition(findElm('b').firstChild, 0) - ), true); - }); - - test('isInSameEditingHost', function() { - setupHtml( - '

    abc

    ' + - 'def' + - '' + - 'ghi' + - 'jkl' + - '' - ); - - strictEqual(CaretUtils.isInSameEditingHost( - CaretPosition(findElm('p:first').firstChild, 0), - CaretPosition(findElm('p:first').firstChild, 1) - ), true); - - strictEqual(CaretUtils.isInSameEditingHost( - CaretPosition(findElm('p:first').firstChild, 0), - CaretPosition(getRoot().childNodes[1], 1) - ), true); - - strictEqual(CaretUtils.isInSameEditingHost( - CaretPosition(findElm('span span:first').firstChild, 0), - CaretPosition(findElm('span span:first').firstChild, 1) - ), true); - - strictEqual(CaretUtils.isInSameEditingHost( - CaretPosition(findElm('p:first').firstChild, 0), - CaretPosition(findElm('span span:first').firstChild, 1) - ), false); - - strictEqual(CaretUtils.isInSameEditingHost( - CaretPosition(findElm('span span:first').firstChild, 0), - CaretPosition(findElm('span span:last').firstChild, 1) - ), false); - }); - - test('isBeforeContentEditableFalse', function() { - setupHtml( - '' + - 'a' - ); - - strictEqual(CaretUtils.isBeforeContentEditableFalse(CaretPosition(getRoot(), 0)), true); - strictEqual(CaretUtils.isBeforeContentEditableFalse(CaretPosition(getRoot(), 1)), true); - strictEqual(CaretUtils.isBeforeContentEditableFalse(CaretPosition(getRoot(), 2)), false); - strictEqual(CaretUtils.isBeforeContentEditableFalse(CaretPosition(getRoot(), 3)), false); - }); - - test('isAfterContentEditableFalse', function() { - setupHtml( - '' + - 'a' - ); - - strictEqual(CaretUtils.isAfterContentEditableFalse(CaretPosition(getRoot(), 0)), false); - strictEqual(CaretUtils.isAfterContentEditableFalse(CaretPosition(getRoot(), 1)), true); - strictEqual(CaretUtils.isAfterContentEditableFalse(CaretPosition(getRoot(), 2)), true); - strictEqual(CaretUtils.isAfterContentEditableFalse(CaretPosition(getRoot(), 3)), false); - }); - - test('normalizeRange', function() { - setupHtml( - 'abc1def' - ); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().firstChild, 2)), createRange(getRoot().firstChild, 2)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().firstChild, 3)), createRange(getRoot(), 1)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().lastChild, 2)), createRange(getRoot().lastChild, 2)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().lastChild, 0)), createRange(getRoot(), 2)); - }); - - test('normalizeRange deep', function() { - setupHtml( - 'abc1def' - ); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(findElm('b').firstChild, 2)), createRange(findElm('b').firstChild, 2)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(findElm('b').firstChild, 3)), createRange(getRoot(), 1)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(findElm('b:last').firstChild, 1)), createRange(findElm('b:last').firstChild, 1)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(findElm('b:last').firstChild, 0)), createRange(getRoot(), 2)); - }); - - test('normalizeRange break at candidate', function() { - setupHtml( - '

    abc

    1

    abc

    ' - ); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(findElm('b').firstChild, 3)), createRange(findElm('b').firstChild, 3)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(findElm('b:last').lastChild, 0)), createRange(findElm('b:last').lastChild, 0)); - }); - - test('normalizeRange at block caret container', function() { - setupHtml( - '

    \u00a0

    1

    \u00a0

    ' - ); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(findElm('p:first').firstChild, 0)), createRange(getRoot(), 1)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(findElm('p:first').firstChild, 1)), createRange(getRoot(), 1)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(findElm('p:last').firstChild, 0)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(findElm('p:last').firstChild, 1)), createRange(getRoot(), 2)); - }); - - test('normalizeRange at inline caret container', function() { - setupHtml( - 'abc1def' - ); - - getRoot().insertBefore(document.createTextNode(ZWSP), getRoot().childNodes[1]); - getRoot().insertBefore(document.createTextNode(ZWSP), getRoot().childNodes[3]); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().firstChild, 3)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().childNodes[1], 0)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().childNodes[1], 1)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().lastChild, 0)), createRange(getRoot(), 3)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().childNodes[3], 0)), createRange(getRoot(), 3)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().childNodes[3], 1)), createRange(getRoot(), 3)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().firstChild, 3)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().childNodes[1], 0)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().childNodes[1], 1)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().lastChild, 0)), createRange(getRoot(), 3)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().childNodes[3], 0)), createRange(getRoot(), 3)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().childNodes[3], 1)), createRange(getRoot(), 3)); - }); - - test('normalizeRange at inline caret container (combined)', function() { - setupHtml( - 'abc' + ZWSP + '1' + ZWSP + 'def' - ); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().firstChild, 3)), createRange(getRoot(), 1)); - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().firstChild, 4)), createRange(getRoot(), 1)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().lastChild, 0)), createRange(getRoot(), 2)); - assertRange(CaretUtils.normalizeRange(-1, getRoot(), createRange(getRoot().lastChild, 1)), createRange(getRoot(), 2)); - }); - - test('normalizeRange at inline caret container after block', function() { - setupHtml( - '

    1

    ' + ZWSP + 'abc' - ); - - assertRange(CaretUtils.normalizeRange(1, getRoot(), createRange(getRoot().lastChild, 0)), createRange(getRoot().lastChild, 0)); - - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/CaretWalker.js b/tests/qunit/editor/tinymce/caret/CaretWalker.js deleted file mode 100644 index c1745eaabc..0000000000 --- a/tests/qunit/editor/tinymce/caret/CaretWalker.js +++ /dev/null @@ -1,277 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/CaretWalker", - "tinymce/caret/CaretPosition" -], function(Env, CaretWalker, CaretPosition) { - module("tinymce.caret.CaretWalker"); - - if (!Env.ceFalse) { - return; - } - - function getRoot() { - return document.getElementById('view'); - } - - function setupHtml(html) { - tinymce.$(getRoot()).empty(); - getRoot().innerHTML = html; - } - - function findElm(selector) { - return tinymce.$(selector, getRoot())[0]; - } - - function findElmPos(selector, offset) { - return CaretPosition(tinymce.$(selector, getRoot())[0], offset); - } - - function findTextPos(selector, offset) { - return CaretPosition(tinymce.$(selector, getRoot())[0].firstChild, offset); - } - - var assertCaretPosition = Utils.assertCaretPosition, - logicalCaret = new CaretWalker(getRoot()); - - test('inside empty root', function() { - setupHtml(''); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), null); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null); - }); - - test('on null', function() { - setupHtml(''); - assertCaretPosition(logicalCaret.next(null), null); - assertCaretPosition(logicalCaret.prev(null), null); - }); - - test('within text node in root', function() { - setupHtml('abc'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 0)), CaretPosition(getRoot().firstChild, 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 2)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), null); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot().firstChild, 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 0)), null); - }); - - test('within text node in element', function() { - setupHtml('

    abc

    '); - assertCaretPosition(logicalCaret.next(findTextPos('p', 0)), findTextPos('p', 1)); - assertCaretPosition(logicalCaret.next(findTextPos('p', 1)), findTextPos('p', 2)); - assertCaretPosition(logicalCaret.next(findTextPos('p', 2)), findTextPos('p', 3)); - assertCaretPosition(logicalCaret.next(findTextPos('p', 3)), null); - assertCaretPosition(logicalCaret.prev(findTextPos('p', 3)), findTextPos('p', 2)); - assertCaretPosition(logicalCaret.prev(findTextPos('p', 2)), findTextPos('p', 1)); - assertCaretPosition(logicalCaret.prev(findTextPos('p', 1)), findTextPos('p', 0)); - assertCaretPosition(logicalCaret.prev(findTextPos('p', 0)), null); - }); - - test('from index text node over comment', function() { - setupHtml('abcdabcd'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot().firstChild, 0)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().lastChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().firstChild, 4)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot().lastChild, 4)); - }); - - test('from text to text across elements', function() { - setupHtml('

    abc

    abc

    '); - assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), findTextPos('p:last', 0)); - assertCaretPosition(logicalCaret.prev(findTextPos('p:last', 0)), findTextPos('p:first', 3)); - }); - - test('from text to text across elements with siblings', function() { - setupHtml('

    abc

    abc

    '); - assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), CaretPosition(findElm('p:last').lastChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last').lastChild)), findTextPos('p:first', 3)); - }); - - test('from input to text', function() { - setupHtml('123456'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().lastChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().firstChild, 3)); - }); - - test('from input to input across elements', function() { - setupHtml('

    '); - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('p:first'), 1)), CaretPosition(findElm('p:last'), 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last'), 0)), CaretPosition(findElm('p:first'), 1)); - }); - - test('next br to br across elements', function() { - setupHtml('



    '); - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('p:first'), 0)), CaretPosition(findElm('p:last'), 0)); - }); - - test('prev br to br across elements', function() { - setupHtml('



    '); - assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last'), 0)), CaretPosition(findElm('p:first'), 0)); - }); - - test('from before/after br to text', function() { - setupHtml('
    123
    456
    789'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 4)), CaretPosition(getRoot(), 5)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 5)), CaretPosition(getRoot().lastChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 5)), CaretPosition(getRoot(), 4)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 4)), CaretPosition(getRoot().childNodes[3], 3)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 0)); - }); - - test('over br', function() { - setupHtml('


    '); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 3)), null); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null); - }); - - test('over input', function() { - setupHtml(''); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 3)), null); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null); - }); - - test('over img', function() { - setupHtml(''); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 3)), null); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null); - }); - - test('over script/style/textarea', function() { - setupHtml('abcd'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().childNodes[2], 0)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().childNodes[2], 1)), CaretPosition(getRoot().childNodes[4], 0)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 5)), CaretPosition(getRoot(), 6)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 6)), CaretPosition(getRoot(), 5)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().childNodes[4], 0)), CaretPosition(getRoot().childNodes[2], 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().childNodes[0], 1)); - }); - - test('around tables', function() { - setupHtml('a
    X
    A
    B
    b'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), findTextPos('td:first', 0)); - assertCaretPosition(logicalCaret.next(findTextPos('td:first', 1)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), findTextPos('td:last', 0)); - assertCaretPosition(logicalCaret.next(findTextPos('table:last td', 1)), CaretPosition(getRoot(), 3)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 3)), CaretPosition(getRoot().lastChild, 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().lastChild, 0)), CaretPosition(getRoot(), 3)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), findTextPos('td:last', 1)); - assertCaretPosition(logicalCaret.prev(findTextPos('td:last', 0)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), findTextPos('td:first', 1)); - assertCaretPosition(logicalCaret.prev(findTextPos('td:first', 0)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().firstChild, 1)); - }); - - test('over cE=false', function() { - setupHtml('123a456'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().lastChild, 0)), CaretPosition(getRoot(), 2)); - }); -/* - test('from outside cE=false to nested cE=true', function() { - setupHtml('abcbcdef'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot(), 1)); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), findTextPos('span span', 0)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().lastChild, 0)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), findTextPos('span span', 1)); - }); - - test('from outside cE=false to nested cE=true before/after cE=false', function() { - setupHtml('abd'); - assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(findElm('span span'), 0)); - assertCaretPosition(logicalCaret.next(CaretPosition(findElm('span span'), 1)), CaretPosition(getRoot(), 2)); - assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(findElm('span span'), 1)); - }); -*/ - test('from inside cE=true in cE=false to after cE=false', function() { - setupHtml( - '

    ' + - '' + - '' + - '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
    '); - - rng = fakeCaret.show(true, $('#view div')[0]); - $fakeCaretElm = $('#view').children(); - - equal($fakeCaretElm[0].nodeName, 'P'); - equal($fakeCaretElm.attr('data-mce-caret'), 'before'); - Utils.assertRange(rng, Utils.createRange($fakeCaretElm[0], 0, $fakeCaretElm[0], 0)); - - fakeCaret.hide(); - equal($('#view *[data-mce-caret]').length, 0); - }); - - test('show/hide (before, block)', function() { - var rng, $fakeCaretElm; - - $('#view').html('
    a
    '); - - rng = fakeCaret.show(false, $('#view div')[0]); - $fakeCaretElm = $('#view').children(); - - equal($fakeCaretElm[1].nodeName, 'P'); - equal($fakeCaretElm.eq(1).attr('data-mce-caret'), 'after'); - Utils.assertRange(rng, Utils.createRange($fakeCaretElm[1], 0, $fakeCaretElm[1], 0)); - - fakeCaret.hide(); - equal($('#view *[data-mce-caret]').length, 0); - }); - - test('show/hide (before, inline)', function() { - var rng, $fakeCaretText; - - $('#view').html('a'); - - rng = fakeCaret.show(true, $('#view span')[0]); - $fakeCaretText = $('#view').contents(); - - equal($fakeCaretText[0].nodeName, '#text'); - equal($fakeCaretText[0].data, Zwsp.ZWSP); - Utils.assertRange(rng, Utils.createRange($fakeCaretText[0], 1)); - - fakeCaret.hide(); - equal($('#view').contents()[0].nodeName, 'SPAN'); - }); - - test('show/hide (after, inline)', function() { - var rng, $fakeCaretText; - - $('#view').html('a'); - - rng = fakeCaret.show(false, $('#view span')[0]); - $fakeCaretText = $('#view').contents(); - - equal($fakeCaretText[1].nodeName, '#text'); - equal($fakeCaretText[1].data, Zwsp.ZWSP); - Utils.assertRange(rng, Utils.createRange($fakeCaretText[1], 1)); - - fakeCaret.hide(); - equal($('#view').contents()[0].nodeName, 'SPAN'); - }); - - test('getCss', function() { - equal(fakeCaret.getCss().length > 10, true); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/LineUtils.js b/tests/qunit/editor/tinymce/caret/LineUtils.js deleted file mode 100644 index 5bcccb835b..0000000000 --- a/tests/qunit/editor/tinymce/caret/LineUtils.js +++ /dev/null @@ -1,28 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/LineUtils" -], function(Env, LineUtils) { - module("tinymce.caret.LineUtils"); - - if (!Env.ceFalse) { - return; - } - - function rect(x, y, w, h) { - return { - left: x, - top: y, - bottom: y + h, - right: x + w, - width: w, - height: h - }; - } - - test('findClosestClientRect', function() { - deepEqual(LineUtils.findClosestClientRect([rect(10, 10, 10, 10), rect(30, 10, 10, 10)], 15), rect(10, 10, 10, 10)); - deepEqual(LineUtils.findClosestClientRect([rect(10, 10, 10, 10), rect(30, 10, 10, 10)], 27), rect(30, 10, 10, 10)); - deepEqual(LineUtils.findClosestClientRect([rect(10, 10, 10, 10), rect(30, 10, 10, 10)], 23), rect(10, 10, 10, 10)); - deepEqual(LineUtils.findClosestClientRect([rect(10, 10, 10, 10), rect(20, 10, 10, 10)], 13), rect(10, 10, 10, 10)); - }); -}); diff --git a/tests/qunit/editor/tinymce/caret/LineWalker.js b/tests/qunit/editor/tinymce/caret/LineWalker.js deleted file mode 100644 index e06c8a6003..0000000000 --- a/tests/qunit/editor/tinymce/caret/LineWalker.js +++ /dev/null @@ -1,88 +0,0 @@ -ModuleLoader.require([ - "tinymce/Env", - "tinymce/caret/LineWalker", - "tinymce/caret/CaretPosition", - "tinymce/dom/DomQuery" -], function(Env, LineWalker, CaretPosition, $) { - module("tinymce.caret.LineWalker"); - - if (!Env.ceFalse) { - return; - } - - test('positionsUntil', function() { - var result, predicateCallCount = 0; - - function predicate() { - predicateCallCount++; - return false; - } - - $('#view').html('ab'); - result = LineWalker.positionsUntil(1, $('#view')[0], predicate, $('#view')[0].firstChild); - equal(result.length, 3); - equal(result[0].position.getNode(), $('#view')[0].lastChild); - equal(result[1].position.getNode(), $('#view')[0].lastChild.firstChild); - equal(result[2].position.getNode(), $('#view')[0].lastChild.firstChild); - equal(predicateCallCount, 3); - - predicateCallCount = 0; - $('#view').html('ab'); - result = LineWalker.positionsUntil(-1, $('#view')[0], predicate, $('#view')[0].lastChild); - equal(result.length, 3); - equal(result[0].position.getNode(), $('#view')[0].lastChild); - equal(result[1].position.getNode(), $('#view')[0].firstChild.firstChild); - equal(result[2].position.getNode(), $('#view')[0].firstChild.firstChild); - equal(predicateCallCount, 3); - }); - - test('upUntil', function() { - var caretPosition, result, predicateCallCount = 0; - - function predicate() { - predicateCallCount++; - return false; - } - - $('#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('

    a

    '), [{level: 1, title: 'a', type: 'header', url: '#a'}], 'Header 1 with id'); - equalTargets(targetsIn('

    a

    '), [{level: 2, title: 'a', type: 'header', url: '#a'}], 'Header 2 with id'); - equalTargets(targetsIn('

    a

    '), [{level: 3, title: 'a', type: 'header', url: '#a'}], 'Header 3 with id'); - equalTargets(targetsIn('

    a

    '), [{level: 4, title: 'a', type: 'header', url: '#a'}], 'Header 4 with id'); - equalTargets(targetsIn('
    a
    '), [{level: 5, title: 'a', type: 'header', url: '#a'}], 'Header 5 with id'); - equalTargets(targetsIn('
    a
    '), [{level: 6, title: 'a', type: 'header', url: '#a'}], 'Header 6 with id'); - equalTargets(targetsIn('

    '), [], 'Empty header should not produce a target'); - equalTargets(targetsIn('

    a

    '), [], 'Header in cE=false'); - equalTargets(targetsIn('

    a

    '), [], 'cE=false header'); - }); - - test('Mixed targets', function() { - equalTargets( - targetsIn('

    a

    '), - [ - {level: 1, title: 'a', type: 'header', url: '#a'}, - {level: 0, title: '#b', type: 'anchor', url: '#b'} - ], - 'Header 1 with id and anchor with id' - ); - }); - - test('Anchor attach', function() { - var elm = createFromHtml(''); - var targets = LinkTargets.find(elm); - - targets[0].attach(); - equal(elm.innerHTML, '', 'Should remain the same as before attach'); - }); - - test('Header attach on header with id', function() { - var elm = createFromHtml('

    a

    '); - var targets = LinkTargets.find(elm); - - targets[0].attach(); - equal(elm.innerHTML, '

    a

    ', 'Should remain the same as before attach'); - }); - - test('Header attach on headers without ids', function() { - var elm = createFromHtml('

    a

    b

    '); - var targets = LinkTargets.find(elm); - - targets[0].attach(); - targets[1].attach(); - - var idA = elm.firstChild.id; - var idB = elm.lastChild.id; - var afterAttachHtml = elm.innerHTML; - - equal(afterAttachHtml, '

    a

    b

    ', 'Should have unique id:s'); - ok(idA !== idB, 'Should not be equal id:s'); - - targets[0].attach(); - targets[1].attach(); - - equal(elm.innerHTML, afterAttachHtml, 'Should be the same id:s regardless of how many times you attach'); - }); -}); diff --git a/tests/qunit/editor/tinymce/data/ObservableObject.js b/tests/qunit/editor/tinymce/data/ObservableObject.js deleted file mode 100644 index 7a46f31012..0000000000 --- a/tests/qunit/editor/tinymce/data/ObservableObject.js +++ /dev/null @@ -1,51 +0,0 @@ -ModuleLoader.require(["tinymce/data/ObservableObject"], function(ObservableObject) { - module("tinymce.data.ObservableObject"); - - test("Constructor", function(assert) { - var obj; - - obj = new ObservableObject(); - assert.ok(!obj.has('a')); - - obj = new ObservableObject({a: 1, b: 2}); - assert.strictEqual(obj.get('a'), 1); - assert.strictEqual(obj.get('b'), 2); - }); - - test("set/get and observe all", function(assert) { - var obj = new ObservableObject(), events = []; - - obj.on('change', function(e) { - events.push(e); - }); - - obj.set('a', 'a'); - obj.set('a', 'a2'); - obj.set('a', 'a3'); - obj.set('b', 'b'); - assert.strictEqual(obj.get('a'), 'a3'); - - equal(events[0].type, 'change'); - equal(events[0].value, 'a'); - equal(events[1].type, 'change'); - equal(events[1].value, 'a2'); - equal(events[2].type, 'change'); - equal(events[2].value, 'a3'); - equal(events[3].type, 'change'); - equal(events[3].value, 'b'); - }); - - test("set/get and observe specific", function(assert) { - var obj = new ObservableObject(), events = []; - - obj.on('change:a', function(e) { - events.push(e); - }); - - obj.set('a', 'a'); - obj.set('b', 'b'); - equal(events[0].type, 'change'); - equal(events[0].value, 'a'); - equal(events.length, 1); - }); -}); diff --git a/tests/qunit/editor/tinymce/dom/DOMUtils.js b/tests/qunit/editor/tinymce/dom/DOMUtils.js deleted file mode 100644 index 32de6d4c18..0000000000 --- a/tests/qunit/editor/tinymce/dom/DOMUtils.js +++ /dev/null @@ -1,716 +0,0 @@ -(function() { - module("tinymce.dom.DOMUtils", { - teardownModule: function() { - DOM = null; - } - }); - - var DOM = new tinymce.dom.DOMUtils(document, {keep_values : true, schema : new tinymce.html.Schema()}); - - test('parseStyle', 11, function() { - var dom; - - DOM.add(document.body, 'div', {id : 'test'}); - - dom = new tinymce.dom.DOMUtils(document, {hex_colors : true, keep_values : true, url_converter : function(u) { - return 'X' + u + 'Y'; - }}); - - equal( - dom.serializeStyle(dom.parseStyle('border: 1px solid red; color: green')), - 'border: 1px solid red; color: green;' - ); - - equal( - dom.serializeStyle(dom.parseStyle('border: 1px solid rgb(0, 255, 255); color: green')), - 'border: 1px solid #00ffff; color: green;' - ); - - equal( - dom.serializeStyle(dom.parseStyle('border-top: 1px solid red; border-left: 1px solid red; border-bottom: 1px solid red; border-right: 1px solid red;')), - 'border: 1px solid red;' - ); - - equal( - dom.serializeStyle(dom.parseStyle('border-width: 1pt 1pt 1pt 1pt; border-style: none none none none; border-color: black black black black;')), - 'border: 1pt none black;' - ); - - equal( - dom.serializeStyle(dom.parseStyle('border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;')), - 'border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;' - ); - - equal( - dom.serializeStyle(dom.parseStyle('background: transparent url(test.gif);')), - 'background: transparent url(\'Xtest.gifY\');' - ); - - equal( - dom.serializeStyle(dom.parseStyle('background: transparent url(http://www.site.com/test.gif?a=1&b=2);')), - 'background: transparent url(\'Xhttp://www.site.com/test.gif?a=1&b=2Y\');' - ); - - dom.setHTML('test', ''); - equal(dom.getAttrib('test2', 'style'), 'margin: 1px;'); - - dom.setHTML('test', ''); - equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xtest.gifY\');'); - - dom.get('test').innerHTML = ''; - equal(dom.getAttrib('test2', 'style'), tinymce.isIE && !window.getSelection ? 'border: #00ff00 1px solid;' : 'border: 1px solid #00ff00;'); // IE has a separate output - - dom.get('test').innerHTML = ''; - equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xhttp://www.site.com/test.gifY\');'); - - DOM.remove('test'); - }); - - test('addClass', function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').className = ''; - DOM.addClass('test', 'abc'); - equal(DOM.get('test').className, 'abc'); - - DOM.addClass('test', '123'); - equal(DOM.get('test').className, 'abc 123'); - - DOM.get('test').innerHTML = ''; - DOM.addClass(DOM.select('span', 'test'), 'abc'); - equal(DOM.get('test2').className, 'abc'); - equal(DOM.get('test3').className, 'abc'); - equal(DOM.get('test4').className, 'abc'); - DOM.get('test').innerHTML = ''; - - DOM.remove('test'); - }); - - test('removeClass', 5, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').className = 'abc 123 xyz'; - DOM.removeClass('test', '123'); - equal(DOM.get('test').className, 'abc xyz'); - - DOM.get('test').innerHTML = ''; - DOM.removeClass(DOM.select('span', 'test'), 'test1'); - equal(DOM.get('test2').className, ''); - equal(DOM.get('test3').className, 'test test'); - equal(DOM.get('test4').className, 'test'); - - DOM.get('test').innerHTML = ''; - DOM.removeClass('test2', 'test'); - equal(Utils.normalizeHtml(DOM.get('test').innerHTML), ''); - - DOM.remove('test'); - }); - - test('hasClass', 7, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').className = 'abc 123 xyz'; - ok(DOM.hasClass('test', 'abc')); - ok(DOM.hasClass('test', '123')); - ok(DOM.hasClass('test', 'xyz')); - ok(!DOM.hasClass('test', 'aaa')); - - DOM.get('test').className = 'abc'; - ok(DOM.hasClass('test', 'abc')); - - DOM.get('test').className = 'aaa abc'; - ok(DOM.hasClass('test', 'abc')); - - DOM.get('test').className = 'abc aaa'; - ok(DOM.hasClass('test', 'abc')); - - DOM.remove('test'); - }); - - test('add', 5, function() { - var e; - - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.add('test', 'span', {'class' : 'abc 123'}, 'content abc'); - e = DOM.get('test').getElementsByTagName('span')[0]; - equal(e.className, 'abc 123'); - equal(e.innerHTML.toLowerCase(), 'content abc'); - DOM.remove(e); - - DOM.add('test', 'span', {'class' : 'abc 123'}); - e = DOM.get('test').getElementsByTagName('span')[0]; - equal(e.className, 'abc 123'); - DOM.remove(e); - - DOM.add('test', 'span'); - e = DOM.get('test').getElementsByTagName('span')[0]; - equal(e.nodeName, 'SPAN'); - DOM.remove(e); - - DOM.get('test').innerHTML = ''; - DOM.add(['test2', 'test3', 'test4'], 'span', {'class' : 'abc 123'}); - equal(DOM.select('span', 'test').length, 6); - - DOM.remove('test'); - }); - - test('create', 3, function() { - var e; - - e = DOM.create('span', {'class' : 'abc 123'}, 'content abc'); - - equal(e.nodeName, 'SPAN'); - equal(e.className, 'abc 123'); - equal(e.innerHTML.toLowerCase(), 'content abc'); - }); - - test('createHTML', 5, function() { - equal(DOM.createHTML('span', {'id': 'id1', 'class': 'abc 123'}, 'content abc'), 'content abc'); - equal(DOM.createHTML('span', {'id': 'id1', 'class': 'abc 123'}), ''); - equal(DOM.createHTML('span', {'id': null, 'class': undefined}), ''); - equal(DOM.createHTML('span'), ''); - equal(DOM.createHTML('span', null, 'content abc'), 'content abc'); - }); - - test('uniqueId', 3, function() { - DOM.counter = 0; - - equal(DOM.uniqueId(), 'mce_0'); - equal(DOM.uniqueId(), 'mce_1'); - equal(DOM.uniqueId(), 'mce_2'); - }); - - test('showHide', function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.show('test'); - equal(DOM.get('test').style.display, ''); - ok(!DOM.isHidden('test')); - - DOM.hide('test'); - equal(DOM.get('test').style.display, 'none'); - ok(DOM.isHidden('test')); - - // Cleanup - DOM.setAttrib('test', 'style', ''); - - DOM.remove('test'); - }); - - test('select', 4, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setHTML('test', '
    test 1
    test 2
    test 3
    test 4
    '); - equal(DOM.select('div', 'test').length, 4); - ok(DOM.select('div', 'test').reverse); - - DOM.setHTML('test', '
    test 1
    test 2
    test 3
    test 4
    '); - equal(DOM.select('div.test2', 'test').length, 2); - - DOM.setHTML('test', '
    test 1
    test 2
    test 3
    test 4
    '); - equal(DOM.select('div div', 'test').length, 1, null, tinymce.isWebKit); // Issue: http://bugs.webkit.org/show_bug.cgi?id=17461 - //alert(DOM.select('div div', 'test').length +","+DOM.get('test').querySelectorAll('div div').length); - - DOM.remove('test'); - }); - - test('is', 3, function() { - DOM.add(document.body, 'div', {id : 'test'}); - DOM.setHTML('test', '
    test 1
    '); - - ok(DOM.is(DOM.get('textX'), 'div')); - ok(DOM.is(DOM.get('textX'), 'div#textX.test')); - ok(!DOM.is(DOM.get('textX'), 'div#textX2')); - - DOM.remove('test'); - }); - - test('encode', 1, function() { - equal(DOM.encode('abc<>"&\'\u00e5\u00e4\u00f6'), 'abc<>"&'\u00e5\u00e4\u00f6'); - }); - - test('setGetAttrib', function() { - var dom; - - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setAttrib('test', 'class', 'test 123'); - equal(DOM.getAttrib('test', 'class'), 'test 123'); - - DOM.setAttrib('test', 'src', 'url'); - equal(DOM.getAttrib('test', 'src'), 'url'); - equal(DOM.getAttrib('test', 'data-mce-src'), 'url'); - equal(DOM.getAttrib('test', 'abc'), ''); - - DOM.setAttribs('test', {'class' : '123', title : 'abc'}); - equal(DOM.getAttrib('test', 'class'), '123'); - equal(DOM.getAttrib('test', 'title'), 'abc'); - - DOM.setAttribs('test'); - equal(DOM.getAttrib('test', 'class'), '123'); - equal(DOM.getAttrib('test', 'title'), 'abc'); - - dom = new tinymce.dom.DOMUtils(document, {keep_values : true, url_converter : function(u, n) { - return '&<>"' + u + '&<>"' + n; - }}); - - dom.setAttribs('test', {src : '123', href : 'abc'}); - equal(DOM.getAttrib('test', 'src'), '&<>"123&<>"src'); - equal(DOM.getAttrib('test', 'href'), '&<>"abc&<>"href'); - - equal(DOM.getAttrib(document, 'test'), false); - equal(DOM.getAttrib(document, 'test', ''), ''); - equal(DOM.getAttrib(document, 'test', 'x'), 'x'); - - DOM.remove('test'); - }); - - test('setGetAttrib on null', function() { - strictEqual(DOM.getAttrib(null, 'test'), ''); - DOM.setAttrib(null, 'test'); - }); - - test('getAttribs', 2, function() { - function check(obj, val) { - var count = 0; - - val = val.split(','); - - tinymce.each(obj, function(o) { - if (tinymce.inArray(val, o.nodeName.toLowerCase()) != -1 && o.specified) { - count++; - } - }); - - return count == obj.length; - } - - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').innerHTML = ''; - ok(check(DOM.getAttribs('test2'), 'id,class')); - - DOM.get('test').innerHTML = '
    '; - ok(check(DOM.getAttribs('test2'), 'id,type,name,value,disabled,readonly,checked'), 'Expected attributed: type,name,disabled,readonly,checked'); - - DOM.remove('test'); - }); - - test('setGetStyles', function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setStyle('test', 'font-size', '20px'); - equal(DOM.getStyle('test', 'font-size'), '20px'); - - DOM.setStyle('test', 'fontSize', '21px'); - equal(DOM.getStyle('test', 'fontSize'), '21px'); - - DOM.setStyles('test', {fontSize : '22px', display : 'inline'}); - equal(DOM.getStyle('test', 'fontSize'), '22px'); - equal(DOM.getStyle('test', 'display'), 'inline'); - - DOM.setStyle('test', 'fontSize', 23); - equal(DOM.getStyle('test', 'fontSize'), '23px'); - - DOM.setStyle('test', 'fontSize', 23); - DOM.setStyle('test', 'fontSize', ''); - equal(DOM.getStyle('test', 'fontSize'), ''); - - DOM.setStyle('test', 'fontSize', 23); - DOM.setStyle('test', 'fontSize', null); - equal(DOM.getStyle('test', 'fontSize'), ''); - - DOM.setAttrib('test', 'style', ''); - equal(typeof DOM.getStyle(null, 'fontSize'), 'undefined'); - - DOM.remove('test'); - }); - - test('getPos', 2, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setStyles('test', {position : 'absolute', left : 100, top : 110}); - equal(DOM.getPos('test').x, 100); - equal(DOM.getPos('test').y, 110); - - DOM.setAttrib('test', 'style', ''); - - DOM.remove('test'); - }); - - var eqNodeName = function(name) { - return function (n) { - return n.nodeName === name; - }; - }; - - test('getParent', 6, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').innerHTML = '
    ababcc
    '; - - equal(DOM.getParent('test2', eqNodeName('SPAN')).nodeName, 'SPAN'); - equal(DOM.getParent('test2', eqNodeName('BODY')).nodeName, 'BODY'); - equal(DOM.getParent('test2', eqNodeName('BODY'), document.body), null); - equal(DOM.getParent('test2', eqNodeName('X')), null); - equal(DOM.getParent('test2', 'SPAN').nodeName, 'SPAN'); - equal(DOM.getParent('test2', 'body', DOM.get('test')), null); - - DOM.get('test').innerHTML = ''; - - DOM.remove('test'); - }); - - test('getParents', 4, function() { - DOM.add(document.body, 'div', {id : 'test'}); - DOM.get('test').innerHTML = '
    ababcc
    '; - - equal(DOM.getParents('test2', eqNodeName('SPAN')).length, 2); - equal(DOM.getParents('test2', 'span').length, 2); - equal(DOM.getParents('test2', 'span.test').length, 1); - equal(DOM.getParents('test2', 'body', DOM.get('test')).length, 0); - - DOM.remove('test'); - }); - - test('is', 2, function() { - DOM.add(document.body, 'div', {id : 'test'}); - DOM.get('test').innerHTML = '
    ababcc
    '; - - ok(DOM.is(DOM.select('span', 'test'), 'span')); - ok(DOM.is(DOM.select('#test2', 'test'), '#test2')); - - DOM.remove('test'); - }); - - test('getViewPort', 4, function() { - var wp; - - wp = DOM.getViewPort(); - equal(wp.x, 0); - equal(wp.y, 0); - ok(wp.w > 0); - ok(wp.h > 0); - }); - - test('getRect', 5, function() { - var r; - - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setStyles('test', {position : 'absolute', left : 100, top : 110, width : 320, height : 240}); - r = DOM.getRect('test'); - equal(r.x, 100); - equal(r.y, 110); - equal(r.w, 320); - equal(r.h, 240); - - DOM.setAttrib('test', 'style', ''); - - DOM.get('test').innerHTML = '
    '; - r = DOM.getRect('test2'); - equal(r.w, 160); - - DOM.remove('test'); - }); - - test('getSize', 2, function() { - var r; - - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').innerHTML = '
    '; - r = DOM.getSize('test2'); - equal(r.w, 160); - - DOM.get('test').innerHTML = '
    '; - r = DOM.getSize('test2'); - equal(r.w, 100); - - DOM.remove('test'); - }); - - test('getNext', 5, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').innerHTML = 'ABC'; - equal(DOM.getNext(DOM.get('test').firstChild, '*').nodeName, 'SPAN'); - equal(DOM.getNext(DOM.get('test').firstChild, 'em').nodeName, 'EM'); - equal(DOM.getNext(DOM.get('test').firstChild, 'div'), null); - equal(DOM.getNext(null, 'div'), null); - equal(DOM.getNext(DOM.get('test').firstChild, eqNodeName('EM')).nodeName, 'EM'); - - DOM.remove('test'); - }); - - test('getPrev', 5, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.get('test').innerHTML = 'ABC'; - equal(DOM.getPrev(DOM.get('test').lastChild, '*').nodeName, 'SPAN'); - equal(DOM.getPrev(DOM.get('test').lastChild, 'strong').nodeName, 'STRONG'); - equal(DOM.getPrev(DOM.get('test').lastChild, 'div'), null); - equal(DOM.getPrev(null, 'div'), null); - equal(DOM.getPrev(DOM.get('test').lastChild, eqNodeName('STRONG')).nodeName, 'STRONG'); - - DOM.remove('test'); - }); - - test('loadCSS', 1, function() { - var c = 0; - - DOM.loadCSS('tinymce/dom/test.css?a=1,tinymce/dom/test.css?a=2,tinymce/dom/test.css?a=3'); - - tinymce.each(document.getElementsByTagName('link'), function(n) { - if (n.href.indexOf('test.css?a=') != -1) { - c++; - } - }); - - equal(c, 3, null, tinymce.isOpera); - }); - - test('insertAfter', 2, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setHTML('test', ''); - DOM.insertAfter(DOM.create('br'), 'test2'); - equal(DOM.get('test2').nextSibling.nodeName, 'BR'); - - DOM.setHTML('test', 'testtest'); - DOM.insertAfter(DOM.create('br'), 'test2'); - equal(DOM.get('test2').nextSibling.nodeName, 'BR'); - - DOM.remove('test'); - }); - - test('isBlock', 4, function() { - ok(DOM.isBlock(DOM.create('div'))); - ok(DOM.isBlock('DIV')); - ok(!DOM.isBlock('SPAN')); - ok(DOM.isBlock('div')); - }); - - test('remove', 2, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setHTML('test', 'testtest2'); - DOM.remove('test2', 1); - equal(DOM.get('test').innerHTML.toLowerCase(), 'testtest2'); - - DOM.setHTML('test', 'testtest2'); - equal(DOM.remove('test2').nodeName, 'SPAN'); - - DOM.remove('test'); - }); - - test('replace', 2, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setHTML('test', 'testtest2'); - DOM.replace(DOM.create('div', {id : 'test2'}), 'test2', 1); - equal(DOM.get('test2').innerHTML.toLowerCase(), 'testtest2'); - - DOM.setHTML('test', 'testtest2'); - DOM.replace(DOM.create('div', {id : 'test2'}), 'test2'); - equal(DOM.get('test2').innerHTML, ''); - - DOM.remove('test'); - }); - - test('toHex', 5, function() { - equal(DOM.toHex('rgb(0, 255, 255)'), '#00ffff'); - equal(DOM.toHex('rgb(255, 0, 0)'), '#ff0000'); - equal(DOM.toHex('rgb(0, 0, 255)'), '#0000ff'); - equal(DOM.toHex('rgb ( 0 , 0 , 255 ) '), '#0000ff'); - equal(DOM.toHex(' RGB ( 0 , 0 , 255 ) '), '#0000ff'); - }); - - test('getOuterHTML', 4, function() { - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setHTML('test', 'testtest2'); - equal(DOM.getOuterHTML('test2').toLowerCase().replace(/\"/g, ''), 'testtest2'); - - DOM.setHTML('test', 'testtest2'); - DOM.setOuterHTML('test2', '
    123
    '); - equal(tinymce.trim(DOM.getOuterHTML('test2') || '').toLowerCase().replace(/\"/g, ''), '
    123
    '); - - DOM.setHTML('test', 'testtest2'); - DOM.setOuterHTML('test2', '
    123
    abc
    '); - equal(tinymce.trim(DOM.get('test').innerHTML).toLowerCase().replace(/>\s+<').replace(/\"/g, ''), '
    123
    abc
    '); - - DOM.setHTML('test', 'test'); - equal(tinymce.trim(DOM.getOuterHTML(DOM.get('test').firstChild)), 'test'); - - DOM.remove('test'); - }); - - test('encodeDecode', 2, function() { - equal(DOM.encode('\u00e5\u00e4\u00f6&<>"'), '\u00e5\u00e4\u00f6&<>"'); - equal(DOM.decode('åäö&<>"'), '\u00e5\u00e4\u00f6&<>"'); - }); - - test('split', 2, function() { - var point, parent; - DOM.add(document.body, 'div', {id : 'test'}); - - DOM.setHTML('test', '

    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

    inner

    text2

    '); - - DOM.setHTML('test', '
    • first line
      • second line
      • third line
    '); - parent = DOM.select('li:nth-child(1)', DOM.get('test'))[0]; - point = DOM.select('ul li:nth-child(2)', DOM.get('test'))[0]; - DOM.split(parent, point); - equal(Utils.cleanHtml(DOM.get('test').innerHTML), '
    • first line
      • second line
    • third line
    '); - - DOM.remove('test'); - }); - - test('nodeIndex', 5, function() { - DOM.add(document.body, 'div', {id : 'test'}, 'abcabcabc'); - - equal(DOM.nodeIndex(DOM.get('test').childNodes[0]), 0, 'Index of first child.'); - equal(DOM.nodeIndex(DOM.get('test').childNodes[1]), 1, 'Index of second child.'); - equal(DOM.nodeIndex(DOM.get('test').childNodes[2]), 2, 'Index of third child.'); - - DOM.get('test').insertBefore(DOM.doc.createTextNode('a'), DOM.get('test').firstChild); - DOM.get('test').insertBefore(DOM.doc.createTextNode('b'), DOM.get('test').firstChild); - - equal(DOM.nodeIndex(DOM.get('test').lastChild), 4, 'Index of last child with fragmented DOM.'); - equal(DOM.nodeIndex(DOM.get('test').lastChild, true), 2, 'Normalized index of last child with fragmented DOM.'); - - DOM.remove('test'); - }); - - test('isEmpty', function() { - DOM.schema = new tinymce.html.Schema(); // A schema will be added when used within a editor instance - DOM.add(document.body, 'div', {id : 'test'}, ''); - - ok(DOM.isEmpty(DOM.get('test')), 'No children'); - - DOM.setHTML('test', '
    '); - ok(DOM.isEmpty(DOM.get('test')), 'Br child'); - - DOM.setHTML('test', '

    '); - ok(!DOM.isEmpty(DOM.get('test')), 'Br children'); - - DOM.setHTML('test', 'text'); - ok(!DOM.isEmpty(DOM.get('test')), 'Text child'); - - DOM.setHTML('test', 'text'); - ok(!DOM.isEmpty(DOM.get('test')), 'Text child in span'); - - DOM.setHTML('test', ''); - ok(DOM.isEmpty(DOM.get('test')), 'Empty span child'); - - DOM.setHTML('test', '
    '); - ok(DOM.isEmpty(DOM.get('test')), 'Empty complex HTML'); - - DOM.setHTML('test', '
    X
    '); - ok(!DOM.isEmpty(DOM.get('test')), 'Non empty complex HTML'); - - DOM.setHTML('test', '
    '); - ok(DOM.isEmpty(DOM.get('test')), 'Non empty complex HTML with space'); - - DOM.setHTML('test', '
    '); - ok(!DOM.isEmpty(DOM.get('test')), 'Non empty complex HTML with achor name'); - - 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, '');
    -		equal(false, DOM.isEmpty(elm, {img: true}));
    -	});
    -
    -	test('isEmpty on pre', function() {
    -		var elm = DOM.create('pre', null, '  ');
    -		equal(false, DOM.isEmpty(elm));
    -	});
    -
    -	test('isEmpty with list of elements considered non-empty without schema', function() {
    -		var domWithoutSchema = new tinymce.dom.DOMUtils(document, {keep_values: true});
    -
    -		var elm = domWithoutSchema.create('p', null, '');
    -		equal(false, domWithoutSchema.isEmpty(elm, {img: true}));
    -	});
    -
    -	test('isEmpty on P with BR in EM', function() {
    -		var elm = DOM.create('p', null, '
    '); - ok(DOM.isEmpty(elm, 'No children')); - }); - - test('isEmpty on P with two BR in EM', function() { - var elm = DOM.create('p', null, '

    '); - equal(false, DOM.isEmpty(elm)); - }); - - test('bind/unbind/fire', function() { - var count = 0; - - DOM.bind(document, 'click', function() { - count++; - }); - DOM.fire(document, 'click'); - DOM.unbind(document, 'click'); - equal(count, 1); - - count = 0; - DOM.bind([document, window], 'click', function(e) { - e.stopPropagation(); - count++; - }); - DOM.fire(document, 'click'); - DOM.fire(window, 'click'); - DOM.unbind([document, window], 'click'); - equal(count, 2); - - count = 0; - DOM.fire(document, 'click'); - DOM.fire(window, 'click'); - equal(count, 0); - }); - - DOM.remove('test'); -})(); diff --git a/tests/qunit/editor/tinymce/dom/Dimensions.js b/tests/qunit/editor/tinymce/dom/Dimensions.js deleted file mode 100644 index fec4bd8531..0000000000 --- a/tests/qunit/editor/tinymce/dom/Dimensions.js +++ /dev/null @@ -1,34 +0,0 @@ -ModuleLoader.require([ - "tinymce/util/Arr", - "tinymce/dom/Dimensions" -], function(Arr, Dimensions) { - module("tinymce.dom.Dimensions"); - - function setupHtml(html) { - var viewElm; - - viewElm = document.getElementById('view'); - viewElm.innerHTML = html; - - return viewElm; - } - - test('getClientRects', function() { - var viewElm = setupHtml('abc123'); - - strictEqual(Dimensions.getClientRects(viewElm.firstChild).length, 1); - strictEqual(Dimensions.getClientRects(viewElm.lastChild).length, 1); - strictEqual(Dimensions.getClientRects(viewElm.firstChild)[0].node, viewElm.firstChild); - strictEqual(Dimensions.getClientRects(viewElm.firstChild)[0].left > 3, true); - strictEqual(Dimensions.getClientRects(viewElm.lastChild)[0].left > 3, true); - }); - - test('getClientRects from array', function() { - var viewElm = setupHtml('ab'), - clientRects = Dimensions.getClientRects(Arr.toArray(viewElm.childNodes)); - - strictEqual(clientRects.length, 2); - strictEqual(clientRects[0].node, viewElm.childNodes[0]); - strictEqual(clientRects[1].node, viewElm.childNodes[1]); - }); -}); diff --git a/tests/qunit/editor/tinymce/dom/DomQuery.js b/tests/qunit/editor/tinymce/dom/DomQuery.js deleted file mode 100644 index 64d6c2cdb4..0000000000 --- a/tests/qunit/editor/tinymce/dom/DomQuery.js +++ /dev/null @@ -1,1034 +0,0 @@ -(function() { - var $elm; - - module("tinymce.dom.DomQuery", { - teardown: function() { - if ($elm) { - $elm.off(); - $elm = null; - } - - document.getElementById('view').innerHTML = ''; - } - }); - - function normalizeParentNode(parentNode) { - // IE 8 will return a document fragment as it's parent when nodes are removed - if (parentNode && parentNode.nodeType == 11) { - return null; - } - - return parentNode; - } - - function normalizeStyleValue(value) { - if (typeof value == 'string') { - return value.toLowerCase().replace(/\s+/g, ' ').replace(/;\s*$/, ''); - } - - return value; - } - - function splitAtView(nodes) { - nodes.each(function(i) { - if (this.id == 'view') { - nodes = nodes.slice(0, i); - return false; - } - }); - - return nodes; - } - - function addTests(prefix, $) { - test(prefix + 'Constructor HTML', function() { - var $html; - - $html = $('ab'); - equal($html.length, 2); - equal($html[0].tagName, 'B'); - equal($html[1].tagName, 'I'); - }); - - test(prefix + 'Constructor HTML with attributes', function() { - var $html; - - $html = $('', {id: 'id', title: 'title'}); - equal($html.length, 1); - equal($html[0].tagName, 'B'); - equal($html[0].getAttribute('id'), 'id'); - equal($html[0].getAttribute('title'), 'title'); - }); - - test(prefix + 'Constructor selector', function() { - var $selector; - - $selector = $('#view'); - equal($selector.length, 1); - equal($selector.selector, '#view'); - strictEqual($selector.context, document); - }); - - test(prefix + 'Constructor selector and context', function() { - var $selector; - - $selector = $('#view', document); - equal($selector.length, 1); - equal($selector.selector, '#view'); - strictEqual($selector.context, document); - }); - - test(prefix + 'Constructor selector and context', function() { - $('#view').html('
    a
    b
    '); - $('b', $('#view div')[0]).html('x'); - equal($('#view').html().toLowerCase().replace(/[\r\n]/g, ''), '
    x
    b
    '); - }); - - test(prefix + 'Constructor array', function() { - var $html; - - $html = $([document.getElementById('view'), document.body]); - equal($html.length, 2); - equal($html[0].tagName, 'DIV'); - equal($html[1].tagName, 'BODY'); - }); - - test(prefix + 'Constructor query instance', function() { - var $clone; - - $clone = $($('#view')); - equal($clone.length, 1); - equal($clone[0].tagName, 'DIV'); - }); - - test(prefix + 'Constructor window', function() { - var $win; - - $win = $(window); - equal($win.length, 1); - strictEqual($win[0], window); - }); - - test(prefix + 'Constructor window', function() { - var $elm; - - $elm = $(document.body); - equal($elm.length, 1); - strictEqual($elm[0], document.body); - }); - - test(prefix + 'static extend()', function() { - var data; - - deepEqual($.extend({a: 1, b: 1}, {b: 2, c: 2}), {a: 1, b: 2, c: 2}); - deepEqual($.extend({a: 1, b: 1}, {b: 2, c: 2}, {c: 3, d: 3}), {a: 1, b: 2, c: 3, d: 3}); - - data = {a: 1, b: 1}; - ok(data === $.extend(data, {b: 2, c: 2}, {c: 3, d: 3}), {a: 1, b: 2, c: 3, d: 3}); - }); - - test(prefix + 'static makeArray()', function() { - strictEqual($.makeArray(window)[0], window); - deepEqual($.makeArray({'0': 'a', '1': 'b', length: 2}), ['a', 'b']); - }); - - test(prefix + 'static inArray()', function() { - deepEqual($.inArray(1, [1, 2]), 0); - deepEqual($.inArray(2, [1, 2]), 1); - deepEqual($.inArray(3, [1, 2]), -1); - }); - - test(prefix + 'static grep()', function() { - deepEqual($.grep([1, 2, 3], function(v) { - return v > 1; - }), [2, 3]); - }); - - test(prefix + 'static isArray()', function() { - ok($.isArray([])); - ok(!$.isArray({})); - }); - - test(prefix + 'static each()', function() { - var data; - - data = ''; - $.each([1, 2, 3], function(key, value) { - data += '' + value + key; - }); - - equal(data, '102132'); - - data = ''; - $.each({a: 1, b: 2, c: 3}, function(key, value) { - data += '' + value + key; - }); - - equal(data, '1a2b3c'); - - data = ''; - $.each([1, 2, 3], function(key, value) { - data += '' + value + key; - - if (value == 2) { - return false; - } - }); - - equal(data, '1021'); - }); - - test(prefix + 'static trim()', function() { - equal($.trim(' a '), 'a'); - equal($.trim('a '), 'a'); - equal($.trim(' a'), 'a'); - }); - - test(prefix + 'static unique()', function() { - var nodes; - - nodes = $.unique([document.getElementById('view'), document.getElementById('view'), document.body]); - equal(nodes.length, 2); - equal(nodes[0].tagName, 'BODY'); - equal(nodes[1].tagName, 'DIV'); - }); - - test(prefix + 'toArray()', function() { - ok($.isArray($('#view').toArray())); - equal($('#view').toArray().length, 1); - }); - - test(prefix + 'add() single element', function() { - var $nodes = $('#view').add(document.body); - equal($nodes.length, 2); - equal($nodes[0].tagName, 'BODY'); - equal($nodes[1].tagName, 'DIV'); - }); - - test(prefix + 'add() multiple elements (duplicates)', function() { - var $nodes = $('#view,#view').add([document.body, document.body]); - equal($nodes.length, 2); - equal($nodes[0].tagName, 'BODY'); - equal($nodes[1].tagName, 'DIV'); - }); - - test(prefix + 'add() multiple elements (non duplicates)', function() { - var $nodes = $('#view').add([$('')[0], $('')[0]]); - equal($nodes.length, 3); - equal($nodes[0].tagName, 'DIV'); - equal($nodes[1].tagName, 'B'); - equal($nodes[2].tagName, 'I'); - }); - - test(prefix + 'add() selector', function() { - var $nodes = $().add('#view'); - equal($nodes.length, 1); - equal($nodes[0].tagName, 'DIV'); - }); - - test(prefix + 'attr() set/get attr on element', function() { - var $elm; - - $elm = $('').attr('id', 'x'); - equal($elm.attr('id'), 'x'); - equal(typeof $elm.attr('noattr'), 'undefined', 'Undefined attribute shouldn\'t have a value'); - - $elm = $('').attr('attr', null); - equal(typeof $elm.attr('attr'), 'undefined', 'Deleted attribute shouldn\'t have a value (1)'); - - $elm = $('').attr('id', 1); - strictEqual($elm.attr('id'), '1'); - }); - - test(prefix + 'attr() set/get style attr on element (IE 7)', function() { - $elm = $('').attr('style', 'font-size: 43px'); - equal(normalizeStyleValue($elm.attr('style')), 'font-size: 43px'); - }); - - test(prefix + 'attr() set/get checked attr on element (IE 7)', function() { - $elm = $('').attr('checked', 'checked'); - equal($elm.attr('checked').toLowerCase(), 'checked'); - }); - - test(prefix + 'attr() get special attrs on element (IE 7)', function() { - $elm = $(''); - equal(typeof $elm.attr('maxlength'), 'undefined', 'Undefined maxlength'); - equal(typeof $elm.attr('size'), 'undefined', 'Undefined size'); - equal(typeof $elm.attr('checked'), 'undefined', 'Undefined checked'); - equal(typeof $elm.attr('readonly'), 'undefined', 'Undefined readonly'); - equal(typeof $elm.attr('disabled'), 'undefined', 'Undefined disabled'); - - $elm = $(''); - equal(typeof $elm.attr('maxlength'), 'undefined', 'Undefined maxlength'); - equal(typeof $elm.attr('size'), 'undefined', 'Undefined size'); - equal(typeof $elm.attr('checked'), 'undefined', 'Undefined checked'); - equal(typeof $elm.attr('readonly'), 'undefined', 'Undefined readonly'); - equal(typeof $elm.attr('disabled'), 'undefined', 'Undefined disabled'); - - $elm = $(''); - equal($elm.attr('maxlength'), '21', 'maxlength'); - equal($elm.attr('size'), '11', 'size'); - equal($elm.attr('disabled'), 'disabled', 'disabled'); - - $elm = $(''); - equal(typeof $elm.attr('maxlength'), 'undefined', 'Undefined maxlength'); - equal(typeof $elm.attr('size'), 'undefined', 'Undefined size'); - equal(typeof $elm.attr('checked'), 'undefined', 'Undefined checked'); - equal(typeof $elm.attr('readonly'), 'undefined', 'Undefined readonly'); - equal(typeof $elm.attr('disabled'), 'undefined', 'Undefined disabled'); - - $elm = $(''); - equal($elm.attr('readonly'), 'readonly', 'readonly'); - }); - - test(prefix + 'attr() set/get attrs on element', function() { - var $elm; - - $elm = $('').attr({id: 'x', title: 'y'}); - equal($elm.attr('id'), 'x'); - equal($elm.attr('title'), 'y'); - }); - - test(prefix + 'attr() set/get on non element', function() { - var $elm; - - $elm = $([document.createTextNode('x')]).attr('id', 'x'); - equal(typeof $elm.attr('id'), 'undefined'); - }); - - test(prefix + 'removeAttr() on element', function() { - var $elm; - - $elm = $('').removeAttr('AttR'); - equal(typeof $elm.attr('attr'), 'undefined'); - - $elm = $([document.createTextNode('x')]).removeAttr('id'); - equal(typeof $elm.attr('id'), 'undefined'); - }); - - test(prefix + 'prop() set/get attr on element', function() { - var $elm; - - $elm = $('').prop('id', 'x'); - equal($elm.prop('id'), 'x'); - equal(typeof $elm.prop('noprop'), 'undefined'); - - $elm = $(''); - equal($elm.prop('class'), 'x'); - equal($elm.prop('className'), 'x'); - - $elm = $('
    -

    TinyMCE tests

    @@ -505,6 +504,7 @@ +