1 if(!dojo._hasResource["dojox.data.tests.stores.CsvStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.CsvStore"] = true;
3 dojo.provide("dojox.data.tests.stores.CsvStore");
4 dojo.require("dojox.data.CsvStore");
5 dojo.require("dojo.data.api.Read");
6 dojo.require("dojo.data.api.Identity");
8 dojox.data.tests.stores.CsvStore.getDatasource = function(filepath){
10 // A simple helper function for getting the sample data used in each of the tests.
12 // A simple helper function for getting the sample data used in each of the tests.
16 dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
18 // When running tests in Rhino, xhrGet is not available,
19 // so we have the file data in the code below.
21 case "stores/movies.csv":
23 csvData += "Title, Year, Producer\n";
24 csvData += "City of God, 2002, Katia Lund\n";
25 csvData += "Rain,, Christine Jeffs\n";
26 csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
27 csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
28 csvData += "Alien, 1979 , Ridley Scott\n";
29 csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
30 csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
32 case "stores/movies2.csv":
34 csvData += "Title, Year, Producer\n";
35 csvData += "City of God, 2002, Katia Lund\n";
36 csvData += "Rain,\"\", Christine Jeffs\n";
37 csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
38 csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
39 csvData += "Alien, 1979 , Ridley Scott\n";
40 csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
41 csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
43 case "stores/books.csv":
45 csvData += "Title, Author\n";
46 csvData += "The Transparent Society, David Brin\n";
47 csvData += "The First Measured Century, Theodore Caplow\n";
48 csvData += "Maps in a Mirror, Orson Scott Card\n";
49 csvData += "Princess Smartypants, Babette Cole\n";
50 csvData += "Carfree Cities, Crawford J.H.\n";
51 csvData += "Down and Out in the Magic Kingdom, Cory Doctorow\n";
52 csvData += "Tax Shift, Alan Thein Durning\n";
53 csvData += "The Sneetches and other stories, Dr. Seuss\n";
54 csvData += "News from Tartary, Peter Fleming\n";
56 case "stores/patterns.csv":
58 csvData += "uniqueId, value\n";
59 csvData += "9, jfq4@#!$!@Rf14r14i5u\n";
60 csvData += "6, BaBaMaSaRa***Foo\n";
61 csvData += "2, bar*foo\n";
62 csvData += "8, 123abc\n";
63 csvData += "4, bit$Bite\n";
64 csvData += "3, 123abc\n";
65 csvData += "10, 123abcdefg\n";
66 csvData += "1, foo*bar\n";
68 csvData += "5, 123abc\n"
71 dataSource.data = csvData;
73 return dataSource; //Object
76 dojox.data.tests.stores.CsvStore.verifyItems = function(csvStore, items, attribute, compareArray){
78 // A helper function for validating that the items array is ordered
79 // the same as the compareArray
80 if(items.length != compareArray.length){ return false; }
81 for(var i = 0; i < items.length; i++){
82 if(!(csvStore.getValue(items[i], attribute) === compareArray[i])){
83 return false; //Boolean
86 return true; //Boolean
89 dojox.data.tests.stores.CsvStore.error = function(t, d, errData){
91 // The error callback function to be used for all of the tests.
93 console.log(errData[i]);
98 doh.register("dojox.data.tests.stores.CsvStore",
100 function testReadAPI_fetch_all(t){
102 // Simple test of a basic fetch on CsvStore.
104 // Simple test of a basic fetch on CsvStore.
106 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
107 var csvStore = new dojox.data.CsvStore(args);
109 var d = new doh.Deferred();
110 function completedAll(items){
111 t.assertTrue((items.length === 7));
116 csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
119 function testReadAPI_fetch_all_withEmptyStringField(t){
121 // Simple test of a basic fetch on CsvStore.
123 // Simple test of a basic fetch on CsvStore.
125 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies2.csv");
126 var csvStore = new dojox.data.CsvStore(args);
128 var d = new doh.Deferred();
129 function completedAll(items){
130 t.assertTrue((items.length === 7));
135 csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
138 function testReadAPI_fetch_one(t){
140 // Simple test of a basic fetch on CsvStore of a single item.
142 // Simple test of a basic fetch on CsvStore of a single item.
144 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
145 var csvStore = new dojox.data.CsvStore(args);
147 var d = new doh.Deferred();
148 function onComplete(items, request){
149 t.is(1, items.length);
152 csvStore.fetch({ query: {Title: "*Sequel*"},
153 onComplete: onComplete,
154 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
158 function testReadAPI_fetch_Multiple(t){
160 // Simple test of a basic fetch on CsvStore of a single item.
162 // Simple test of a basic fetch on CsvStore of a single item.
164 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
165 var csvStore = new dojox.data.CsvStore(args);
167 var d = new doh.Deferred();
169 var done = [false, false];
171 function onCompleteOne(items, request){
173 t.is(1, items.length);
174 if(done[0] && done[1]){
179 function onCompleteTwo(items, request){
181 t.is(1, items.length);
182 if(done[0] && done[1]){
189 csvStore.fetch({ query: {Title: "*Sequel*"},
190 onComplete: onCompleteOne,
191 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
193 csvStore.fetch({ query: {Title: "2001:*"},
194 onComplete: onCompleteTwo,
195 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
207 function testReadAPI_fetch_MultipleMixed(t){
209 // Simple test of a basic fetch on CsvStore of a single item.
211 // Simple test of a basic fetch on CsvStore of a single item.
213 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
214 var csvStore = new dojox.data.CsvStore(args);
216 var d = new doh.Deferred();
218 var done = [false, false];
219 function onComplete(items, request){
221 t.is(1, items.length);
222 if(done[0] && done[1]){
227 function onItem(item){
229 t.assertTrue(item !== null);
230 t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
231 t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
232 if(done[0] && done[1]){
237 csvStore.fetch({ query: {Title: "*Sequel*"},
238 onComplete: onComplete,
239 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
242 csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
245 function testReadAPI_fetch_all_streaming(t){
247 // Simple test of a basic fetch on CsvStore.
249 // Simple test of a basic fetch on CsvStore.
251 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
252 var csvStore = new dojox.data.CsvStore(args);
254 var d = new doh.Deferred();
257 function onBegin(size, requestObj){
258 t.assertTrue(size === 7);
260 function onItem(item, requestObj){
261 t.assertTrue(csvStore.isItem(item));
264 function onComplete(items, request){
271 csvStore.fetch({ onBegin: onBegin,
273 onComplete: onComplete,
274 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
278 function testReadAPI_fetch_paging(t){
280 // Test of multiple fetches on a single result. Paging, if you will.
282 // Test of multiple fetches on a single result. Paging, if you will.
284 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
285 var csvStore = new dojox.data.CsvStore(args);
287 var d = new doh.Deferred();
288 function dumpFirstFetch(items, request){
289 t.is(5, items.length);
292 request.onComplete = dumpSecondFetch;
293 csvStore.fetch(request);
296 function dumpSecondFetch(items, request){
297 t.is(1, items.length);
300 request.onComplete = dumpThirdFetch;
301 csvStore.fetch(request);
304 function dumpThirdFetch(items, request){
305 t.is(5, items.length);
308 request.onComplete = dumpFourthFetch;
309 csvStore.fetch(request);
312 function dumpFourthFetch(items, request){
313 t.is(5, items.length);
316 request.onComplete = dumpFifthFetch;
317 csvStore.fetch(request);
320 function dumpFifthFetch(items, request){
321 t.is(0, items.length);
324 request.onComplete = dumpSixthFetch;
325 csvStore.fetch(request);
328 function dumpSixthFetch(items, request){
329 t.is(5, items.length);
333 function completed(items, request){
334 t.is(7, items.length);
337 request.onComplete = dumpFirstFetch;
338 csvStore.fetch(request);
341 csvStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
346 function testReadAPI_getLabel(t){
348 // Simple test of the getLabel function against a store set that has a label defined.
350 // Simple test of the getLabel function against a store set that has a label defined.
352 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
353 args.label = "Title";
354 var csvStore = new dojox.data.CsvStore(args);
356 var d = new doh.Deferred();
357 function onComplete(items, request){
358 t.assertEqual(items.length, 1);
359 var label = csvStore.getLabel(items[0]);
360 t.assertTrue(label !== null);
361 t.assertEqual("The Sequel to \"Dances With Wolves.\"", label);
364 csvStore.fetch({ query: {Title: "*Sequel*"},
365 onComplete: onComplete,
366 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
370 function testReadAPI_getLabelAttributes(t){
372 // Simple test of the getLabelAttributes function against a store set that has a label defined.
374 // Simple test of the getLabelAttributes function against a store set that has a label defined.
376 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
377 args.label = "Title";
378 var csvStore = new dojox.data.CsvStore(args);
380 var d = new doh.Deferred();
381 function onComplete(items, request){
382 t.assertEqual(items.length, 1);
383 var labelList = csvStore.getLabelAttributes(items[0]);
384 t.assertTrue(dojo.isArray(labelList));
385 t.assertEqual("Title", labelList[0]);
388 csvStore.fetch({ query: {Title: "*Sequel*"},
389 onComplete: onComplete,
390 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
394 function testReadAPI_getValue(t){
396 // Simple test of the getValue function of the store.
398 // Simple test of the getValue function of the store.
400 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
401 var csvStore = new dojox.data.CsvStore(args);
403 var d = new doh.Deferred();
404 function onItem(item){
405 t.assertTrue(item !== null);
406 t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
407 t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
410 csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
413 function testReadAPI_getValue_2(t){
415 // Simple test of the getValue function of the store.
417 // Simple test of the getValue function of the store.
419 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
420 var csvStore = new dojox.data.CsvStore(args);
422 var d = new doh.Deferred();
423 function onItem(item){
424 t.assertTrue(item !== null);
425 t.is("City of God", csvStore.getValue(item,"Title"));
426 t.is("2002", csvStore.getValue(item,"Year"));
429 csvStore.fetchItemByIdentity({identity: "0", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
432 function testReadAPI_getValue_3(t){
434 // Simple test of the getValue function of the store.
436 // Simple test of the getValue function of the store.
438 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
439 var csvStore = new dojox.data.CsvStore(args);
441 var d = new doh.Deferred();
442 function onItem(item){
443 t.assertTrue(item !== null);
444 t.is("1979", csvStore.getValue(item,"Year"));
445 t.is("Alien", csvStore.getValue(item,"Title"));
448 csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
451 function testReadAPI_getValue_4(t){
453 // Simple test of the getValue function of the store.
455 // Simple test of the getValue function of the store.
457 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
458 var csvStore = new dojox.data.CsvStore(args);
460 var d = new doh.Deferred();
461 function onItem(item){
462 t.assertTrue(item !== null);
463 t.is("2001: A Space Odyssey", csvStore.getValue(item,"Title"));
464 t.is("Stanley Kubrick", csvStore.getValue(item,"Producer"));
467 csvStore.fetchItemByIdentity({identity: "2", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
471 function testReadAPI_getValues(t){
473 // Simple test of the getValues function of the store.
475 // Simple test of the getValues function of the store.
477 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
478 var csvStore = new dojox.data.CsvStore(args);
480 var d = new doh.Deferred();
481 function onItem(item){
482 t.assertTrue(item !== null);
483 var names = csvStore.getValues(item,"Title");
484 t.assertTrue(dojo.isArray(names));
485 t.is(1, names.length);
486 t.is("Rain", names[0]);
489 csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
492 function testIdentityAPI_fetchItemByIdentity(t){
494 // Simple test of the fetchItemByIdentity function of the store.
496 // Simple test of the fetchItemByIdentity function of the store.
498 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
499 var csvStore = new dojox.data.CsvStore(args);
501 var d = new doh.Deferred();
502 function onItem(item){
503 t.assertTrue(item !== null);
506 csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
510 function testIdentityAPI_fetchItemByIdentity_bad1(t){
512 // Simple test of the fetchItemByIdentity function of the store.
514 // Simple test of the fetchItemByIdentity function of the store.
516 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
517 var csvStore = new dojox.data.CsvStore(args);
519 var d = new doh.Deferred();
520 function onItem(item){
521 t.assertTrue(item === null);
524 csvStore.fetchItemByIdentity({identity: "7", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
527 function testIdentityAPI_fetchItemByIdentity_bad2(t){
529 // Simple test of the fetchItemByIdentity function of the store.
531 // Simple test of the fetchItemByIdentity function of the store.
533 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
534 var csvStore = new dojox.data.CsvStore(args);
535 var d = new doh.Deferred();
536 function onItem(item){
537 t.assertTrue(item === null);
540 csvStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
543 function testIdentityAPI_fetchItemByIdentity_bad3(t){
545 // Simple test of the fetchItemByIdentity function of the store.
547 // Simple test of the fetchItemByIdentity function of the store.
549 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
550 var csvStore = new dojox.data.CsvStore(args);
551 var d = new doh.Deferred();
552 function onItem(item){
553 t.assertTrue(item === null);
556 csvStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
559 function testIdentityAPI_getIdentity(t){
561 // Simple test of the fetchItemByIdentity function of the store.
563 // Simple test of the fetchItemByIdentity function of the store.
565 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
566 var csvStore = new dojox.data.CsvStore(args);
568 var d = new doh.Deferred();
569 function completed(items, request){
570 t.is(7, items.length);
572 for(var i = 0; i < items.length; i++){
573 if(!(csvStore.getIdentity(items[i]) === i)){
578 t.assertTrue(passed);
583 csvStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
586 function testIdentityAPI_getIdentityAttributes(t){
588 // Simple test of the getIdentityAttributes
590 // Simple test of the fetchItemByIdentity function of the store.
592 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
593 var csvStore = new dojox.data.CsvStore(args);
595 var d = new doh.Deferred();
596 function onItem(item){
597 t.assertTrue(csvStore.isItem(item));
598 t.assertEqual(null, csvStore.getIdentityAttributes(item));
601 csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
604 function testReadAPI_isItem(t){
606 // Simple test of the isItem function of the store
608 // Simple test of the isItem function of the store
610 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
611 var csvStore = new dojox.data.CsvStore(args);
613 var d = new doh.Deferred();
614 function onItem(item){
615 t.assertTrue(csvStore.isItem(item));
616 t.assertTrue(!csvStore.isItem({}));
617 t.assertTrue(!csvStore.isItem({ item: "not an item" }));
618 t.assertTrue(!csvStore.isItem("not an item"));
619 t.assertTrue(!csvStore.isItem(["not an item"]));
622 csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
625 function testReadAPI_hasAttribute(t){
627 // Simple test of the hasAttribute function of the store
629 // Simple test of the hasAttribute function of the store
631 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
632 var csvStore = new dojox.data.CsvStore(args);
634 var d = new doh.Deferred();
635 function onItem(item){
636 t.assertTrue(item !== null);
637 t.assertTrue(csvStore.hasAttribute(item, "Title"));
638 t.assertTrue(csvStore.hasAttribute(item, "Producer"));
639 t.assertTrue(!csvStore.hasAttribute(item, "Year"));
640 t.assertTrue(!csvStore.hasAttribute(item, "Nothing"));
641 t.assertTrue(!csvStore.hasAttribute(item, "title"));
643 //Test that null attributes throw an exception
646 csvStore.hasAttribute(item, null);
650 t.assertTrue(passed);
653 csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
656 function testReadAPI_containsValue(t){
658 // Simple test of the containsValue function of the store
660 // Simple test of the containsValue function of the store
662 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
663 var csvStore = new dojox.data.CsvStore(args);
665 var d = new doh.Deferred();
666 function onItem(item){
667 t.assertTrue(item !== null);
668 t.assertTrue(csvStore.containsValue(item, "Title", "Alien"));
669 t.assertTrue(csvStore.containsValue(item, "Year", "1979"));
670 t.assertTrue(csvStore.containsValue(item, "Producer", "Ridley Scott"));
671 t.assertTrue(!csvStore.containsValue(item, "Title", "Alien2"));
672 t.assertTrue(!csvStore.containsValue(item, "Year", "1979 "));
673 t.assertTrue(!csvStore.containsValue(item, "Title", null));
675 //Test that null attributes throw an exception
678 csvStore.containsValue(item, null, "foo");
682 t.assertTrue(passed);
685 csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
688 function testReadAPI_getAttributes(t){
690 // Simple test of the getAttributes function of the store
692 // Simple test of the getAttributes function of the store
694 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
695 var csvStore = new dojox.data.CsvStore(args);
697 var d = new doh.Deferred();
698 function onItem(item){
699 t.assertTrue(item !== null);
700 t.assertTrue(csvStore.isItem(item));
702 var attributes = csvStore.getAttributes(item);
703 t.is(3, attributes.length);
704 for(var i = 0; i < attributes.length; i++){
705 t.assertTrue((attributes[i] === "Title" || attributes[i] === "Year" || attributes[i] === "Producer"));
709 csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
713 function testReadAPI_getAttributes_onlyTwo(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.CsvStore.getDatasource("stores/movies.csv");
720 var csvStore = new dojox.data.CsvStore(args);
722 var d = new doh.Deferred();
723 function onItem(item){
724 // Test an item that does not have all of the attributes
725 t.assertTrue(item !== null);
726 t.assertTrue(csvStore.isItem(item));
728 var attributes = csvStore.getAttributes(item);
729 t.assertTrue(attributes.length === 2);
730 t.assertTrue(attributes[0] === "Title");
731 t.assertTrue(attributes[1] === "Producer");
734 csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
738 function testReadAPI_getFeatures(t){
740 // Simple test of the getFeatures function of the store
742 // Simple test of the getFeatures function of the store
744 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
745 var csvStore = new dojox.data.CsvStore(args);
747 var features = csvStore.getFeatures();
750 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
753 t.assertTrue(count === 2);
755 function testReadAPI_fetch_patternMatch0(t){
757 // Function to test pattern matching of everything starting with lowercase e
759 // Function to test pattern matching of everything starting with lowercase e
761 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
762 var csvStore = new dojox.data.CsvStore(args);
764 var d = new doh.Deferred();
765 function completed(items, request){
766 t.is(2, items.length);
767 var valueArray = [ "Alien", "The Sequel to \"Dances With Wolves.\""];
768 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "Title", valueArray));
772 csvStore.fetch({query: {Producer: "* Scott"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
775 function testReadAPI_fetch_patternMatch1(t){
777 // Function to test pattern matching of everything with $ in it.
779 // Function to test pattern matching of everything with $ in it.
781 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
782 var csvStore = new dojox.data.CsvStore(args);
784 var d = new doh.Deferred();
785 function completed(items, request){
786 t.assertTrue(items.length === 2);
787 var valueArray = [ "jfq4@#!$!@Rf14r14i5u", "bit$Bite"];
788 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", valueArray));
792 csvStore.fetch({query: {value: "*$*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
795 function testReadAPI_fetch_patternMatch2(t){
797 // Function to test exact pattern match
799 // Function to test exact pattern match
801 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
802 var csvStore = new dojox.data.CsvStore(args);
804 var d = new doh.Deferred();
805 function completed(items, request){
806 t.is(1, items.length);
807 t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
811 csvStore.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
814 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
816 // Function to test exact pattern match with case insensitivity set.
818 // Function to test exact pattern match with case insensitivity set.
820 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
821 var csvStore = new dojox.data.CsvStore(args);
823 var d = new doh.Deferred();
824 function completed(items, request){
825 t.is(1, items.length);
826 t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
830 csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
833 function testReadAPI_fetch_patternMatch_caseSensitive(t){
835 // Function to test exact pattern match with case insensitivity set.
837 // Function to test exact pattern match with case insensitivity set.
839 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
840 var csvStore = new dojox.data.CsvStore(args);
842 var d = new doh.Deferred();
843 function completed(items, request){
844 t.is(0, items.length);
848 csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
851 function testReadAPI_fetch_sortNumeric(t){
853 // Function to test sorting numerically.
855 // Function to test sorting numerically.
857 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
858 var csvStore = new dojox.data.CsvStore(args);
860 var d = new doh.Deferred();
861 function completed(items, request){
862 t.assertTrue(items.length === 10);
863 // TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
864 var orderedArray = [ "1", "10", "2", "3", "4", "5", "6", "7", "8", "9" ];
865 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
869 var sortAttributes = [{attribute: "uniqueId"}];
870 csvStore.fetch({onComplete: completed,
871 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d),
872 sort: sortAttributes});
875 function testReadAPI_fetch_sortNumericDescending(t){
877 // Function to test sorting numerically.
879 // Function to test sorting numerically.
881 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
882 var csvStore = new dojox.data.CsvStore(args);
884 var d = new doh.Deferred();
885 function completed(items, request){
886 t.is(10, items.length);
887 // TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
888 var orderedArray = [ "9", "8", "7", "6", "5", "4", "3", "2", "10", "1" ];
889 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
893 var sortAttributes = [{attribute: "uniqueId", descending: true}];
894 csvStore.fetch({ sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
897 function testReadAPI_fetch_sortNumericWithCount(t){
899 // Function to test sorting numerically in descending order, returning only a specified number of them.
901 // Function to test sorting numerically in descending order, returning only a specified number of them.
903 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
904 var csvStore = new dojox.data.CsvStore(args);
906 var d = new doh.Deferred();
907 function completed(items, request){
908 t.is(5, items.length);
909 // TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
910 var orderedArray = [ "9", "8", "7", "6", "5" ];
911 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
915 var sortAttributes = [{attribute: "uniqueId", descending: true}];
916 csvStore.fetch({sort: sortAttributes,
918 onComplete: completed,
919 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
922 function testReadAPI_fetch_sortAlphabetic(t){
924 // Function to test sorting alphabetic ordering.
926 // Function to test sorting alphabetic ordering.
928 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
929 var csvStore = new dojox.data.CsvStore(args);
931 var d = new doh.Deferred();
932 function completed(items, request){
933 //Output should be in this order...
934 var orderedArray = [ "123abc",
942 "jfq4@#!$!@Rf14r14i5u",
945 t.is(10, items.length);
946 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
950 var sortAttributes = [{attribute: "value"}];
951 csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
954 function testReadAPI_fetch_sortAlphabeticDescending(t){
956 // Function to test sorting alphabetic ordering in descending mode.
958 // Function to test sorting alphabetic ordering in descending mode.
960 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
961 var csvStore = new dojox.data.CsvStore(args);
963 var d = new doh.Deferred();
964 function completed(items, request){
965 //Output should be in this order...
966 var orderedArray = [ undefined,
967 "jfq4@#!$!@Rf14r14i5u",
977 t.is(10, items.length);
978 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
982 var sortAttributes = [{attribute: "value", descending: true}];
983 csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
986 function testReadAPI_fetch_sortMultiple(t){
988 // Function to test sorting on multiple attributes.
990 // Function to test sorting on multiple attributes.
992 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
993 var csvStore = new dojox.data.CsvStore(args);
995 var d = new doh.Deferred();
996 function completed(items, request){
997 var orderedArray0 = [ "8", "5", "3", "10", "6", "2", "4", "1", "9", "7" ];
998 var orderedArray1 = [ "123abc",
1006 "jfq4@#!$!@Rf14r14i5u",
1009 t.is(10, items.length);
1010 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray0));
1011 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray1));
1015 var sortAttributes = [{ attribute: "value"}, { attribute: "uniqueId", descending: true}];
1016 csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
1019 function testReadAPI_fetch_sortMultipleSpecialComparator(t){
1021 // Function to test sorting on multiple attributes with a custom comparator.
1023 // Function to test sorting on multiple attributes with a custom comparator.
1025 var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
1026 var csvStore = new dojox.data.CsvStore(args);
1028 csvStore.comparatorMap = {};
1029 csvStore.comparatorMap["Producer"] = function(a,b){
1031 // We want to sort authors alphabetical by their last name
1032 function lastName(name){
1033 if(typeof name === "undefined"){ return undefined; }
1035 var matches = name.match(/\s*(\S+)$/); // Grab the last word in the string.
1036 return matches ? matches[1] : name; // Strings with only whitespace will not match.
1038 var lastNameA = lastName(a);
1039 var lastNameB = lastName(b);
1040 if(lastNameA > lastNameB || typeof lastNameA === "undefined"){
1042 }else if(lastNameA < lastNameB || typeof lastNameB === "undefined"){
1048 var sortAttributes = [{attribute: "Producer", descending: true}, { attribute: "Title", descending: true}];
1050 var d = new doh.Deferred();
1051 function completed(items, findResult){
1052 var orderedArray = [5,4,0,3,2,1,6];
1053 t.assertTrue(items.length === 7);
1055 for(var i = 0; i < items.length; i++){
1056 if(!(csvStore.getIdentity(items[i]) === orderedArray[i])){
1061 t.assertTrue(passed);
1065 csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
1068 function testReadAPI_functionConformance(t){
1070 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
1072 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
1074 var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
1075 var readApi = new dojo.data.api.Read();
1079 if(i.toString().charAt(0) !== '_')
1081 var member = readApi[i];
1082 //Check that all the 'Read' defined functions exist on the test store.
1083 if(typeof member === "function"){
1084 console.log("Looking at function: [" + i + "]");
1085 var testStoreMember = testStore[i];
1086 if(!(typeof testStoreMember === "function")){
1087 console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
1094 t.assertTrue(passed);
1096 function testIdentityAPI_functionConformance(t){
1098 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
1100 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
1102 var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
1103 var identityApi = new dojo.data.api.Identity();
1106 for(i in identityApi){
1107 if(i.toString().charAt(0) !== '_')
1109 var member = identityApi[i];
1110 //Check that all the 'Read' defined functions exist on the test store.
1111 if(typeof member === "function"){
1112 console.log("Looking at function: [" + i + "]");
1113 var testStoreMember = testStore[i];
1114 if(!(typeof testStoreMember === "function")){
1121 t.assertTrue(passed);