Wordpress/tests/qunit/editor/plugins/noneditable.html

238 lines
9.1 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<title>Unit tests for noneditable</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="../js/qunit/reporter.js"></script>
<script src="../js/utils.js"></script>
<script src="../js/tinymce_loader.js"></script>
<script>
var editor, rng;
QUnit.config.reorder = false;
QUnit.config.autostart = false;
module("Noneditable plugin", {
autostart: false
});
test('expand to noneditable (start)', function() {
editor.setContent('<p><span class="mceNonEditable">no</span>yes</p>');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild.firstChild.firstChild, 1);
rng.setEnd(editor.getBody().firstChild.lastChild, 1);
editor.selection.setRng(rng);
editor.dom.fire(editor.getBody(), 'mouseup');
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, 'P');
equal(rng.startOffset, 0);
equal(rng.endContainer.nodeName, '#text');
equal(rng.endOffset, 1);
});
test('expand to noneditable (end)', function() {
editor.setContent('<p>yes<span class="mceNonEditable">no</span></p>');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild.firstChild, 1);
rng.setEnd(editor.getBody().firstChild.lastChild.firstChild, 1);
editor.selection.setRng(rng);
editor.dom.fire(editor.getBody(), 'mouseup');
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, '#text');
equal(rng.startOffset, 1);
equal(rng.endContainer.nodeName, 'P');
equal(rng.endOffset, 2);
});
test('expand to noneditable (start/end)', function() {
editor.setContent('<p>yes<span class="mceNonEditable">noedit</span>yes</p>');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('span')[0].firstChild, 1);
rng.setEnd(editor.dom.select('span')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.dom.fire(editor.getBody(), 'mouseup');
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, 'P');
equal(rng.startOffset, 1);
equal(rng.endContainer.nodeName, 'P');
equal(rng.endOffset, 2);
});
test('type after non editable', function() {
editor.setContent('<p><span class="mceNonEditable">no</span>yes</p>');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('span')[0].firstChild, 2);
rng.setEnd(editor.dom.select('span')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.dom.fire(editor.getBody(), 'mouseup');
type('X');
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.getAttribute('data-mce-bogus'), 'true');
equal(rng.startContainer.nodeName, 'SPAN');
equal(rng.startOffset, 1);
equal(rng.endContainer.nodeName, 'SPAN');
equal(rng.endOffset, 1);
equal(editor.getContent(), '<p><span class="mceNonEditable">no</span>Xyes</p>');
});
test('type between non editable', function() {
editor.setContent('<p><span class="mceNonEditable">no</span><span class="mceNonEditable">no</span></p>');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('span')[0].firstChild, 2);
rng.setEnd(editor.dom.select('span')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.dom.fire(editor.getBody(), 'mouseup');
type('X');
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.getAttribute('data-mce-bogus'), 'true');
equal(rng.startContainer.nodeName, 'SPAN');
equal(rng.startOffset, 1);
equal(rng.endContainer.nodeName, 'SPAN');
equal(rng.endOffset, 1);
equal(editor.getContent(), '<p><span class="mceNonEditable">no</span>X<span class="mceNonEditable">no</span></p>');
});
test('type after last non editable', function() {
editor.setContent('<p><span class="mceNonEditable">no</span></p>');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('span')[0].firstChild, 2);
rng.setEnd(editor.dom.select('span')[0].firstChild, 2);
editor.selection.setRng(rng);
editor.dom.fire(editor.getBody(), 'mouseup');
type('X');
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.getAttribute('data-mce-bogus'), 'true');
equal(rng.startContainer.nodeName, 'SPAN');
equal(rng.startOffset, 1);
equal(rng.endContainer.nodeName, 'SPAN');
equal(rng.endOffset, 1);
equal(editor.getContent(), '<p><span class="mceNonEditable">no</span>X</p>');
});
test('escape noneditable inline element (left)', function() {
editor.setContent('<p>no <span class="mceNonEditable">yes</span> no</p><p class="mceNonEditable">no</p>');
var container = editor.dom.select('p')[0];
rng = editor.dom.createRng();
rng.selectNode(editor.dom.select('span')[0]);
editor.selection.setRng(rng);
type({keyCode: 37});
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, 'SPAN');
equal(rng.startContainer.parentNode.nodeName, 'P');
equal(editor.dom.nodeIndex(rng.startContainer), 1);
equal(rng.collapsed, true);
});
test('escape noneditable inline element (right)', function() {
editor.setContent('<p>no <span class="mceNonEditable">yes</span> no</p><p class="mceNonEditable">no</p>');
var container = editor.dom.select('p')[0];
rng = editor.dom.createRng();
rng.selectNode(editor.dom.select('span')[0]);
editor.selection.setRng(rng);
type({keyCode: 39});
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, 'SPAN');
equal(rng.startContainer.parentNode.nodeName, 'P');
equal(editor.dom.nodeIndex(rng.startContainer), 2);
equal(rng.collapsed, true);
});
test('escape noneditable block element (left)', function(){
editor.setContent('<p>yes</p><p class="mceNonEditable">no</p><p>yes</p>');
rng = editor.dom.createRng();
rng.selectNode(editor.dom.select('p')[1]);
editor.selection.setRng(rng);
type({keyCode: 37});
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, "P");
equal(editor.dom.nodeIndex(rng.startContainer), 0);
equal(rng.startOffset, 1);
equal(rng.collapsed, true);
});
test('escape noneditable block element (right)', function(){
editor.setContent('<p>yes</p><p class="mceNonEditable">no</p><p>yes</p>');
rng = editor.dom.createRng();
rng.selectNode(editor.dom.select('p')[1]);
editor.selection.setRng(rng);
type({keyCode: 39});
rng = normalizeRng(editor.selection.getRng(true));
equal(rng.startContainer.nodeName, "P");
equal(editor.dom.nodeIndex(rng.startContainer), 2);
equal(rng.startOffset, 0);
equal(rng.collapsed, true);
});
test('noneditable regexp', function() {
editor.setContent('<p>{test1}{test2}</p>');
equal(editor.dom.select('span').length, 2);
equal(editor.getContent(), '<p>{test1}{test2}</p>');
});
tinymce.init({
mode : "exact",
elements : "elm1",
add_unload_trigger : false,
indent : false,
theme_advanced_styles : 'test1=test1;test2=test2',
noneditable_regexp : [/\{[^\}]+\}/g],
valid_elements : '@[contenteditable|id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],strong,b,em,i,strike,u,#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,-blockquote[cite],-table[border|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],object[classid|width|height|codebase|*],param[name|value],embed[type|width|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|tabindex|accesskey],kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],q[cite],samp,select[disabled|multiple|name|size],small,textarea[cols|rows|disabled|name|readonly],tt,var,big',
plugins: 'noneditable',
forced_root_block : '',
convert_fonts_to_spans : 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) {
editor = ed;
QUnit.start();
}
});
</script>
</head>
<body>
<h1 id="qunit-header">Unit tests noneditable plugin</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<textarea id="elm1" name="elm1"></textarea>
<div>
<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
</div>
</body>
</html>