Annotation of kupuMPIWG/tests/test_kupueditor.js, revision 1.1.1.1
1.1 dwinter 1: /*****************************************************************************
2: *
3: * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
4: *
5: * This software is distributed under the terms of the Kupu
6: * License. See LICENSE.txt for license text. For a list of Kupu
7: * Contributors see CREDITS.txt.
8: *
9: *****************************************************************************/
10:
11: // $Id: test_kupueditor.js 12412 2005-05-17 12:35:41Z duncan $
12:
13: function KupuEditorTestCase() {
14: this.name = 'KupuEditorTestCase';
15:
16: this.setUp = function() {
17: this.editor = new KupuEditor(null, {}, null);
18: };
19:
20: this.testGetNearestParentOfType = function() {
21: var doc = Sarissa.getDomDocument();
22: var xmlstring = '<p><a id="outer"><a id="inner"><b><span>some link</span></b> Even more</a></a></p>'
23: doc.loadXML(xmlstring);
24: this.assertEquals(doc.xml.strip(),xmlstring);
25:
26: var span = doc.documentElement.firstChild.firstChild.firstChild.firstChild;
27:
28: // first test with a non-existing parent; we should get null.
29: var ret = this.editor.getNearestParentOfType(span, 'br');
30: this.assertFalse(ret);
31:
32: // now test with a real parent; we expect the exact same node.
33: ret = this.editor.getNearestParentOfType(span, 'a');
34: var expected = doc.documentElement.firstChild.firstChild;
35: this.assert(ret === expected);
36: // assert again that we got the nearest...
37: this.assertEquals(ret.getAttribute('id'), 'inner');
38: };
39:
40: this.testRemoveNearestParentOfType = function() {
41: var doc = Sarissa.getDomDocument();
42: var xmlstring = '<p><a id="outer"><a id="inner"><b><span>some link</span></b> Even more</a></a></p>'
43: doc.loadXML(xmlstring);
44: this.assertEquals(doc.xml.strip(), xmlstring);
45:
46: var span = doc.documentElement.firstChild.firstChild.firstChild.firstChild;
47:
48: // first try to remove a parent we don't have; we expect the
49: // xml not to change.
50: this.editor.removeNearestParentOfType(span, 'br');
51: this.assertEquals(doc.xml.strip(), xmlstring);
52:
53: // now remove a real parent; we expect it to be gone in the
54: // resulting xml.
55: this.editor.removeNearestParentOfType(span, 'a');
56: var expected = '<p><a id="outer"><b><span>some link</span></b> Even more</a></p>';
57: this.assertEquals(doc.xml.strip(), expected);
58: };
59:
60: this.test_serializeOutputToString = function() {
61: var doc = Sarissa.getDomDocument();
62: //var docel = doc.documentElement;
63: var docel = doc.documentElement ? doc.documentElement : doc;
64: var html = doc.createElement('html');
65: docel.appendChild(html);
66: var head = doc.createElement('head');
67: html.appendChild(head);
68: var title = doc.createElement('title');
69: head.appendChild(title);
70: var titletext = doc.createTextNode('foo');
71: title.appendChild(titletext);
72: var body = doc.createElement('body');
73: html.appendChild(body);
74: var sometext1 = doc.createTextNode('foo');
75: body.appendChild(sometext1);
76: var br = doc.createElement('br');
77: body.appendChild(br);
78: var sometext2 = doc.createTextNode('bar');
79: body.appendChild(sometext2);
80: var result_not_replaced = '<html><head><title>foo</title></head><body>foo<br/>bar</body></html>';
81: this.assertEquals(this.editor._serializeOutputToString(docel),
82: result_not_replaced);
83: var result_replaced = '<html><head><title>foo</title></head><body>foo<br />bar</body></html>';
84: this.editor.config.compatible_singletons = true;
85: this.assertEquals(this.editor._serializeOutputToString(docel),
86: result_replaced);
87: var result_strict = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' +
88: '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' +
89: '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>foo</title></head><body>foo<br />bar</body></html>';
90: this.editor.config.strict_output = true;
91: this.assertEquals(this.editor._serializeOutputToString(docel),
92: result_strict);
93: };
94:
95: this.testEscapeEntities = function() {
96: var test = 'r\xe9diger\r\nhello';
97: var expected = 'rédiger\r\nhello';
98: this.assertEquals(this.editor.escapeEntities(test), expected);
99: };
100: };
101:
102: KupuEditorTestCase.prototype = new TestCase;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>