1 if(!dojo._hasResource["dojox.data.tests.stores.OpmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.OpmlStore"] = true;
3 dojo.provide("dojox.data.tests.stores.OpmlStore");
4 dojo.require("dojox.data.OpmlStore");
5 dojo.require("dojo.data.api.Read");
7 dojox.data.tests.stores.OpmlStore.getDatasource = function(filepath){
9 // A simple helper function for getting the sample data used in each of the tests.
11 // A simple helper function for getting the sample data used in each of the tests.
15 dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
17 // When running tests in Rhino, xhrGet is not available,
18 // so we have the file data in the code below.
20 case "stores/geography.xml":
22 opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
23 opmlData += ' <opml version="1.0">\n';
24 opmlData += ' <head>\n';
25 opmlData += ' <title>geography.opml</title>\n';
26 opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
27 opmlData += ' <dateModified>2006-11-13</dateModified>\n';
28 opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
29 opmlData += ' </head>\n';
30 opmlData += ' <body>\n';
31 opmlData += ' <outline text="Africa" type="continent">\n';
32 opmlData += ' <outline text="Egypt" type="country"/>\n';
33 opmlData += ' <outline text="Kenya" type="country">\n';
34 opmlData += ' <outline text="Nairobi" type="city"/>\n';
35 opmlData += ' <outline text="Mombasa" type="city"/>\n';
36 opmlData += ' </outline>\n';
37 opmlData += ' <outline text="Sudan" type="country">\n';
38 opmlData += ' <outline text="Khartoum" type="city"/>\n';
39 opmlData += ' </outline>\n';
40 opmlData += ' </outline>\n';
41 opmlData += ' <outline text="Asia" type="continent">\n';
42 opmlData += ' <outline text="China" type="country"/>\n';
43 opmlData += ' <outline text="India" type="country"/>\n';
44 opmlData += ' <outline text="Russia" type="country"/>\n';
45 opmlData += ' <outline text="Mongolia" type="country"/>\n';
46 opmlData += ' </outline>\n';
47 opmlData += ' <outline text="Australia" type="continent" population="21 million">\n';
48 opmlData += ' <outline text="Australia" type="country" population="21 million"/>\n';
49 opmlData += ' </outline>\n';
50 opmlData += ' <outline text="Europe" type="continent">\n';
51 opmlData += ' <outline text="Germany" type="country"/>\n';
52 opmlData += ' <outline text="France" type="country"/>\n';
53 opmlData += ' <outline text="Spain" type="country"/>\n';
54 opmlData += ' <outline text="Italy" type="country"/>\n';
55 opmlData += ' </outline>\n';
56 opmlData += ' <outline text="North America" type="continent">\n';
57 opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n';
58 opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n';
59 opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n';
60 opmlData += ' </outline>\n';
61 opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n';
62 opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n';
63 opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n';
64 opmlData += ' </outline>\n';
65 opmlData += ' <outline text="United States of America" type="country"/>\n';
66 opmlData += ' </outline>\n';
67 opmlData += ' <outline text="South America" type="continent">\n';
68 opmlData += ' <outline text="Brazil" type="country" population="186 million"/>\n';
69 opmlData += ' <outline text="Argentina" type="country" population="40 million"/>\n';
70 opmlData += ' </outline>\n';
71 opmlData += ' </body>\n';
72 opmlData += ' </opml>\n';
74 case "stores/geography_withspeciallabel.xml":
76 opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
77 opmlData += '<opml version="1.0">\n';
78 opmlData += ' <head>\n';
79 opmlData += ' <title>geography.opml</title>\n';
80 opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
81 opmlData += ' <dateModified>2006-11-13</dateModified>\n';
82 opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
83 opmlData += ' </head>\n';
84 opmlData += ' <body>\n';
85 opmlData += ' <outline text="Africa" type="continent" label="Continent/Africa">\n';
86 opmlData += ' <outline text="Egypt" type="country" label="Country/Egypt"/>\n';
87 opmlData += ' <outline text="Kenya" type="country" label="Country/Kenya">\n';
88 opmlData += ' <outline text="Nairobi" type="city" label="City/Nairobi"/>\n';
89 opmlData += ' <outline text="Mombasa" type="city" label="City/Mombasa"/>\n';
90 opmlData += ' </outline>\n';
91 opmlData += ' <outline text="Sudan" type="country" label="Country/Sudan">\n';
92 opmlData += ' <outline text="Khartoum" type="city" label="City/Khartoum"/>\n';
93 opmlData += ' </outline>\n';
94 opmlData += ' </outline>\n';
95 opmlData += ' <outline text="Asia" type="continent" label="Continent/Asia">\n';
96 opmlData += ' <outline text="China" type="country" label="Country/China"/>\n';
97 opmlData += ' <outline text="India" type="country" label="Country/India"/>\n';
98 opmlData += ' <outline text="Russia" type="country" label="Country/Russia"/>\n';
99 opmlData += ' <outline text="Mongolia" type="country" label="Country/Mongolia"/>\n';
100 opmlData += ' </outline>\n';
101 opmlData += ' <outline text="Australia" type="continent" population="21 million" label="Continent/Australia">\n';
102 opmlData += ' <outline text="Australia" type="country" population="21 million" label="Country/Australia"/>\n';
103 opmlData += ' </outline>\n';
104 opmlData += ' <outline text="Europe" type="continent" label="Contintent/Europe">\n';
105 opmlData += ' <outline text="Germany" type="country" label="Country/Germany"/>\n';
106 opmlData += ' <outline text="France" type="country" label="Country/France"/>\n';
107 opmlData += ' <outline text="Spain" type="country" label="Country/Spain"/>\n';
108 opmlData += ' <outline text="Italy" type="country" label="Country/Italy"/>\n';
109 opmlData += ' </outline>\n';
110 opmlData += ' <outline text="North America" type="continent" label="Continent/North America">\n';
111 opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">\n';
112 opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>\n';
113 opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>\n';
114 opmlData += ' </outline>\n';
115 opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">\n';
116 opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>\n';
117 opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>\n';
118 opmlData += ' </outline>\n';
119 opmlData += ' <outline text="United States of America" type="country" label="Country/United States of America"/>\n';
120 opmlData += ' </outline>\n';
121 opmlData += ' <outline text="South America" type="continent" label="Continent/South America">\n';
122 opmlData += ' <outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>\n';
123 opmlData += ' <outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>\n';
124 opmlData += ' </outline>\n';
125 opmlData += ' </body>\n';
126 opmlData += '</opml>\n';
129 dataSource.data = opmlData;
131 return dataSource; //Object
134 dojox.data.tests.stores.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){
136 // A helper function for validating that the items array is ordered
137 // the same as the compareArray
138 if(items.length != compareArray.length){ return false; }
139 for(var i = 0; i < items.length; i++){
140 if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){
141 return false; //Boolean
144 return true; //Boolean
147 dojox.data.tests.stores.OpmlStore.error = function(t, d, errData){
149 // The error callback function to be used for all of the tests.
153 doh.register("dojox.data.tests.stores.OpmlStore",
155 function testReadAPI_fetch_all(t){
157 // Simple test of a basic fetch on OpmlStore.
159 // Simple test of a basic fetch on OpmlStore.
161 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
162 var opmlStore = new dojox.data.OpmlStore(args);
164 var d = new doh.Deferred();
165 function completedAll(items){
166 t.is(6, items.length);
171 opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
174 function testReadAPI_fetch_one(t){
176 // Simple test of a basic fetch on OpmlStore of a single item.
178 // Simple test of a basic fetch on OpmlStore of a single item.
180 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
181 var opmlStore = new dojox.data.OpmlStore(args);
183 var d = new doh.Deferred();
184 function onComplete(items, request){
185 t.is(1, items.length);
188 opmlStore.fetch({ query: {text: "Asia"},
189 onComplete: onComplete,
190 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
195 function testReadAPI_fetch_one_Multiple(t){
197 // Simple test of a basic fetch on OpmlStore of a single item.
199 // Simple test of a basic fetch on OpmlStore of a single item.
201 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
202 var opmlStore = new dojox.data.OpmlStore(args);
204 var d = new doh.Deferred();
205 var done = [false,false];
206 function onCompleteOne(items, request){
208 t.is(1, items.length);
209 if(done[0] && done[1]){
213 function onCompleteTwo(items, request){
215 t.is(1, items.length);
216 if(done[0] && done[1]){
221 opmlStore.fetch({ query: {text: "Asia"},
222 onComplete: onCompleteOne,
223 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
226 opmlStore.fetch({ query: {text: "North America"},
227 onComplete: onCompleteTwo,
228 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
234 function testReadAPI_fetch_one_MultipleMixed(t){
236 // Simple test of a basic fetch on OpmlStore of a single item mixing two fetch types.
238 // Simple test of a basic fetch on Cpmltore of a single item mixing two fetch types.
240 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
241 var opmlStore = new dojox.data.OpmlStore(args);
243 var d = new doh.Deferred();
245 var done = [false, false];
246 function onComplete(items, request){
248 t.is(1, items.length);
249 console.log("Found item: " + opmlStore.getValue(items[0],"text") + " with identity: " + opmlStore.getIdentity(items[0]));
250 t.is(0, opmlStore.getIdentity(items[0]));
251 if(done[0] && done[1]){
256 function onItem(item){
258 t.assertTrue(item !== null);
259 console.log("Found item: " + opmlStore.getValue(item,"text"));
260 t.is('Egypt', opmlStore.getValue(item,"text")); //Should be the second node parsed, ergo id 1, first node is id 0.
261 t.is(1, opmlStore.getIdentity(item));
262 if(done[0] && done[1]){
267 opmlStore.fetch({ query: {text: "Africa"},
268 onComplete: onComplete,
269 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
272 opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
277 function testReadAPI_fetch_one_deep(t){
279 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
281 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
283 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
284 var opmlStore = new dojox.data.OpmlStore(args);
286 var d = new doh.Deferred();
287 function onComplete(items, request){
288 t.is(1, items.length);
291 opmlStore.fetch({ query: {text: "Mexico City"},
292 queryOptions: {deep:true},
293 onComplete: onComplete,
294 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
299 function testReadAPI_fetch_one_deep_off(t){
301 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
303 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
305 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
306 var opmlStore = new dojox.data.OpmlStore(args);
308 var d = new doh.Deferred();
309 function onComplete(items, request){
310 //Nothing should be found.
311 t.is(0, items.length);
314 opmlStore.fetch({ query: {text: "Mexico City"},
315 onComplete: onComplete,
316 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
321 function testReadAPI_fetch_all_streaming(t){
323 // Simple test of a basic fetch on OpmlStore.
325 // Simple test of a basic fetch on OpmlStore.
327 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
328 var opmlStore = new dojox.data.OpmlStore(args);
330 var d = new doh.Deferred();
333 function onBegin(size, requestObj){
336 function onItem(item, requestObj){
337 t.assertTrue(opmlStore.isItem(item));
340 function onComplete(items, request){
347 opmlStore.fetch({ onBegin: onBegin,
349 onComplete: onComplete,
350 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
354 function testReadAPI_fetch_paging(t){
356 // Test of multiple fetches on a single result. Paging, if you will.
358 // Test of multiple fetches on a single result. Paging, if you will.
360 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
361 var opmlStore = new dojox.data.OpmlStore(args);
363 var d = new doh.Deferred();
364 function dumpFirstFetch(items, request){
365 t.is(5, items.length);
368 request.onComplete = dumpSecondFetch;
369 opmlStore.fetch(request);
372 function dumpSecondFetch(items, request){
373 t.is(1, items.length);
376 request.onComplete = dumpThirdFetch;
377 opmlStore.fetch(request);
380 function dumpThirdFetch(items, request){
381 t.is(5, items.length);
384 request.onComplete = dumpFourthFetch;
385 opmlStore.fetch(request);
388 function dumpFourthFetch(items, request){
389 t.is(4, items.length);
392 request.onComplete = dumpFifthFetch;
393 opmlStore.fetch(request);
396 function dumpFifthFetch(items, request){
397 t.is(0, items.length);
400 request.onComplete = dumpSixthFetch;
401 opmlStore.fetch(request);
404 function dumpSixthFetch(items, request){
405 t.is(4, items.length);
409 function completed(items, request){
410 t.is(6, items.length);
413 request.onComplete = dumpFirstFetch;
414 opmlStore.fetch(request);
417 opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
421 function testReadAPI_getLabel(t){
423 // Simple test of the getLabel function against a store set that has a label defined.
425 // Simple test of the getLabel function against a store set that has a label defined.
427 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
428 var opmlStore = new dojox.data.OpmlStore(args);
430 var d = new doh.Deferred();
431 function onComplete(items, request){
432 t.assertEqual(items.length, 1);
433 var label = opmlStore.getLabel(items[0]);
434 t.assertTrue(label !== null);
435 t.assertEqual("Asia", label);
438 opmlStore.fetch({ query: {text: "Asia"},
439 onComplete: onComplete,
440 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
444 function testReadAPI_getLabelAttributes(t){
446 // Simple test of the getLabelAttributes function against a store set that has a label defined.
448 // Simple test of the getLabelAttributes function against a store set that has a label defined.
450 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
451 var opmlStore = new dojox.data.OpmlStore(args);
453 var d = new doh.Deferred();
454 function onComplete(items, request){
455 t.assertEqual(items.length, 1);
456 var labelList = opmlStore.getLabelAttributes(items[0]);
457 t.assertTrue(dojo.isArray(labelList));
458 t.assertEqual("text", labelList[0]);
461 opmlStore.fetch({ query: {text: "Asia"},
462 onComplete: onComplete,
463 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
468 function testReadAPI_getLabel_nondefault(t){
470 // Simple test of the getLabel function against a store set that has a label defined.
472 // Simple test of the getLabel function against a store set that has a label defined.
474 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
476 var opmlStore = new dojox.data.OpmlStore(args);
478 var d = new doh.Deferred();
479 function onComplete(items, request){
480 t.assertEqual(items.length, 1);
481 var label = opmlStore.getLabel(items[0]);
482 t.assertTrue(label !== null);
483 t.assertEqual("Continent/Asia", label);
486 opmlStore.fetch({ query: {text: "Asia"},
487 onComplete: onComplete,
488 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
492 function testReadAPI_getLabelAttributes_nondefault(t){
494 // Simple test of the getLabelAttributes function against a store set that has a label defined.
496 // Simple test of the getLabelAttributes function against a store set that has a label defined.
498 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
500 var opmlStore = new dojox.data.OpmlStore(args);
502 var d = new doh.Deferred();
503 function onComplete(items, request){
504 t.assertEqual(items.length, 1);
505 var labelList = opmlStore.getLabelAttributes(items[0]);
506 t.assertTrue(dojo.isArray(labelList));
507 t.assertEqual("label", labelList[0]);
510 opmlStore.fetch({ query: {text: "Asia"},
511 onComplete: onComplete,
512 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
517 function testReadAPI_getValue(t){
519 // Simple test of the getValue function of the store.
521 // Simple test of the getValue function of the store.
523 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
524 var opmlStore = new dojox.data.OpmlStore(args);
526 var d = new doh.Deferred();
527 function completedAll(items){
528 t.is(6, items.length);
530 t.is("Africa", opmlStore.getValue(items[0],"text"));
531 t.is("Asia", opmlStore.getValue(items[1],"text"));
532 t.is("Australia", opmlStore.getValue(items[2],"text"));
533 t.is("Europe", opmlStore.getValue(items[3],"text"));
534 t.is("North America", opmlStore.getValue(items[4],"text"));
535 t.is("South America", opmlStore.getValue(items[5],"text"));
537 t.is("continent", opmlStore.getValue(items[1],"type"));
538 t.is("21 million", opmlStore.getValue(items[2],"population"));
540 var firstChild = opmlStore.getValue(items[4],"children");
541 t.assertTrue(opmlStore.isItem(firstChild));
542 t.is("Mexico", opmlStore.getValue(firstChild,"text"));
543 t.is("country", opmlStore.getValue(firstChild,"type"));
544 t.is("108 million", opmlStore.getValue(firstChild,"population"));
545 t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area"));
547 firstChild = opmlStore.getValue(firstChild,"children");
548 t.assertTrue(opmlStore.isItem(firstChild));
549 t.is("Mexico City", opmlStore.getValue(firstChild,"text"));
550 t.is("city", opmlStore.getValue(firstChild,"type"));
551 t.is("19 million", opmlStore.getValue(firstChild,"population"));
552 t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone"));
558 opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
561 function testReadAPI_getValues(t){
563 // Simple test of the getValues function of the store.
565 // Simple test of the getValues function of the store.
567 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
568 var opmlStore = new dojox.data.OpmlStore(args);
570 var d = new doh.Deferred();
571 function completed(items){
572 t.is(1, items.length);
574 var children = opmlStore.getValues(items[0],"children");
575 t.is(3, children.length);
576 for(var i=0; i<children.length; i++){
577 t.assertTrue(opmlStore.isItem(children[i]));
580 t.is("Mexico", opmlStore.getValues(children[0],"text")[0]);
581 t.is("country", opmlStore.getValues(children[0],"type")[0]);
582 t.is("108 million", opmlStore.getValues(children[0],"population")[0]);
583 t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]);
585 t.is("Canada", opmlStore.getValues(children[1],"text")[0]);
586 t.is("country", opmlStore.getValues(children[1],"type")[0]);
588 children = opmlStore.getValues(children[1],"children");
589 t.is(2, children.length);
590 for(var i=0; i<children.length; i++){
591 t.assertTrue(opmlStore.isItem(children[i]));
593 t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]);
594 t.is("Toronto", opmlStore.getValues(children[1],"text")[0]);
600 opmlStore.fetch({ query: {text: "North America"},
601 onComplete: completed,
602 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
605 function testReadAPI_isItem(t){
607 // Simple test of the isItem function of the store
609 // Simple test of the isItem function of the store
611 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
612 var opmlStore = new dojox.data.OpmlStore(args);
614 var d = new doh.Deferred();
615 function completedAll(items){
616 t.is(6, items.length);
617 for(var i=0; i<6; i++){
618 t.assertTrue(opmlStore.isItem(items[i]));
620 t.assertTrue(!opmlStore.isItem({}));
621 t.assertTrue(!opmlStore.isItem({ item: "not an item" }));
622 t.assertTrue(!opmlStore.isItem("not an item"));
623 t.assertTrue(!opmlStore.isItem(["not an item"]));
629 opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
632 function testReadAPI_hasAttribute(t){
634 // Simple test of the hasAttribute function of the store
636 // Simple test of the hasAttribute function of the store
638 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
639 var opmlStore = new dojox.data.OpmlStore(args);
641 var d = new doh.Deferred();
642 function onComplete(items){
643 t.is(1, items.length);
644 t.assertTrue(items[0] !== null);
645 t.assertTrue(opmlStore.hasAttribute(items[0], "text"));
646 t.assertTrue(opmlStore.hasAttribute(items[0], "type"));
647 t.assertTrue(!opmlStore.hasAttribute(items[0], "population"));
648 t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing"));
649 t.assertTrue(!opmlStore.hasAttribute(items[0], "Text"));
651 //Test that null attributes throw an exception
654 opmlStore.hasAttribute(items[0], null);
658 t.assertTrue(passed);
664 opmlStore.fetch({ query: {text: "Asia"},
665 onComplete: onComplete,
666 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
670 function testReadAPI_containsValue(t){
672 // Simple test of the containsValue function of the store
674 // Simple test of the containsValue function of the store
676 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
677 var opmlStore = new dojox.data.OpmlStore(args);
679 var d = new doh.Deferred();
680 function onComplete(items){
681 t.is(1, items.length);
682 t.assertTrue(items[0] !== null);
683 t.assertTrue(opmlStore.containsValue(items[0], "text", "North America"));
684 t.assertTrue(opmlStore.containsValue(items[0], "type", "continent"));
685 t.assertTrue(!opmlStore.containsValue(items[0], "text", "America"));
686 t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent"));
687 t.assertTrue(!opmlStore.containsValue(items[0], "text", null));
689 var children = opmlStore.getValues(items[0], "children");
690 t.assertTrue(opmlStore.containsValue(items[0], "children", children[0]));
691 t.assertTrue(opmlStore.containsValue(items[0], "children", children[1]));
692 t.assertTrue(opmlStore.containsValue(items[0], "children", children[2]));
694 //Test that null attributes throw an exception
697 opmlStore.containsValue(items[0], null, "foo");
701 t.assertTrue(passed);
707 opmlStore.fetch({ query: {text: "North America"},
708 onComplete: onComplete,
709 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
713 function testReadAPI_getAttributes(t){
715 // Simple test of the getAttributes function of the store
717 // Simple test of the getAttributes function of the store
719 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
720 var opmlStore = new dojox.data.OpmlStore(args);
722 var d = new doh.Deferred();
723 function onComplete(items){
724 t.is(6, items.length);
725 t.assertTrue(opmlStore.isItem(items[0]));
727 var attributes = opmlStore.getAttributes(items[0]);
728 t.is(3, attributes.length);
729 for(var i = 0; i < attributes.length; i++){
730 t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children"));
737 opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
740 function testReadAPI_getFeatures(t){
742 // Simple test of the getFeatures function of the store
744 // Simple test of the getFeatures function of the store
746 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
747 var opmlStore = new dojox.data.OpmlStore(args);
749 var features = opmlStore.getFeatures();
752 t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity"));
755 t.assertTrue(count === 2);
757 function testReadAPI_fetch_patternMatch0(t){
759 // Function to test pattern matching of everything starting with Capital A
761 // Function to test pattern matching of everything starting with Capital A
763 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
764 var opmlStore = new dojox.data.OpmlStore(args);
766 var d = new doh.Deferred();
767 function completed(items, request){
768 t.is(3, items.length);
769 var valueArray = [ "Africa", "Asia", "Australia"];
770 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
774 opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
777 function testReadAPI_fetch_patternMatch1(t){
779 // Function to test pattern matching of everything with America in it.
781 // Function to test pattern matching of everything with America in it.
783 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
784 var opmlStore = new dojox.data.OpmlStore(args);
786 var d = new doh.Deferred();
787 function completed(items, request){
788 t.assertTrue(items.length === 2);
789 var valueArray = [ "North America", "South America"];
790 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
794 opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
797 function testReadAPI_fetch_patternMatch2(t){
799 // Function to test exact pattern match
801 // Function to test exact pattern match
803 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
804 var opmlStore = new dojox.data.OpmlStore(args);
806 var d = new doh.Deferred();
807 function completed(items, request){
808 t.is(1, items.length);
809 t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe");
813 opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
816 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
818 // Function to test exact pattern match with case insensitivity set.
820 // Function to test exact pattern match with case insensitivity set.
822 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
823 var opmlStore = new dojox.data.OpmlStore(args);
825 var d = new doh.Deferred();
826 function completed(items, request){
827 t.is(1, items.length);
828 t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia");
832 opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
835 function testReadAPI_fetch_patternMatch_caseSensitive(t){
837 // Function to test exact pattern match with case sensitivity set.
839 // Function to test exact pattern match with case sensitivity set.
841 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
842 var opmlStore = new dojox.data.OpmlStore(args);
844 var d = new doh.Deferred();
845 function completed(items, request){
846 t.is(0, items.length);
850 opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
853 function testReadAPI_fetch_sortAlphabetic(t){
855 // Function to test sorting alphabetic ordering.
857 // Function to test sorting alphabetic ordering.
859 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
860 var opmlStore = new dojox.data.OpmlStore(args);
862 var d = new doh.Deferred();
863 function completed(items, request){
864 //Output should be in this order...
865 var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"];
866 t.is(6, items.length);
867 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
871 var sortAttributes = [{attribute: "text"}];
872 opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
875 function testReadAPI_fetch_sortAlphabeticDescending(t){
877 // Function to test sorting alphabetic ordering in descending mode.
879 // Function to test sorting alphabetic ordering in descending mode.
881 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
882 var opmlStore = new dojox.data.OpmlStore(args);
884 var d = new doh.Deferred();
885 function completed(items, request){
886 //Output should be in this order...
887 var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa"
889 t.is(6, items.length);
890 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
894 var sortAttributes = [{attribute: "text", descending: true}];
895 opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
898 function testReadAPI_fetch_sortAlphabeticWithCount(t){
900 // Function to test sorting numerically in descending order, returning only a specified number of them.
902 // Function to test sorting numerically in descending order, returning only a specified number of them.
904 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
905 var opmlStore = new dojox.data.OpmlStore(args);
907 var d = new doh.Deferred();
908 function completed(items, request){
909 //Output should be in this order...
910 var orderedArray = [ "South America", "North America", "Europe", "Australia"
912 t.is(4, items.length);
913 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
917 var sortAttributes = [{attribute: "text", descending: true}];
918 opmlStore.fetch({sort: sortAttributes,
920 onComplete: completed,
921 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
924 function testReadAPI_functionConformance(t){
926 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
928 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
930 var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));
931 var readApi = new dojo.data.api.Read();
935 if(i.toString().charAt(0) !== '_')
937 var member = readApi[i];
938 //Check that all the 'Read' defined functions exist on the test store.
939 if(typeof member === "function"){
940 var testStoreMember = testStore[i];
941 if(!(typeof testStoreMember === "function")){
948 t.assertTrue(passed);
950 function testIdentityAPI_fetchItemByIdentity(t){
952 // Simple test of the fetchItemByIdentity function of the store.
954 // Simple test of the fetchItemByIdentity function of the store.
956 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
957 var opmlStore = new dojox.data.OpmlStore(args);
959 var d = new doh.Deferred();
960 function onItem(item){
961 t.assertTrue(item !== null);
964 opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
968 function testIdentityAPI_fetchItemByIdentity_bad1(t){
970 // Simple test of the fetchItemByIdentity function of the store.
972 // Simple test of the fetchItemByIdentity function of the store.
974 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
975 var opmlStore = new dojox.data.OpmlStore(args);
977 var d = new doh.Deferred();
978 function onItem(item){
979 t.assertTrue(item === null);
982 opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
985 function testIdentityAPI_fetchItemByIdentity_bad2(t){
987 // Simple test of the fetchItemByIdentity function of the store.
989 // Simple test of the fetchItemByIdentity function of the store.
991 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
992 var opmlStore = new dojox.data.OpmlStore(args);
993 var d = new doh.Deferred();
994 function onItem(item){
995 t.assertTrue(item === null);
998 opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
1001 function testIdentityAPI_fetchItemByIdentity_bad3(t){
1003 // Simple test of the fetchItemByIdentity function of the store.
1005 // Simple test of the fetchItemByIdentity function of the store.
1007 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
1008 var opmlStore = new dojox.data.OpmlStore(args);
1009 var d = new doh.Deferred();
1010 function onItem(item){
1011 t.assertTrue(item === null);
1014 opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
1017 function testIdentityAPI_getIdentity(t){
1019 // Simple test of the fetchItemByIdentity function of the store.
1021 // Simple test of the fetchItemByIdentity function of the store.
1023 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
1024 var opmlStore = new dojox.data.OpmlStore(args);
1026 var d = new doh.Deferred();
1027 function completed(items, request){
1029 for(var i = 0; i < items.length; i++){
1030 console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i);
1031 if(!(opmlStore.getIdentity(items[i]) == i)){
1036 t.assertTrue(passed);
1041 opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}});
1044 function testIdentityAPI_functionConformance(t){
1046 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
1048 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
1050 var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/geography.xml"));
1051 var identityApi = new dojo.data.api.Identity();
1054 for(i in identityApi){
1055 if(i.toString().charAt(0) !== '_')
1057 var member = identityApi[i];
1058 //Check that all the 'Read' defined functions exist on the test store.
1059 if(typeof member === "function"){
1060 console.log("Looking at function: [" + i + "]");
1061 var testStoreMember = testStore[i];
1062 if(!(typeof testStoreMember === "function")){
1069 t.assertTrue(passed);