Debian Codegraph @

dojox/data/tests/stores/HtmlStore.js

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