module("tinymce.Editor", { setupModule: function() { QUnit.stop(); tinymce.init({ selector: "textarea", 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', init_instance_callback: function(ed) { window.editor = ed; QUnit.start(); } }); } }); 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(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); }); test('urls - absoluteURLs', function() { editor.settings.relative_urls = false; editor.settings.remove_script_host = true; editor.documentBaseURI = new tinymce.util.URI('http://www.site.com/dirA/dirB/dirC/'); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.settings.relative_urls = false; editor.settings.remove_script_host = false; editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); editor.setContent('test'); equal(editor.getContent(), ''); }); test('WebKit Serialization range bug', function() { expect(1); if (tinymce.isIE) { ok(true, "Skip IE"); } else { // Note that if we create the P with this invalid content directly, Chrome cleans it up differently to other browsers so we don't // wind up testing the serialization functionality we were aiming for and the test fails. var p = editor.dom.create('p', {}, '123X |
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('custom elements', function() { editor.setContent('abc
'); equal(editor.getContent(), 'abc
'); });