Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.data.tests.dom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.data.tests.dom"] = true;
3
dojo.provide("dojox.data.tests.dom");
4
dojo.require("dojox.data.dom");
5
 
6
tests.register("dojox.data.tests.dom",
7
	[
8
		function testCreateDocument(t){
9
			var document = dojox.data.dom.createDocument();
10
			t.assertTrue(document !== null);
11
		},
12
		function testCreateDocumentFromText(t){
13
			var simpleXml = "<parentNode><childNode><grandchildNode/></childNode><childNode/></parentNode>";
14
			var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
15
 
16
			var parent = document.firstChild;
17
            t.assertTrue(parent !== null);
18
			t.assertTrue(parent.tagName === "parentNode");
19
			t.assertTrue(parent.childNodes.length == 2);
20
 
21
			var firstChild = parent.firstChild;
22
			t.assertTrue(firstChild !== null);
23
			t.assertTrue(firstChild.tagName === "childNode");
24
			t.assertTrue(firstChild.childNodes.length == 1);
25
 
26
			var secondChild = firstChild.nextSibling;
27
			t.assertTrue(secondChild !== null);
28
			t.assertTrue(secondChild.tagName === "childNode");
29
 
30
			var grandChild = firstChild.firstChild;
31
			t.assertTrue(grandChild !== null);
32
			t.assertTrue(grandChild.tagName === "grandchildNode");
33
 
34
		},
35
		function testReadTextContent(t){
36
			var text = "This is a bunch of child text on the node";
37
			var simpleXml = "<parentNode>" + text + "</parentNode>";
38
			var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
39
 
40
			var topNode = document.firstChild;
41
            t.assertTrue(topNode !== null);
42
			t.assertTrue(topNode.tagName === "parentNode");
43
			t.assertTrue(text === dojox.data.dom.textContent(topNode));
44
            dojo._destroyElement(topNode);
45
			t.assertTrue(document.firstChild === null);
46
		},
47
		function testSetTextContent(t){
48
			var text = "This is a bunch of child text on the node";
49
			var text2 = "This is the new text";
50
			var simpleXml = "<parentNode>" + text + "</parentNode>";
51
			var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
52
 
53
			var topNode = document.firstChild;
54
			t.assertTrue(topNode !== null);
55
			t.assertTrue(topNode.tagName === "parentNode");
56
			t.assertTrue(text === dojox.data.dom.textContent(topNode));
57
			dojox.data.dom.textContent(topNode, text2);
58
			t.assertTrue(text2 === dojox.data.dom.textContent(topNode));
59
			dojo._destroyElement(topNode);
60
			t.assertTrue(document.firstChild === null);
61
 
62
		},
63
		function testReplaceChildrenArray(t){
64
			var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
65
			var simpleXml2 = "<parentNode><child4/><child5/><child6/><child7/></parentNode>";
66
			var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
67
			var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
68
 
69
			var topNode1 = doc1.firstChild;
70
			var topNode2 = doc2.firstChild;
71
            t.assertTrue(topNode1 !== null);
72
			t.assertTrue(topNode1.tagName === "parentNode");
73
            t.assertTrue(topNode2 !== null);
74
			t.assertTrue(topNode2.tagName === "parentNode");
75
			dojox.data.dom.removeChildren(topNode1);
76
			var newChildren=[];
77
			for(var i=0;i<topNode2.childNodes.length;i++){
78
				newChildren.push(topNode2.childNodes[i]);
79
			}
80
			dojox.data.dom.removeChildren(topNode2);
81
			dojox.data.dom.replaceChildren(topNode1,newChildren);
82
			t.assertTrue(topNode1.childNodes.length === 4);
83
			t.assertTrue(topNode1.firstChild.tagName === "child4");
84
			t.assertTrue(topNode1.lastChild.tagName === "child7");
85
 
86
		},
87
		function testReplaceChildrenSingle(t){
88
			var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
89
			var simpleXml2 = "<parentNode><child4/></parentNode>";
90
			var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
91
			var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
92
 
93
			var topNode1 = doc1.firstChild;
94
			var topNode2 = doc2.firstChild;
95
            t.assertTrue(topNode1 !== null);
96
			t.assertTrue(topNode1.tagName === "parentNode");
97
            t.assertTrue(topNode2 !== null);
98
			t.assertTrue(topNode2.tagName === "parentNode");
99
			dojox.data.dom.removeChildren(topNode1);
100
 
101
			var newChildren = topNode2.firstChild;
102
			dojox.data.dom.removeChildren(topNode2);
103
			dojox.data.dom.replaceChildren(topNode1,newChildren);
104
			t.assertTrue(topNode1.childNodes.length === 1);
105
			t.assertTrue(topNode1.firstChild.tagName === "child4");
106
			t.assertTrue(topNode1.lastChild.tagName === "child4");
107
		},
108
		function testRemoveChildren(t){
109
			var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
110
			var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
111
 
112
			var topNode1 = doc1.firstChild;
113
            t.assertTrue(topNode1 !== null);
114
			t.assertTrue(topNode1.tagName === "parentNode");
115
			dojox.data.dom.removeChildren(topNode1);
116
			t.assertTrue(topNode1.childNodes.length === 0);
117
			t.assertTrue(topNode1.firstChild === null);
118
		},
119
		function testInnerXML(t){
120
			var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
121
			var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
122
 
123
			var topNode1 = doc1.firstChild;
124
            t.assertTrue(topNode1 !== null);
125
			t.assertTrue(topNode1.tagName === "parentNode");
126
 
127
			var innerXml = dojox.data.dom.innerXML(topNode1);
128
			t.assertTrue(simpleXml1 === innerXml);
129
		}
130
	]
131
);
132
 
133
}