1 if(!dojo._hasResource["dojox.data.tests.stores.HtmlTableStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.HtmlTableStore"] = true;
3 dojo.provide("dojox.data.tests.stores.HtmlTableStore");
4 dojo.require("dojox.data.HtmlTableStore");
5 dojo.require("dojo.data.api.Read");
6 dojo.require("dojo.data.api.Identity");
9 dojox.data.tests.stores.HtmlTableStore.getBooks2Store = function(){
10 return new dojox.data.HtmlTableStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books2.html").toString(), tableId: "books2"});
13 dojox.data.tests.stores.HtmlTableStore.getBooksStore = function(){
14 return new dojox.data.HtmlTableStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books.html").toString(), tableId: "books"});
17 doh.register("dojox.data.tests.stores.HtmlTableStore",
19 /***************************************
20 dojo.data.api.Read API
21 ***************************************/
22 function testReadAPI_fetch_all(t){
24 // Simple test of fetching all xml items through an XML element called isbn
26 // Simple test of fetching all xml items through an XML element called isbn
27 var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
29 var d = new doh.Deferred();
30 function onComplete(items, request) {
31 t.assertEqual(20, items.length);
34 function onError(error, request) {
37 store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
40 function testReadAPI_fetch_one(t){
42 // Simple test of fetching one xml items through an XML element called isbn
44 // Simple test of fetching one xml items through an XML element called isbn
45 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
47 var d = new doh.Deferred();
48 function onComplete(items, request) {
49 t.assertEqual(1, items.length);
52 function onError(error, request) {
55 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
58 function testReadAPI_fetch_paging(t){
60 // Simple test of fetching one xml items through an XML element called isbn
62 // Simple test of fetching one xml items through an XML element called isbn
63 var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
65 var d = new doh.Deferred();
66 function dumpFirstFetch(items, request){
67 t.assertEqual(5, items.length);
70 request.onComplete = dumpSecondFetch;
74 function dumpSecondFetch(items, request){
75 t.assertEqual(1, items.length);
78 request.onComplete = dumpThirdFetch;
82 function dumpThirdFetch(items, request){
83 t.assertEqual(5, items.length);
86 request.onComplete = dumpFourthFetch;
90 function dumpFourthFetch(items, request){
91 t.assertEqual(18, items.length);
94 request.onComplete = dumpFifthFetch;
98 function dumpFifthFetch(items, request){
99 t.assertEqual(11, items.length);
102 request.onComplete = dumpSixthFetch;
103 store.fetch(request);
106 function dumpSixthFetch(items, request){
107 t.assertEqual(18, items.length);
111 function completed(items, request){
112 t.assertEqual(20, items.length);
115 request.onComplete = dumpFirstFetch;
116 store.fetch(request);
119 function error(errData, request){
123 store.fetch({onComplete: completed, onError: error});
126 function testReadAPI_fetch_pattern0(t){
128 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match
130 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match
131 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
132 var d = new doh.Deferred();
133 function onComplete(items, request) {
134 t.assertEqual(1, items.length);
137 function onError(error, request) {
140 store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError});
143 function testReadAPI_fetch_pattern1(t){
145 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match
147 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match
148 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
149 var d = new doh.Deferred();
150 function onComplete(items, request) {
151 t.assertEqual(4, items.length);
154 function onError(error, request) {
157 store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError});
160 function testReadAPI_fetch_pattern2(t){
162 // Simple test of fetching one xml items through an XML element called isbn with * pattern match
164 // Simple test of fetching one xml items through an XML element called isbn with * pattern match
165 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
166 var d = new doh.Deferred();
167 function onComplete(items, request) {
168 t.assertEqual(5, items.length);
171 function onError(error, request) {
174 store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError});
177 function testReadAPI_fetch_pattern_caseInsensitive(t){
179 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
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.HtmlTableStore.getBooks2Store();
183 var d = new doh.Deferred();
184 function onComplete(items, request) {
185 t.assertEqual(1, items.length);
188 function onError(error, request) {
191 store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
194 function testReadAPI_fetch_pattern_caseSensitive(t){
196 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
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.HtmlTableStore.getBooks2Store();
200 var d = new doh.Deferred();
201 function onComplete(items, request) {
202 t.assertEqual(1, items.length);
205 function onError(error, request) {
208 store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
211 function testReadAPI_getLabel(t){
213 // Simple test of the getLabel function against a store set that has a label defined.
215 // Simple test of the getLabel function against a store set that has a label defined.
217 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
219 var d = new doh.Deferred();
220 function onComplete(items, request){
221 t.assertEqual(items.length, 1);
222 var label = store.getLabel(items[0]);
223 t.assertTrue(label !== null);
224 t.assertEqual("Table Row #3", label);
227 function onError(error, request) {
230 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
233 function testReadAPI_getLabelAttributes(t){
235 // Simple test of the getLabelAttributes function against a store set that has a label defined.
237 // Simple test of the getLabelAttributes function against a store set that has a label defined.
239 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
241 var d = new doh.Deferred();
242 function onComplete(items, request){
243 t.assertEqual(items.length, 1);
244 var labelList = store.getLabelAttributes(items[0]);
245 t.assertTrue(labelList === null);
248 function onError(error, request) {
251 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
255 function testReadAPI_getValue(t){
257 // Simple test of the getValue API
259 // Simple test of the getValue API
260 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
262 var d = new doh.Deferred();
263 function onComplete(items, request) {
264 t.assertEqual(1, items.length);
266 t.assertTrue(store.hasAttribute(item,"isbn"));
267 t.assertEqual(store.getValue(item,"isbn"), "A9B574");
270 function onError(error, request) {
273 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
276 function testReadAPI_getValues(t){
278 // Simple test of the getValues API
280 // Simple test of the getValues API
281 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
283 var d = new doh.Deferred();
284 function onComplete(items, request) {
285 t.assertEqual(1, items.length);
287 t.assertTrue(store.hasAttribute(item,"isbn"));
288 var values = store.getValues(item,"isbn");
289 t.assertEqual(1,values.length);
290 t.assertEqual("A9B574", values[0]);
293 function onError(error, request) {
296 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
299 function testReadAPI_isItem(t){
301 // Simple test of the isItem API
303 // Simple test of the isItem API
304 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
306 var d = new doh.Deferred();
307 function onComplete(items, request) {
308 t.assertEqual(1, items.length);
310 t.assertTrue(store.isItem(item));
311 t.assertTrue(!store.isItem({}));
312 t.assertTrue(!store.isItem("Foo"));
313 t.assertTrue(!store.isItem(1));
316 function onError(error, request) {
319 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
322 function testReadAPI_isItem_multistore(t){
324 // Simple test of the isItem API across multiple store instances.
326 // Simple test of the isItem API across multiple store instances.
327 var store1 = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
328 var store2 = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
330 var d = new doh.Deferred();
331 function onComplete1(items, request) {
332 t.assertEqual(1, items.length);
333 var item1 = items[0];
334 t.assertTrue(store1.isItem(item1));
336 function onComplete2(items, request) {
337 t.assertEqual(1, items.length);
338 var item2 = items[0];
339 t.assertTrue(store2.isItem(item2));
340 t.assertTrue(!store1.isItem(item2));
341 t.assertTrue(!store2.isItem(item1));
344 store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError});
346 function onError(error, request) {
349 store1.fetch({query:{isbn:"1"}, onComplete: onComplete1, onError: onError});
352 function testReadAPI_hasAttribute(t){
354 // Simple test of the hasAttribute API
356 // Simple test of the hasAttribute API
357 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
359 var d = new doh.Deferred();
360 function onComplete(items, request) {
361 t.assertEqual(1, items.length);
363 t.assertTrue(store.hasAttribute(item,"isbn"));
364 t.assertTrue(!store.hasAttribute(item,"bob"));
367 function onError(error, request) {
370 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
373 function testReadAPI_containsValue(t){
375 // Simple test of the containsValue API
377 // Simple test of the containsValue API
378 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
380 var d = new doh.Deferred();
381 function onComplete(items, request) {
382 t.assertEqual(1, items.length);
384 t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
385 t.assertTrue(!store.containsValue(item,"isbn", "bob"));
388 function onError(error, request) {
391 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
394 function testReadAPI_sortDescending(t){
396 // Simple test of the sorting API in descending order.
398 // Simple test of the sorting API in descending order.
399 var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
401 //Comparison is done as a string type (toString comparison), so the order won't be numeric
402 //So have to compare in 'alphabetic' order.
403 var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1];
405 var d = new doh.Deferred();
406 function onComplete(items, request) {
407 t.assertEqual(20, items.length);
409 for(var i = 0; i < items.length; i++){
410 t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
414 function onError(error, request) {
418 var sortAttributes = [{attribute: "isbn", descending: true}];
419 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
422 function testReadAPI_sortAscending(t){
424 // Simple test of the sorting API in ascending order.
426 // Simple test of the sorting API in ascending order.
427 var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
429 //Comparison is done as a string type (toString comparison), so the order won't be numeric
430 //So have to compare in 'alphabetic' order.
431 var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9];
433 var d = new doh.Deferred();
434 function onComplete(items, request) {
435 t.assertEqual(20, items.length);
437 for(var i = 0; i < items.length; i++){
438 t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
442 function onError(error, request) {
446 var sortAttributes = [{attribute: "isbn"}];
447 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
450 function testReadAPI_sortDescendingNumeric(t){
452 // Simple test of the sorting API in descending order using a numeric comparator.
454 // Simple test of the sorting API in descending order using a numeric comparator.
455 var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
457 //isbn should be treated as a numeric, not as a string comparison
458 store.comparatorMap = {};
459 store.comparatorMap["isbn"] = function(a, b){
461 if(parseInt(a.toString()) > parseInt(b.toString())){
463 }else if(parseInt(a.toString()) < parseInt(b.toString())){
466 return ret; //int, {-1,0,1}
469 var d = new doh.Deferred();
470 function onComplete(items, request) {
471 t.assertEqual(20, items.length);
473 for(var i = 0; i < items.length; i++){
474 t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
479 function onError(error, request) {
483 var sortAttributes = [{attribute: "isbn", descending: true}];
484 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
487 function testReadAPI_sortAscendingNumeric(t){
489 // Simple test of the sorting API in ascending order using a numeric comparator.
491 // Simple test of the sorting API in ascending order using a numeric comparator.
492 var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
494 //isbn should be treated as a numeric, not as a string comparison
495 store.comparatorMap = {};
496 store.comparatorMap["isbn"] = function(a, b){
498 if(parseInt(a.toString()) > parseInt(b.toString())){
500 }else if(parseInt(a.toString()) < parseInt(b.toString())){
503 return ret; //int, {-1,0,1}
506 var d = new doh.Deferred();
507 function onComplete(items, request) {
508 t.assertEqual(20, items.length);
510 for(var i = 0; i < items.length; i++){
511 t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
516 function onError(error, request) {
520 var sortAttributes = [{attribute: "isbn"}];
521 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
524 function testReadAPI_isItemLoaded(t){
526 // Simple test of the isItemLoaded API
528 // Simple test of the isItemLoaded API
529 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
531 var d = new doh.Deferred();
532 function onComplete(items, request) {
533 t.assertEqual(1, items.length);
535 t.assertTrue(store.isItemLoaded(item));
538 function onError(error, request) {
541 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
544 function testReadAPI_getFeatures(t){
546 // Simple test of the getFeatures function of the store
548 // Simple test of the getFeatures function of the store
550 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
551 var features = store.getFeatures();
554 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
557 t.assertEqual(2, count);
559 function testReadAPI_getAttributes(t){
561 // Simple test of the getAttributes API
563 // Simple test of the getAttributes API
564 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
566 var d = new doh.Deferred();
567 function onComplete(items, request) {
568 t.assertEqual(1, items.length);
570 var attributes = store.getAttributes(item);
571 t.assertEqual(3,attributes.length);
572 for(var i=0; i<attributes.length; i++){
573 t.assertTrue((attributes[i] === "isbn" || attributes[i] === "title" || attributes[i] === "author"));
577 function onError(error, request) {
580 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
583 function testReadAPI_functionConformance(t){
585 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
587 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
589 var testStore = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
590 var readApi = new dojo.data.api.Read();
594 var member = readApi[i];
595 //Check that all the 'Read' defined functions exist on the test store.
596 if(typeof member === "function"){
597 var testStoreMember = testStore[i];
598 if(!(typeof testStoreMember === "function")){
599 console.log("Problem with function: [" + i + "]");
605 t.assertTrue(passed);
607 /***************************************
608 dojo.data.api.Identity API
609 ***************************************/
610 function testIdentityAPI_getIdentity(t){
612 // Simple test of the getAttributes API
614 // Simple test of the getAttributes API
615 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
617 var d = new doh.Deferred();
618 function onComplete(items, request) {
619 t.assertEqual(1, items.length);
621 t.assertEqual(3,store.getIdentity(item));
624 function onError(error, request) {
627 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
630 function testIdentityAPI_getIdentityAttributes(t){
632 // Simple test of the getAttributes API
634 // Simple test of the getAttributes API
635 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
637 var d = new doh.Deferred();
638 function onComplete(items, request) {
639 t.assertEqual(1, items.length);
641 //Should have none, as it's not a public attribute.
642 var attributes = store.getIdentityAttributes(item);
643 t.assertEqual(null, attributes);
646 function onError(error, request) {
649 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
652 function testIdentityAPI_fetchItemByIdentity(t){
654 // Simple test of the fetchItemByIdentity API
656 // Simple test of the fetchItemByIdentity API
657 var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
659 var d = new doh.Deferred();
660 function onItem(item, request) {
661 t.assertTrue(item !== null);
662 t.assertTrue(store.isItem(item));
663 t.assertEqual("A9B574", store.getValue(item, "isbn"));
666 function onError(error, request) {
669 store.fetchItemByIdentity({identity: 3, onItem: onItem, onError: onError});
672 function testIdentityAPI_functionConformance(t){
674 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
676 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
678 var testStore = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
679 var identityApi = new dojo.data.api.Identity();
682 for(i in identityApi){
683 var member = identityApi[i];
684 //Check that all the 'Read' defined functions exist on the test store.
685 if(typeof member === "function"){
686 var testStoreMember = testStore[i];
687 if(!(typeof testStoreMember === "function")){
688 console.log("Problem with function: [" + i + "]");
694 t.assertTrue(passed);
699 //Register the remote tests ... when they work.
700 //doh.registerUrl("dojox.data.tests.stores.HtmlTableStore.remote", dojo.moduleUrl("dojox.data.tests", "ml/test_HtmlTableStore_declaratively.html"));