2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.data.tests.stores.XmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.data.tests.stores.XmlStore"] = true;
|
|
|
3 |
dojo.provide("dojox.data.tests.stores.XmlStore");
|
|
|
4 |
dojo.require("dojox.data.XmlStore");
|
|
|
5 |
dojo.require("dojo.data.api.Read");
|
|
|
6 |
dojo.require("dojo.data.api.Write");
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
dojox.data.tests.stores.XmlStore.getBooks2Store = function(){
|
|
|
10 |
return new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books2.xml").toString(), label: "title"});
|
|
|
11 |
};
|
|
|
12 |
|
|
|
13 |
dojox.data.tests.stores.XmlStore.getBooksStore = function(){
|
|
|
14 |
return new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books.xml").toString(), label: "title"});
|
|
|
15 |
};
|
|
|
16 |
|
|
|
17 |
doh.register("dojox.data.tests.stores.XmlStore",
|
|
|
18 |
[
|
|
|
19 |
function testReadAPI_fetch_all(t){
|
|
|
20 |
// summary:
|
|
|
21 |
// Simple test of fetching all xml items through an XML element called isbn
|
|
|
22 |
// description:
|
|
|
23 |
// Simple test of fetching all xml items through an XML element called isbn
|
|
|
24 |
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
25 |
|
|
|
26 |
var d = new doh.Deferred();
|
|
|
27 |
function onComplete(items, request) {
|
|
|
28 |
t.assertEqual(20, items.length);
|
|
|
29 |
d.callback(true);
|
|
|
30 |
}
|
|
|
31 |
function onError(error, request) {
|
|
|
32 |
d.errback(error);
|
|
|
33 |
}
|
|
|
34 |
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
|
|
|
35 |
return d; //Object
|
|
|
36 |
},
|
|
|
37 |
function testReadAPI_fetch_one(t){
|
|
|
38 |
// summary:
|
|
|
39 |
// Simple test of fetching one xml items through an XML element called isbn
|
|
|
40 |
// description:
|
|
|
41 |
// Simple test of fetching one xml items through an XML element called isbn
|
|
|
42 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
43 |
|
|
|
44 |
var d = new doh.Deferred();
|
|
|
45 |
function onComplete(items, request) {
|
|
|
46 |
t.assertEqual(1, items.length);
|
|
|
47 |
d.callback(true);
|
|
|
48 |
}
|
|
|
49 |
function onError(error, request) {
|
|
|
50 |
d.errback(error);
|
|
|
51 |
}
|
|
|
52 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
53 |
return d; //Object
|
|
|
54 |
},
|
|
|
55 |
{
|
|
|
56 |
name: "testReadAPI_fetch_paging",
|
|
|
57 |
timeout: 10000,
|
|
|
58 |
runTest: function(t){
|
|
|
59 |
// summary:
|
|
|
60 |
// Simple test of fetching one xml items through an XML element called isbn
|
|
|
61 |
// description:
|
|
|
62 |
// Simple test of fetching one xml items through an XML element called isbn
|
|
|
63 |
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
64 |
var d = new doh.Deferred();
|
|
|
65 |
function dumpFirstFetch(items, request){
|
|
|
66 |
t.assertEqual(5, items.length);
|
|
|
67 |
request.start = 3;
|
|
|
68 |
request.count = 1;
|
|
|
69 |
request.onComplete = dumpSecondFetch;
|
|
|
70 |
store.fetch(request);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
function dumpSecondFetch(items, request){
|
|
|
74 |
t.assertEqual(1, items.length);
|
|
|
75 |
request.start = 0;
|
|
|
76 |
request.count = 5;
|
|
|
77 |
request.onComplete = dumpThirdFetch;
|
|
|
78 |
store.fetch(request);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
function dumpThirdFetch(items, request){
|
|
|
82 |
t.assertEqual(5, items.length);
|
|
|
83 |
request.start = 2;
|
|
|
84 |
request.count = 20;
|
|
|
85 |
request.onComplete = dumpFourthFetch;
|
|
|
86 |
store.fetch(request);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
function dumpFourthFetch(items, request){
|
|
|
90 |
t.assertEqual(18, items.length);
|
|
|
91 |
request.start = 9;
|
|
|
92 |
request.count = 100;
|
|
|
93 |
request.onComplete = dumpFifthFetch;
|
|
|
94 |
store.fetch(request);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
function dumpFifthFetch(items, request){
|
|
|
98 |
t.assertEqual(11, items.length);
|
|
|
99 |
request.start = 2;
|
|
|
100 |
request.count = 20;
|
|
|
101 |
request.onComplete = dumpSixthFetch;
|
|
|
102 |
store.fetch(request);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
function dumpSixthFetch(items, request){
|
|
|
106 |
t.assertEqual(18, items.length);
|
|
|
107 |
d.callback(true);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
function completed(items, request){
|
|
|
111 |
t.assertEqual(20, items.length);
|
|
|
112 |
request.start = 1;
|
|
|
113 |
request.count = 5;
|
|
|
114 |
request.onComplete = dumpFirstFetch;
|
|
|
115 |
store.fetch(request);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
function error(errData, request){
|
|
|
119 |
d.errback(errData);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
store.fetch({onComplete: completed, onError: error});
|
|
|
123 |
return d; //Object
|
|
|
124 |
}
|
|
|
125 |
},
|
|
|
126 |
function testReadAPI_fetch_pattern0(t){
|
|
|
127 |
// summary:
|
|
|
128 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
129 |
// description:
|
|
|
130 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
131 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
132 |
var d = new doh.Deferred();
|
|
|
133 |
function onComplete(items, request) {
|
|
|
134 |
t.assertEqual(1, items.length);
|
|
|
135 |
d.callback(true);
|
|
|
136 |
}
|
|
|
137 |
function onError(error, request) {
|
|
|
138 |
d.errback(error);
|
|
|
139 |
}
|
|
|
140 |
store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError});
|
|
|
141 |
return d; //Object
|
|
|
142 |
},
|
|
|
143 |
function testReadAPI_fetch_pattern1(t){
|
|
|
144 |
// summary:
|
|
|
145 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
146 |
// description:
|
|
|
147 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
148 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
149 |
var d = new doh.Deferred();
|
|
|
150 |
function onComplete(items, request) {
|
|
|
151 |
t.assertEqual(4, items.length);
|
|
|
152 |
d.callback(true);
|
|
|
153 |
}
|
|
|
154 |
function onError(error, request) {
|
|
|
155 |
d.errback(error);
|
|
|
156 |
}
|
|
|
157 |
store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError});
|
|
|
158 |
return d; //Object
|
|
|
159 |
},
|
|
|
160 |
function testReadAPI_fetch_pattern2(t){
|
|
|
161 |
// summary:
|
|
|
162 |
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
|
|
|
163 |
// description:
|
|
|
164 |
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
|
|
|
165 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
166 |
var d = new doh.Deferred();
|
|
|
167 |
function onComplete(items, request) {
|
|
|
168 |
t.assertEqual(5, items.length);
|
|
|
169 |
d.callback(true);
|
|
|
170 |
}
|
|
|
171 |
function onError(error, request) {
|
|
|
172 |
d.errback(error);
|
|
|
173 |
}
|
|
|
174 |
store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError});
|
|
|
175 |
return d; //Object
|
|
|
176 |
},
|
|
|
177 |
function testReadAPI_fetch_pattern_caseInsensitive(t){
|
|
|
178 |
// summary:
|
|
|
179 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
|
|
|
180 |
// description:
|
|
|
181 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
|
|
|
182 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
183 |
var d = new doh.Deferred();
|
|
|
184 |
function onComplete(items, request) {
|
|
|
185 |
t.assertEqual(1, items.length);
|
|
|
186 |
d.callback(true);
|
|
|
187 |
}
|
|
|
188 |
function onError(error, request) {
|
|
|
189 |
d.errback(error);
|
|
|
190 |
}
|
|
|
191 |
store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
|
|
|
192 |
return d; //Object
|
|
|
193 |
},
|
|
|
194 |
function testReadAPI_fetch_pattern_caseSensitive(t){
|
|
|
195 |
// summary:
|
|
|
196 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
|
|
|
197 |
// description:
|
|
|
198 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
|
|
|
199 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
200 |
var d = new doh.Deferred();
|
|
|
201 |
function onComplete(items, request) {
|
|
|
202 |
t.assertEqual(1, items.length);
|
|
|
203 |
d.callback(true);
|
|
|
204 |
}
|
|
|
205 |
function onError(error, request) {
|
|
|
206 |
d.errback(error);
|
|
|
207 |
}
|
|
|
208 |
store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
|
|
|
209 |
return d; //Object
|
|
|
210 |
},
|
|
|
211 |
function testReadAPI_fetch_all_rootItem(t){
|
|
|
212 |
// summary:
|
|
|
213 |
// Simple test of fetching all xml items through an XML element called isbn
|
|
|
214 |
// description:
|
|
|
215 |
// Simple test of fetching all xml items through an XML element called isbn
|
|
|
216 |
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books3.xml").toString(),
|
|
|
217 |
rootItem:"book"});
|
|
|
218 |
|
|
|
219 |
var d = new doh.Deferred();
|
|
|
220 |
function onComplete(items, request) {
|
|
|
221 |
t.assertEqual(5, items.length);
|
|
|
222 |
d.callback(true);
|
|
|
223 |
}
|
|
|
224 |
function onError(error, request) {
|
|
|
225 |
d.errback(error);
|
|
|
226 |
}
|
|
|
227 |
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
|
|
|
228 |
return d; //Object
|
|
|
229 |
},
|
|
|
230 |
function testReadAPI_fetch_withAttrMap_all(t){
|
|
|
231 |
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr.xml").toString(),
|
|
|
232 |
attributeMap: {"book.isbn": "@isbn"}});
|
|
|
233 |
|
|
|
234 |
var d = new doh.Deferred();
|
|
|
235 |
function onComplete(items, request) {
|
|
|
236 |
t.assertEqual(5, items.length);
|
|
|
237 |
d.callback(true);
|
|
|
238 |
}
|
|
|
239 |
function onError(error, request) {
|
|
|
240 |
console.debug(error);
|
|
|
241 |
d.errback(error);
|
|
|
242 |
}
|
|
|
243 |
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
|
|
|
244 |
return d; //Object
|
|
|
245 |
},
|
|
|
246 |
function testReadAPI_fetch_withAttrMap_one(t){
|
|
|
247 |
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr.xml").toString(),
|
|
|
248 |
attributeMap: {"book.isbn": "@isbn"}});
|
|
|
249 |
|
|
|
250 |
var d = new doh.Deferred();
|
|
|
251 |
function onComplete(items, request) {
|
|
|
252 |
t.assertEqual(1, items.length);
|
|
|
253 |
d.callback(true);
|
|
|
254 |
}
|
|
|
255 |
function onError(error, request) {
|
|
|
256 |
console.debug(error);
|
|
|
257 |
d.errback(error);
|
|
|
258 |
}
|
|
|
259 |
store.fetch({query:{isbn:"2"}, onComplete: onComplete, onError: onError});
|
|
|
260 |
return d; //Object
|
|
|
261 |
},
|
|
|
262 |
function testReadAPI_fetch_withAttrMap_pattern0(t){
|
|
|
263 |
// summary:
|
|
|
264 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
265 |
// description:
|
|
|
266 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
267 |
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
|
|
|
268 |
attributeMap: {"book.isbn": "@isbn"}});
|
|
|
269 |
var d = new doh.Deferred();
|
|
|
270 |
function onComplete(items, request) {
|
|
|
271 |
t.assertEqual(3, items.length);
|
|
|
272 |
d.callback(true);
|
|
|
273 |
}
|
|
|
274 |
function onError(error, request) {
|
|
|
275 |
d.errback(error);
|
|
|
276 |
}
|
|
|
277 |
store.fetch({query:{isbn:"ABC?"}, onComplete: onComplete, onError: onError});
|
|
|
278 |
return d; //Object
|
|
|
279 |
},
|
|
|
280 |
function testReadAPI_fetch_withAttrMap_pattern1(t){
|
|
|
281 |
// summary:
|
|
|
282 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
283 |
// description:
|
|
|
284 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
285 |
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
|
|
|
286 |
attributeMap: {"book.isbn": "@isbn"}});
|
|
|
287 |
var d = new doh.Deferred();
|
|
|
288 |
function onComplete(items, request) {
|
|
|
289 |
t.assertEqual(5, items.length);
|
|
|
290 |
d.callback(true);
|
|
|
291 |
}
|
|
|
292 |
function onError(error, request) {
|
|
|
293 |
d.errback(error);
|
|
|
294 |
}
|
|
|
295 |
store.fetch({query:{isbn:"A*"}, onComplete: onComplete, onError: onError});
|
|
|
296 |
return d; //Object
|
|
|
297 |
},
|
|
|
298 |
function testReadAPI_fetch_withAttrMap_pattern2(t){
|
|
|
299 |
// summary:
|
|
|
300 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
301 |
// description:
|
|
|
302 |
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
|
|
|
303 |
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
|
|
|
304 |
attributeMap: {"book.isbn": "@isbn"}});
|
|
|
305 |
var d = new doh.Deferred();
|
|
|
306 |
function onComplete(items, request) {
|
|
|
307 |
t.assertEqual(2, items.length);
|
|
|
308 |
d.callback(true);
|
|
|
309 |
}
|
|
|
310 |
function onError(error, request) {
|
|
|
311 |
d.errback(error);
|
|
|
312 |
}
|
|
|
313 |
store.fetch({query:{isbn:"?C*"}, onComplete: onComplete, onError: onError});
|
|
|
314 |
return d; //Object
|
|
|
315 |
},
|
|
|
316 |
|
|
|
317 |
function testReadAPI_getLabel(t){
|
|
|
318 |
// summary:
|
|
|
319 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
320 |
// description:
|
|
|
321 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
322 |
|
|
|
323 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
324 |
|
|
|
325 |
var d = new doh.Deferred();
|
|
|
326 |
function onComplete(items, request){
|
|
|
327 |
t.assertEqual(items.length, 1);
|
|
|
328 |
var label = store.getLabel(items[0]);
|
|
|
329 |
t.assertTrue(label !== null);
|
|
|
330 |
t.assertEqual("Title of 4", label);
|
|
|
331 |
d.callback(true);
|
|
|
332 |
}
|
|
|
333 |
function onError(error, request) {
|
|
|
334 |
d.errback(error);
|
|
|
335 |
}
|
|
|
336 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
337 |
return d;
|
|
|
338 |
},
|
|
|
339 |
function testReadAPI_getLabelAttributes(t){
|
|
|
340 |
// summary:
|
|
|
341 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
342 |
// description:
|
|
|
343 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
344 |
|
|
|
345 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
346 |
|
|
|
347 |
var d = new doh.Deferred();
|
|
|
348 |
function onComplete(items, request){
|
|
|
349 |
t.assertEqual(items.length, 1);
|
|
|
350 |
var labelList = store.getLabelAttributes(items[0]);
|
|
|
351 |
t.assertTrue(dojo.isArray(labelList));
|
|
|
352 |
t.assertEqual("title", labelList[0]);
|
|
|
353 |
d.callback(true);
|
|
|
354 |
}
|
|
|
355 |
function onError(error, request) {
|
|
|
356 |
d.errback(error);
|
|
|
357 |
}
|
|
|
358 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
359 |
return d;
|
|
|
360 |
},
|
|
|
361 |
|
|
|
362 |
function testReadAPI_getValue(t){
|
|
|
363 |
// summary:
|
|
|
364 |
// Simple test of the getValue API
|
|
|
365 |
// description:
|
|
|
366 |
// Simple test of the getValue API
|
|
|
367 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
368 |
|
|
|
369 |
var d = new doh.Deferred();
|
|
|
370 |
function onComplete(items, request) {
|
|
|
371 |
t.assertEqual(1, items.length);
|
|
|
372 |
var item = items[0];
|
|
|
373 |
t.assertTrue(store.hasAttribute(item,"isbn"));
|
|
|
374 |
t.assertEqual(store.getValue(item,"isbn"), "A9B574");
|
|
|
375 |
d.callback(true);
|
|
|
376 |
}
|
|
|
377 |
function onError(error, request) {
|
|
|
378 |
d.errback(error);
|
|
|
379 |
}
|
|
|
380 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
381 |
return d; //Object
|
|
|
382 |
},
|
|
|
383 |
function testReadAPI_getValues(t){
|
|
|
384 |
// summary:
|
|
|
385 |
// Simple test of the getValues API
|
|
|
386 |
// description:
|
|
|
387 |
// Simple test of the getValues API
|
|
|
388 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
389 |
|
|
|
390 |
var d = new doh.Deferred();
|
|
|
391 |
function onComplete(items, request) {
|
|
|
392 |
t.assertEqual(1, items.length);
|
|
|
393 |
var item = items[0];
|
|
|
394 |
t.assertTrue(store.hasAttribute(item,"isbn"));
|
|
|
395 |
var values = store.getValues(item,"isbn");
|
|
|
396 |
t.assertEqual(1,values.length);
|
|
|
397 |
t.assertEqual("A9B574", values[0]);
|
|
|
398 |
d.callback(true);
|
|
|
399 |
}
|
|
|
400 |
function onError(error, request) {
|
|
|
401 |
d.errback(error);
|
|
|
402 |
}
|
|
|
403 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
404 |
return d; //Object
|
|
|
405 |
},
|
|
|
406 |
function testReadAPI_isItem(t){
|
|
|
407 |
// summary:
|
|
|
408 |
// Simple test of the isItem API
|
|
|
409 |
// description:
|
|
|
410 |
// Simple test of the isItem API
|
|
|
411 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
412 |
|
|
|
413 |
var d = new doh.Deferred();
|
|
|
414 |
function onComplete(items, request) {
|
|
|
415 |
t.assertEqual(1, items.length);
|
|
|
416 |
var item = items[0];
|
|
|
417 |
t.assertTrue(store.isItem(item));
|
|
|
418 |
t.assertTrue(!store.isItem({}));
|
|
|
419 |
t.assertTrue(!store.isItem("Foo"));
|
|
|
420 |
t.assertTrue(!store.isItem(1));
|
|
|
421 |
d.callback(true);
|
|
|
422 |
}
|
|
|
423 |
function onError(error, request) {
|
|
|
424 |
d.errback(error);
|
|
|
425 |
}
|
|
|
426 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
427 |
return d; //Object
|
|
|
428 |
},
|
|
|
429 |
function testReadAPI_isItem_multistore(t){
|
|
|
430 |
// summary:
|
|
|
431 |
// Simple test of the isItem API across multiple store instances.
|
|
|
432 |
// description:
|
|
|
433 |
// Simple test of the isItem API across multiple store instances.
|
|
|
434 |
var store1 = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
435 |
var store2 = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
436 |
|
|
|
437 |
var d = new doh.Deferred();
|
|
|
438 |
function onComplete1(items, request) {
|
|
|
439 |
t.assertEqual(1, items.length);
|
|
|
440 |
var item1 = items[0];
|
|
|
441 |
t.assertTrue(store1.isItem(item1));
|
|
|
442 |
|
|
|
443 |
function onComplete2(items, request) {
|
|
|
444 |
t.assertEqual(1, items.length);
|
|
|
445 |
var item2 = items[0];
|
|
|
446 |
t.assertTrue(store2.isItem(item2));
|
|
|
447 |
t.assertTrue(!store1.isItem(item2));
|
|
|
448 |
t.assertTrue(!store2.isItem(item1));
|
|
|
449 |
d.callback(true);
|
|
|
450 |
}
|
|
|
451 |
store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError});
|
|
|
452 |
}
|
|
|
453 |
function onError(error, request) {
|
|
|
454 |
d.errback(error);
|
|
|
455 |
}
|
|
|
456 |
store1.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError});
|
|
|
457 |
return d; //Object
|
|
|
458 |
},
|
|
|
459 |
function testReadAPI_hasAttribute(t){
|
|
|
460 |
// summary:
|
|
|
461 |
// Simple test of the hasAttribute API
|
|
|
462 |
// description:
|
|
|
463 |
// Simple test of the hasAttribute API
|
|
|
464 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
465 |
|
|
|
466 |
var d = new doh.Deferred();
|
|
|
467 |
function onComplete(items, request) {
|
|
|
468 |
t.assertEqual(1, items.length);
|
|
|
469 |
var item = items[0];
|
|
|
470 |
t.assertTrue(store.hasAttribute(item,"isbn"));
|
|
|
471 |
t.assertTrue(!store.hasAttribute(item,"bob"));
|
|
|
472 |
d.callback(true);
|
|
|
473 |
}
|
|
|
474 |
function onError(error, request) {
|
|
|
475 |
d.errback(error);
|
|
|
476 |
}
|
|
|
477 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
478 |
return d; //Object
|
|
|
479 |
},
|
|
|
480 |
function testReadAPI_containsValue(t){
|
|
|
481 |
// summary:
|
|
|
482 |
// Simple test of the containsValue API
|
|
|
483 |
// description:
|
|
|
484 |
// Simple test of the containsValue API
|
|
|
485 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
486 |
|
|
|
487 |
var d = new doh.Deferred();
|
|
|
488 |
function onComplete(items, request) {
|
|
|
489 |
t.assertEqual(1, items.length);
|
|
|
490 |
var item = items[0];
|
|
|
491 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
492 |
t.assertTrue(!store.containsValue(item,"isbn", "bob"));
|
|
|
493 |
d.callback(true);
|
|
|
494 |
}
|
|
|
495 |
function onError(error, request) {
|
|
|
496 |
d.errback(error);
|
|
|
497 |
}
|
|
|
498 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
499 |
return d; //Object
|
|
|
500 |
},
|
|
|
501 |
function testReadAPI_sortDescending(t){
|
|
|
502 |
// summary:
|
|
|
503 |
// Simple test of the sorting API in descending order.
|
|
|
504 |
// description:
|
|
|
505 |
// Simple test of the sorting API in descending order.
|
|
|
506 |
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
507 |
|
|
|
508 |
//Comparison is done as a string type (toString comparison), so the order won't be numeric
|
|
|
509 |
//So have to compare in 'alphabetic' order.
|
|
|
510 |
var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1];
|
|
|
511 |
|
|
|
512 |
var d = new doh.Deferred();
|
|
|
513 |
function onComplete(items, request) {
|
|
|
514 |
console.log("Number of items: " + items.length);
|
|
|
515 |
t.assertEqual(20, items.length);
|
|
|
516 |
|
|
|
517 |
for(var i = 0; i < items.length; i++){
|
|
|
518 |
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
|
|
|
519 |
}
|
|
|
520 |
d.callback(true);
|
|
|
521 |
}
|
|
|
522 |
function onError(error, request) {
|
|
|
523 |
d.errback(error);
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
var sortAttributes = [{attribute: "isbn", descending: true}];
|
|
|
527 |
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
|
|
|
528 |
return d; //Object
|
|
|
529 |
},
|
|
|
530 |
function testReadAPI_sortAscending(t){
|
|
|
531 |
// summary:
|
|
|
532 |
// Simple test of the sorting API in ascending order.
|
|
|
533 |
// description:
|
|
|
534 |
// Simple test of the sorting API in ascending order.
|
|
|
535 |
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
536 |
|
|
|
537 |
//Comparison is done as a string type (toString comparison), so the order won't be numeric
|
|
|
538 |
//So have to compare in 'alphabetic' order.
|
|
|
539 |
var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9];
|
|
|
540 |
|
|
|
541 |
var d = new doh.Deferred();
|
|
|
542 |
function onComplete(items, request) {
|
|
|
543 |
t.assertEqual(20, items.length);
|
|
|
544 |
var itemId = 1;
|
|
|
545 |
for(var i = 0; i < items.length; i++){
|
|
|
546 |
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
|
|
|
547 |
}
|
|
|
548 |
d.callback(true);
|
|
|
549 |
}
|
|
|
550 |
function onError(error, request) {
|
|
|
551 |
d.errback(error);
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
var sortAttributes = [{attribute: "isbn"}];
|
|
|
555 |
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
|
|
|
556 |
return d; //Object
|
|
|
557 |
},
|
|
|
558 |
function testReadAPI_sortDescendingNumeric(t){
|
|
|
559 |
// summary:
|
|
|
560 |
// Simple test of the sorting API in descending order using a numeric comparator.
|
|
|
561 |
// description:
|
|
|
562 |
// Simple test of the sorting API in descending order using a numeric comparator.
|
|
|
563 |
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
564 |
|
|
|
565 |
//isbn should be treated as a numeric, not as a string comparison
|
|
|
566 |
store.comparatorMap = {};
|
|
|
567 |
store.comparatorMap["isbn"] = function(a, b){
|
|
|
568 |
var ret = 0;
|
|
|
569 |
if(parseInt(a.toString()) > parseInt(b.toString())){
|
|
|
570 |
ret = 1;
|
|
|
571 |
}else if(parseInt(a.toString()) < parseInt(b.toString())){
|
|
|
572 |
ret = -1;
|
|
|
573 |
}
|
|
|
574 |
return ret; //int, {-1,0,1}
|
|
|
575 |
};
|
|
|
576 |
|
|
|
577 |
var d = new doh.Deferred();
|
|
|
578 |
function onComplete(items, request) {
|
|
|
579 |
t.assertEqual(20, items.length);
|
|
|
580 |
var itemId = 20;
|
|
|
581 |
for(var i = 0; i < items.length; i++){
|
|
|
582 |
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
|
|
|
583 |
itemId--;
|
|
|
584 |
}
|
|
|
585 |
d.callback(true);
|
|
|
586 |
}
|
|
|
587 |
function onError(error, request) {
|
|
|
588 |
d.errback(error);
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
var sortAttributes = [{attribute: "isbn", descending: true}];
|
|
|
592 |
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
|
|
|
593 |
return d; //Object
|
|
|
594 |
},
|
|
|
595 |
function testReadAPI_sortAscendingNumeric(t){
|
|
|
596 |
// summary:
|
|
|
597 |
// Simple test of the sorting API in ascending order using a numeric comparator.
|
|
|
598 |
// description:
|
|
|
599 |
// Simple test of the sorting API in ascending order using a numeric comparator.
|
|
|
600 |
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
601 |
|
|
|
602 |
//isbn should be treated as a numeric, not as a string comparison
|
|
|
603 |
store.comparatorMap = {};
|
|
|
604 |
store.comparatorMap["isbn"] = function(a, b){
|
|
|
605 |
var ret = 0;
|
|
|
606 |
if(parseInt(a.toString()) > parseInt(b.toString())){
|
|
|
607 |
ret = 1;
|
|
|
608 |
}else if(parseInt(a.toString()) < parseInt(b.toString())){
|
|
|
609 |
ret = -1;
|
|
|
610 |
}
|
|
|
611 |
return ret; //int, {-1,0,1}
|
|
|
612 |
};
|
|
|
613 |
|
|
|
614 |
var d = new doh.Deferred();
|
|
|
615 |
function onComplete(items, request) {
|
|
|
616 |
t.assertEqual(20, items.length);
|
|
|
617 |
var itemId = 1;
|
|
|
618 |
for(var i = 0; i < items.length; i++){
|
|
|
619 |
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
|
|
|
620 |
itemId++;
|
|
|
621 |
}
|
|
|
622 |
d.callback(true);
|
|
|
623 |
}
|
|
|
624 |
function onError(error, request) {
|
|
|
625 |
d.errback(error);
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
var sortAttributes = [{attribute: "isbn"}];
|
|
|
629 |
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
|
|
|
630 |
return d; //Object
|
|
|
631 |
},
|
|
|
632 |
function testReadAPI_isItemLoaded(t){
|
|
|
633 |
// summary:
|
|
|
634 |
// Simple test of the isItemLoaded API
|
|
|
635 |
// description:
|
|
|
636 |
// Simple test of the isItemLoaded API
|
|
|
637 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
638 |
|
|
|
639 |
var d = new doh.Deferred();
|
|
|
640 |
function onComplete(items, request) {
|
|
|
641 |
t.assertEqual(1, items.length);
|
|
|
642 |
var item = items[0];
|
|
|
643 |
t.assertTrue(store.isItemLoaded(item));
|
|
|
644 |
d.callback(true);
|
|
|
645 |
}
|
|
|
646 |
function onError(error, request) {
|
|
|
647 |
d.errback(error);
|
|
|
648 |
}
|
|
|
649 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
650 |
return d; //Object
|
|
|
651 |
},
|
|
|
652 |
function testReadAPI_getFeatures(t){
|
|
|
653 |
// summary:
|
|
|
654 |
// Simple test of the getFeatures function of the store
|
|
|
655 |
// description:
|
|
|
656 |
// Simple test of the getFeatures function of the store
|
|
|
657 |
|
|
|
658 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
659 |
var features = store.getFeatures();
|
|
|
660 |
var count = 0;
|
|
|
661 |
for(i in features){
|
|
|
662 |
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Write"));
|
|
|
663 |
count++;
|
|
|
664 |
}
|
|
|
665 |
t.assertEqual(2, count);
|
|
|
666 |
},
|
|
|
667 |
function testReadAPI_getAttributes(t){
|
|
|
668 |
// summary:
|
|
|
669 |
// Simple test of the getAttributes API
|
|
|
670 |
// description:
|
|
|
671 |
// Simple test of the getAttributes API
|
|
|
672 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
673 |
|
|
|
674 |
var d = new doh.Deferred();
|
|
|
675 |
function onComplete(items, request) {
|
|
|
676 |
t.assertEqual(1, items.length);
|
|
|
677 |
var item = items[0];
|
|
|
678 |
var attributes = store.getAttributes(item);
|
|
|
679 |
|
|
|
680 |
//Should be six, as all items should have tagName, childNodes, and text() special attributes
|
|
|
681 |
//in addition to any doc defined ones, which in this case are author, title, and isbn
|
|
|
682 |
//FIXME: Figure out why IE returns 5! Need to get firebug lite working in IE for that.
|
|
|
683 |
//Suspect it's childNodes, may not be defined if there are no child nodes.
|
|
|
684 |
for(var i = 0; i < attributes.length; i++){
|
|
|
685 |
console.log("attribute found: " + attributes[i]);
|
|
|
686 |
}
|
|
|
687 |
if(dojo.isIE){
|
|
|
688 |
t.assertEqual(5,attributes.length);
|
|
|
689 |
}else{
|
|
|
690 |
t.assertEqual(6,attributes.length);
|
|
|
691 |
}
|
|
|
692 |
d.callback(true);
|
|
|
693 |
}
|
|
|
694 |
function onError(error, request) {
|
|
|
695 |
d.errback(error);
|
|
|
696 |
}
|
|
|
697 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
698 |
return d; //Object
|
|
|
699 |
},
|
|
|
700 |
function testWriteAPI_setValue(t){
|
|
|
701 |
// summary:
|
|
|
702 |
// Simple test of the setValue API
|
|
|
703 |
// description:
|
|
|
704 |
// Simple test of the setValue API
|
|
|
705 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
706 |
|
|
|
707 |
var d = new doh.Deferred();
|
|
|
708 |
function onComplete(items, request) {
|
|
|
709 |
t.assertEqual(1, items.length);
|
|
|
710 |
var item = items[0];
|
|
|
711 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
712 |
store.setValue(item, "isbn", "A9B574-new");
|
|
|
713 |
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
|
|
|
714 |
d.callback(true);
|
|
|
715 |
}
|
|
|
716 |
function onError(error, request) {
|
|
|
717 |
d.errback(error);
|
|
|
718 |
}
|
|
|
719 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
720 |
return d; //Object
|
|
|
721 |
},
|
|
|
722 |
function testWriteAPI_setValues(t){
|
|
|
723 |
// summary:
|
|
|
724 |
// Simple test of the setValues API
|
|
|
725 |
// description:
|
|
|
726 |
// Simple test of the setValues API
|
|
|
727 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
728 |
|
|
|
729 |
var d = new doh.Deferred();
|
|
|
730 |
function onComplete(items, request) {
|
|
|
731 |
t.assertEqual(1, items.length);
|
|
|
732 |
var item = items[0];
|
|
|
733 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
734 |
store.setValues(item, "isbn", ["A9B574-new1", "A9B574-new2"]);
|
|
|
735 |
var values = store.getValues(item,"isbn");
|
|
|
736 |
t.assertEqual(values[0].toString(), "A9B574-new1");
|
|
|
737 |
t.assertEqual(values[1].toString(), "A9B574-new2");
|
|
|
738 |
store.setValues(values[0], "text()", ["A9B574", "-new3"]);
|
|
|
739 |
t.assertEqual(store.getValue(values[0],"text()").toString(), "A9B574-new3");
|
|
|
740 |
d.callback(true);
|
|
|
741 |
}
|
|
|
742 |
function onError(error, request) {
|
|
|
743 |
d.errback(error);
|
|
|
744 |
}
|
|
|
745 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
746 |
return d; //Object
|
|
|
747 |
},
|
|
|
748 |
function testWriteAPI_unsetAttribute(t){
|
|
|
749 |
// summary:
|
|
|
750 |
// Simple test of the unsetAttribute API
|
|
|
751 |
// description:
|
|
|
752 |
// Simple test of the unsetAttribute API
|
|
|
753 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
754 |
|
|
|
755 |
var d = new doh.Deferred();
|
|
|
756 |
function onComplete(items, request) {
|
|
|
757 |
t.assertEqual(1, items.length);
|
|
|
758 |
var item = items[0];
|
|
|
759 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
760 |
store.unsetAttribute(item,"isbn");
|
|
|
761 |
t.assertTrue(!store.hasAttribute(item,"isbn"));
|
|
|
762 |
t.assertTrue(store.isDirty(item));
|
|
|
763 |
d.callback(true);
|
|
|
764 |
}
|
|
|
765 |
function onError(error, request) {
|
|
|
766 |
d.errback(error);
|
|
|
767 |
}
|
|
|
768 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
769 |
return d; //Object
|
|
|
770 |
},
|
|
|
771 |
function testWriteAPI_isDirty(t){
|
|
|
772 |
// summary:
|
|
|
773 |
// Simple test of the isDirty API
|
|
|
774 |
// description:
|
|
|
775 |
// Simple test of the isDirty API
|
|
|
776 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
777 |
|
|
|
778 |
var d = new doh.Deferred();
|
|
|
779 |
function onComplete(items, request) {
|
|
|
780 |
t.assertEqual(1, items.length);
|
|
|
781 |
var item = items[0];
|
|
|
782 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
783 |
store.setValue(item, "isbn", "A9B574-new");
|
|
|
784 |
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
|
|
|
785 |
t.assertTrue(store.isDirty(item));
|
|
|
786 |
d.callback(true);
|
|
|
787 |
}
|
|
|
788 |
function onError(error, request) {
|
|
|
789 |
d.errback(error);
|
|
|
790 |
}
|
|
|
791 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
792 |
return d; //Object
|
|
|
793 |
},
|
|
|
794 |
function testWriteAPI_revert(t){
|
|
|
795 |
// summary:
|
|
|
796 |
// Simple test of the isDirty API
|
|
|
797 |
// description:
|
|
|
798 |
// Simple test of the isDirty API
|
|
|
799 |
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
|
|
|
800 |
|
|
|
801 |
var d = new doh.Deferred();
|
|
|
802 |
function onComplete(items, request) {
|
|
|
803 |
t.assertEqual(1, items.length);
|
|
|
804 |
var item = items[0];
|
|
|
805 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
806 |
t.assertTrue(!store.isDirty(item));
|
|
|
807 |
store.setValue(item, "isbn", "A9B574-new");
|
|
|
808 |
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
|
|
|
809 |
t.assertTrue(store.isDirty(item));
|
|
|
810 |
store.revert();
|
|
|
811 |
|
|
|
812 |
//Fetch again to see if it reset the state.
|
|
|
813 |
function onComplete1(items, request) {
|
|
|
814 |
t.assertEqual(1, items.length);
|
|
|
815 |
var item = items[0];
|
|
|
816 |
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
|
|
|
817 |
d.callback(true);
|
|
|
818 |
}
|
|
|
819 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError});
|
|
|
820 |
}
|
|
|
821 |
function onError(error, request) {
|
|
|
822 |
d.errback(error);
|
|
|
823 |
}
|
|
|
824 |
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
|
|
|
825 |
return d; //Object
|
|
|
826 |
},
|
|
|
827 |
function testReadAPI_functionConformance(t){
|
|
|
828 |
// summary:
|
|
|
829 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
830 |
// description:
|
|
|
831 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
832 |
|
|
|
833 |
var testStore = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
834 |
var readApi = new dojo.data.api.Read();
|
|
|
835 |
var passed = true;
|
|
|
836 |
|
|
|
837 |
for(i in readApi){
|
|
|
838 |
var member = readApi[i];
|
|
|
839 |
//Check that all the 'Read' defined functions exist on the test store.
|
|
|
840 |
if(typeof member === "function"){
|
|
|
841 |
var testStoreMember = testStore[i];
|
|
|
842 |
if(!(typeof testStoreMember === "function")){
|
|
|
843 |
console.log("Problem with function: [" + i + "]");
|
|
|
844 |
passed = false;
|
|
|
845 |
break;
|
|
|
846 |
}
|
|
|
847 |
}
|
|
|
848 |
}
|
|
|
849 |
t.assertTrue(passed);
|
|
|
850 |
},
|
|
|
851 |
function testWriteAPI_functionConformance(t){
|
|
|
852 |
// summary:
|
|
|
853 |
// Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
854 |
// description:
|
|
|
855 |
// Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
856 |
|
|
|
857 |
var testStore = dojox.data.tests.stores.XmlStore.getBooksStore();
|
|
|
858 |
var writeApi = new dojo.data.api.Write();
|
|
|
859 |
var passed = true;
|
|
|
860 |
|
|
|
861 |
for(i in writeApi){
|
|
|
862 |
var member = writeApi[i];
|
|
|
863 |
//Check that all the 'Write' defined functions exist on the test store.
|
|
|
864 |
if(typeof member === "function"){
|
|
|
865 |
var testStoreMember = testStore[i];
|
|
|
866 |
if(!(typeof testStoreMember === "function")){
|
|
|
867 |
passed = false;
|
|
|
868 |
break;
|
|
|
869 |
}
|
|
|
870 |
}
|
|
|
871 |
}
|
|
|
872 |
t.assertTrue(passed);
|
|
|
873 |
}
|
|
|
874 |
]
|
|
|
875 |
);
|
|
|
876 |
|
|
|
877 |
|
|
|
878 |
|
|
|
879 |
|
|
|
880 |
|
|
|
881 |
}
|