Wordpress/tests/qunit/editor/tinymce/ForceBlocks.html
Andrew Ozz ce2dcccf86 Incorporate the TinyMCE tests into our JS tests:
- Modified the original tests so TinyMCE can be loaded from /src/wp-includes/js/tinymce.
- Added "WP" option to the UI to select only tests relevant to our integration (excludes most of the default plugins tests).
- Added tests for obsolete HTML elements and attributes (html4 back-compat).
See #27014.

git-svn-id: https://develop.svn.wordpress.org/trunk@27155 602fd350-edb4-49c9-b593-d223f7449a82
2014-02-10 01:11:25 +00:00

117 lines
3.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Unit tests for tinymce.ForceBlocks</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;
QUnit.config.reorder = false;
QUnit.config.autostart = false;
module("tinymce.ForceBlocks", {
autostart: false,
setup: function() {
editor.settings.forced_root_block = 'p';
editor.settings.forced_root_block_attrs = null;
}
});
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);
}
test('Wrap single root text node in P', function() {
editor.getBody().innerHTML = 'abcd';
setSelection('body', 2);
pressArrowKey();
equal(cleanHtml(editor.getBody().innerHTML), '<p>abcd</p>');
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';
setSelection('body', 2);
pressArrowKey();
equal(editor.getContent(), '<p class="class1">abcd</p>');
equal(editor.selection.getNode().nodeName, 'P');
});
test('Wrap single root text node in P but not table sibling', function() {
editor.getBody().innerHTML = 'abcd<table><tr><td>x</td></tr></table>';
setSelection('body', 2);
pressArrowKey();
equal(cleanHtml(editor.getBody().innerHTML), '<p>abcd</p><table><tbody><tr><td>x</td></tr></tbody></table>');
equal(editor.selection.getNode().nodeName, 'P');
});
test('Wrap root em in P but not table sibling', function() {
editor.getBody().innerHTML = '<em>abcd</em><table><tr><td>x</td></tr></table>';
setSelection('em', 2);
pressArrowKey();
equal(cleanHtml(editor.getBody().innerHTML), '<p><em>abcd</em></p><table><tbody><tr><td>x</td></tr></tbody></table>');
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';
setSelection('body', 2);
pressArrowKey();
equal(cleanHtml(editor.getBody().innerHTML), '<div>abcd</div>');
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<div>abcd</div>';
setSelection('body', 2);
body.insertBefore(editor.getDoc().createTextNode(''), body.firstChild);
body.appendChild(editor.getDoc().createTextNode(''));
pressArrowKey();
equal(cleanHtml(body.innerHTML), '<div>abcd</div><div>abcd</div>');
equal(editor.selection.getNode().nodeName, 'DIV');
equal(body.childNodes.length, 2);
});
tinymce.init({
mode : "exact",
elements : "elm1",
add_unload_trigger : false,
indent : false,
schema: 'html5',
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 for tinymce.ForceBlocks</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>
</body>
</html>