Debian Codegraph @

dojox/data/tests/stores/CssClassStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.CssClassStore");
2 dojo.require("dojox.data.CssClassStore");
3 dojo.require("dojo.data.api.Read");
4 dojo.require("dojo.data.api.Identity");
5
6 dojox.data.tests.stores.CssClassStore.createStore = function(context){
7 // summary:
8 // A simple helper function for getting the sample data used in each of the tests.
9 // description:
10 // A simple helper function for getting the sample data used in each of the tests.
11 var store = null;
12 if(dojo.isBrowser){
13 if(!dojox.data.tests.stores.CssClassStore._loaded){
14 var head = dojo.doc.getElementsByTagName('head')[0];
15 var link = document.createElement('link');
16 link.href = require.toUrl('dojox/data/tests/stores/test1.css').toString();
17 link.rel = "stylesheet";
18 link.type = "text/css";
19 head.appendChild(link);
20 var style;
21 var text;
22 if(dojo.isIE){
23 style = document.createStyleSheet();
24 style.cssText = '@import "'+require.toUrl('dojox/data/tests/stores/test2.css').toString()+'";';
25 }else{
26 style = document.createElement('style');
27 text = document.createTextNode('@import "'+require.toUrl('dojox/data/tests/stores/test2.css').toString()+'";');
28 style.appendChild(text);
29 head.appendChild(style);
30 }
31 if(dojo.isIE){
32 style = document.createStyleSheet();
33 style.cssText = '.embeddedTestClass { text-align: center; }';
34 }else{
35 style = document.createElement('style');
36 text = document.createTextNode('.embeddedTestClass { text-align: center; }');
37 style.appendChild(text);
38 head.appendChild(style);
39 }
40 dojox.data.tests.stores.CssClassStore._loaded = true;
41 }
42 store = new dojox.data.CssClassStore({context: context});
43 }else{
44 // When running tests in Rhino, xhrGet is not available,
45 // so we have the file data in the code below.
46
47 // TODO: What are the stipulations re: DOM ? Can I do the same as above?
48 }
49 return store;
50 };
51
52 dojox.data.tests.stores.CssClassStore.verifyItems = function(cssClassStore, items, attribute, compareArray){
53 // summary:
54 // A helper function for validating that the items array is ordered
55 // the same as the compareArray
56 if(items.length != compareArray.length){ return false; }
57 for(var i = 0; i < items.length; i++){
58 // Safari is dumb, see comment in CssClassStore about bug in selectorText
59 if(!(cssClassStore.getValue(items[i], attribute) === compareArray[i])){
60 return false; //Boolean
61 }
62 }
63 return true; //Boolean
64 };
65
66 dojox.data.tests.stores.CssClassStore.error = function(t, d, errData){
67 // summary:
68 // The error callback function to be used for all of the tests.
69 for (var i in errData) {
70 console.log(errData[i]);
71 }
72 d.errback(errData);
73 };
74
75 doh.register("dojox.data.tests.stores.CssClassStore",
76 [
77 {
78 name: "testReadAPI_fetch",
79 timeout: 10000, //10 seconds.
80 runTest: function(t) {
81 // summary:
82 // Simple test of a basic fetch on CssClassStore.
83 // description:
84 // Simple test of a basic fetch on CssClassStore.
85 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
86
87 var d = new doh.Deferred();
88 function completedAll(items){
89 t.assertTrue(items.length === 3);
90 d.callback(true);
91 }
92
93 //Get everything...
94 cssClassStore.fetch({
95 query: {'class': '*TestClass'},
96 onComplete: completedAll,
97 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
98 });
99 return d; //Object
100 }
101 },
102 function testReadAPI_fetch_all(t){
103 // summary:
104 // Simple test of a basic fetch on CssClassStore.
105 // description:
106 // Simple test of a basic fetch on CssClassStore.
107 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore(['dojox/data/tests/stores/test1.css', 'dojox/data/tests/stores/test2.css']);
108
109 var d = new doh.Deferred();
110 function completedAll(items){
111 t.assertTrue(items.length === 3);
112 d.callback(true);
113 }
114
115 //Get everything...
116 cssClassStore.fetch({
117 onComplete: completedAll,
118 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
119 });
120 return d; //Object
121 },
122 function testReadAPI_fetch_withinContext(t){
123 // summary:
124 // Simple test of a basic fetch on CssClassStore.
125 // description:
126 // Simple test of a basic fetch on CssClassStore.
127
128 //dojox.data.tests.stores.CssClassStore.loadStylesheets();
129 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore(['dojox/data/tests/stores/test1.css']);
130
131 var d = new doh.Deferred();
132 function completedAll(items){
133 t.assertTrue(items.length === 1);
134 d.callback(true);
135 }
136
137 //Get everything...
138 cssClassStore.fetch({
139 query: {'class': '*TestClass'},
140 onComplete: completedAll,
141 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
142 });
143 return d; //Object
144 },
145 function testReadAPI_fetch_withinMultipleSheetContext(t){
146 // summary:
147 // Simple test of a basic fetch on CssClassStore.
148 // description:
149 // Simple test of a basic fetch on CssClassStore.
150
151 //dojox.data.tests.stores.CssClassStore.loadStylesheets();
152 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore(['dojox/data/tests/stores/test1.css', 'dojox/data/tests/stores/test2.css']);
153
154 var d = new doh.Deferred();
155 function completedAll(items){
156 t.assertTrue(items.length === 2);
157 d.callback(true);
158 }
159
160 //Get everything...
161 cssClassStore.fetch({
162 query: {'class': '*TestClass'},
163 onComplete: completedAll,
164 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
165 });
166 return d; //Object
167 },
168 function testReadAPI_fetch_switchContext(t){
169 // summary:
170 // Simple test of a basic fetch on CssClassStore.
171 // description:
172 // Simple test of a basic fetch on CssClassStore.
173
174 //dojox.data.tests.stores.CssClassStore.loadStylesheets();
175 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore(['dojox/data/tests/stores/test1.css', 'dojox/data/tests/stores/test2.css']);
176
177 var d = new doh.Deferred();
178 function completedAll(items){
179 t.assertTrue(items.length === 2);
180
181 function completedAllTwo(items){
182 t.assertTrue(items.length === 1);
183 d.callback(true);
184 }
185
186 cssClassStore.setContext(['dojox/data/tests/stores/test1.css']);
187 cssClassStore.fetch({
188 query: {'class': '*TestClass'},
189 onComplete: completedAllTwo,
190 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
191 });
192 }
193
194 //Get everything...
195 cssClassStore.fetch({
196 query: {'class': '*TestClass'},
197 onComplete: completedAll,
198 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
199 });
200 return d; //Object
201 },
202 function testReadAPI_fetch_one(t){
203 // summary:
204 // Simple test of a basic fetch on CsvStore of a single item.
205 // description:
206 // Simple test of a basic fetch on CsvStore of a single item.
207 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
208
209 var d = new doh.Deferred();
210 function onComplete(items, request){
211 t.is(1, items.length);
212 d.callback(true);
213 }
214 cssClassStore.fetch({
215 query: {'class': '.linkTestClass'},
216 onComplete: onComplete,
217 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
218 });
219 return d; //Object
220 },
221 function testReadAPI_fetch_one_sans(t){
222 // summary:
223 // Simple test of a basic fetch on CsvStore of a single item.
224 // description:
225 // Simple test of a basic fetch on CsvStore of a single item.
226 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
227
228 var d = new doh.Deferred();
229 function onComplete(items, request){
230 t.is(1, items.length);
231 d.callback(true);
232 }
233 cssClassStore.fetch({
234 query: {'classSans': 'linkTestClass'},
235 onComplete: onComplete,
236 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
237 });
238 return d; //Object
239 },
240 function testReadAPI_fetch_Multiple(t){
241 // summary:
242 // Simple test of a basic fetch on CsvStore of a single item.
243 // description:
244 // Simple test of a basic fetch on CsvStore of a single item.
245 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
246
247 var d = new doh.Deferred();
248 var done = [false, false];
249
250 function onCompleteOne(items, request){
251 done[0] = true;
252 t.is(1, items.length);
253 if(done[0] && done[1]){
254 d.callback(true);
255 }
256 }
257
258 function onCompleteTwo(items, request){
259 done[1] = true;
260 t.is(1, items.length);
261 if(done[0] && done[1]){
262 d.callback(true);
263 }
264 }
265
266 try{
267 cssClassStore.fetch({
268 query: {'class': '.embeddedTestClass'},
269 onComplete: onCompleteOne,
270 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
271 });
272 cssClassStore.fetch({
273 query: {'class': '.linkTestClass'},
274 onComplete: onCompleteTwo,
275 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
276 });
277 }catch(e){
278 for(var i in e){
279 console.log(e[i]);
280 }
281 }
282
283 return d; //Object
284 },
285 function testReadAPI_fetch_MultipleMixed(t){
286 // summary:
287 // Simple test of a basic fetch on CsvStore of a single item.
288 // description:
289 // Simple test of a basic fetch on CsvStore of a single item.
290 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
291
292 var d = new doh.Deferred();
293
294 var done = [false, false];
295 function onComplete(items, request){
296 done[0] = true;
297 t.is(1, items.length);
298 t.is('.linkTestClass', cssClassStore.getValue(items[0], 'class'));
299 if(done[0] && done[1]){
300 d.callback(true);
301 }
302 }
303
304 function onItem(item){
305 done[1] = true;
306 t.assertTrue(item !== null);
307 t.is('.embeddedTestClass', cssClassStore.getValue(item, 'class'));
308 if(done[0] && done[1]){
309 d.callback(true);
310 }
311 }
312
313 cssClassStore.fetch({
314 query: {'class': '.linkTestClass'},
315 onComplete: onComplete,
316 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
317 });
318
319 cssClassStore.fetch({
320 query: {'classSans': 'embeddedTestClass'},
321 onItem: onItem,
322 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
323 });
324 return d; //Object
325 },
326 function testReadAPI_fetch_all_streaming(t){
327 // summary:
328 // Simple test of a basic fetch on CsvStore.
329 // description:
330 // Simple test of a basic fetch on CsvStore.
331 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
332
333 var d = new doh.Deferred();
334 var count = 0;
335
336 function onBegin(size, requestObj){
337 t.assertTrue(size === 3);
338 }
339 function onItem(item, requestObj){
340 t.assertTrue(cssClassStore.isItem(item));
341 count++;
342 }
343 function onComplete(items, request){
344 t.is(3, count);
345 t.is(null, items);
346 d.callback(true);
347 }
348
349 //Get everything...
350 cssClassStore.fetch({
351 query: {'class': '*TestClass'},
352 onBegin: onBegin,
353 onItem: onItem,
354 onComplete: onComplete,
355 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
356 });
357 return d; //Object
358 },
359 function testReadAPI_fetch_paging(t){
360 // summary:
361 // Test of multiple fetches on a single result. Paging, if you will.
362 // description:
363 // Test of multiple fetches on a single result. Paging, if you will.
364 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
365
366 var d = new doh.Deferred();
367
368 function dumpThirdFetch(items, request){
369 t.is(2, items.length);
370 d.callback(true);
371 }
372
373 function dumpSecondFetch(items, request){
374 t.is(1, items.length);
375 t.is('.embeddedTestClass', cssClassStore.getValue(items[0], 'class'));
376 request.start = 0;
377 request.count = 2;
378 request.onComplete = dumpThirdFetch;
379 cssClassStore.fetch(request);
380 }
381
382 function dumpFirstFetch(items, request){
383 t.is(3, items.length);
384 request.start = 2;
385 request.count = 1;
386 request.onComplete = dumpSecondFetch;
387 cssClassStore.fetch(request);
388 }
389
390 cssClassStore.fetch({
391 query: {'class': '*TestClass'},
392 onComplete: dumpFirstFetch,
393 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
394 });
395 return d; //Object
396
397 },
398
399 function testReadAPI_getLabel(t){
400 // summary:
401 // Simple test of the getLabel function against a store set that has a label defined.
402 // description:
403 // Simple test of the getLabel function against a store set that has a label defined.
404 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
405
406 var d = new doh.Deferred();
407 function onComplete(items, request){
408 t.assertEqual(items.length, 1);
409 var label = cssClassStore.getLabel(items[0]);
410 t.assertTrue(label !== null);
411 t.assertEqual(".linkTestClass", label);
412 d.callback(true);
413 }
414 cssClassStore.fetch({
415 query: {'classSans': 'linkTestClass'},
416 onComplete: onComplete,
417 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
418 });
419 return d;
420 },
421 function testReadAPI_getLabelAttributes(t){
422 // summary:
423 // Simple test of the getLabelAttributes function against a store set that has a label defined.
424 // description:
425 // Simple test of the getLabelAttributes function against a store set that has a label defined.
426 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
427
428 var d = new doh.Deferred();
429 function onComplete(items, request){
430 t.assertEqual(items.length, 1);
431 var labelList = cssClassStore.getLabelAttributes(items[0]);
432 t.assertTrue(dojo.isArray(labelList));
433 t.assertEqual("class", labelList[0]);
434 d.callback(true);
435 }
436 cssClassStore.fetch({
437 query: {'classSans': 'linkTestClass'},
438 onComplete: onComplete,
439 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
440 });
441 return d;
442 },
443 function testReadAPI_getValue(t){
444 // summary:
445 // Simple test of the getValue function of the store.
446 // description:
447 // Simple test of the getValue function of the store.
448 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
449
450 var d = new doh.Deferred();
451 function onItem(item){
452 t.assertTrue(item !== null);
453 t.is('.linkTestClass', cssClassStore.getValue(item,'class'));
454 t.is('linkTestClass', cssClassStore.getValue(item,'classSans'));
455 d.callback(true);
456 }
457 cssClassStore.fetch({
458 query: {'classSans': 'linkTestClass'},
459 onItem: onItem,
460 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
461 });
462 return d;
463 },
464 function testReadAPI_getValue_2(t){
465 // summary:
466 // Simple test of the getValue function of the store.
467 // description:
468 // Simple test of the getValue function of the store.
469 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
470
471 var d = new doh.Deferred();
472 function onItem(item){
473 t.assertTrue(item !== null);
474 t.is('.importTestClass', cssClassStore.getValue(item,'class'));
475 t.is('importTestClass', cssClassStore.getValue(item,'classSans'));
476 d.callback(true);
477 }
478 cssClassStore.fetch({
479 query: {'classSans': 'importTestClass'},
480 onItem: onItem,
481 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
482 });
483 return d;
484 },
485 function testReadAPI_getValues(t){
486 // summary:
487 // Simple test of the getValues function of the store.
488 // description:
489 // Simple test of the getValues function of the store.
490 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
491
492 var d = new doh.Deferred();
493 function onItem(item){
494 t.assertTrue(item !== null);
495 var values = cssClassStore.getValues(item,'class');
496 t.assertTrue(dojo.isArray(values));
497 t.is(1, values.length);
498 t.is('.embeddedTestClass', values[0]);
499 d.callback(true);
500 }
501 cssClassStore.fetch({
502 query: {'classSans': 'embeddedTestClass'},
503 onItem: onItem,
504 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
505 });
506 return d;
507 },
508 function testReadAPI_isItem(t){
509 // summary:
510 // Simple test of the isItem function of the store
511 // description:
512 // Simple test of the isItem function of the store
513 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
514
515 var d = new doh.Deferred();
516 function onItem(item){
517 t.assertTrue(cssClassStore.isItem(item));
518 t.assertTrue(!cssClassStore.isItem({}));
519 t.assertTrue(!cssClassStore.isItem({ item: "not an item" }));
520 t.assertTrue(!cssClassStore.isItem("not an item"));
521 t.assertTrue(!cssClassStore.isItem(["not an item"]));
522 d.callback(true);
523 }
524 cssClassStore.fetch({
525 query: {'classSans': 'embeddedTestClass'},
526 onItem: onItem,
527 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
528 });
529 return d;
530 },
531 function testReadAPI_hasAttribute(t){
532 // summary:
533 // Simple test of the hasAttribute function of the store
534 // description:
535 // Simple test of the hasAttribute function of the store
536 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
537
538 var d = new doh.Deferred();
539 function onItem(item){
540 t.assertTrue(item !== null);
541 t.assertTrue(cssClassStore.hasAttribute(item, 'class'));
542 t.assertTrue(cssClassStore.hasAttribute(item, 'classSans'));
543 t.assertTrue(!cssClassStore.hasAttribute(item, "Year"));
544 t.assertTrue(!cssClassStore.hasAttribute(item, "Nothing"));
545 t.assertTrue(!cssClassStore.hasAttribute(item, "title"));
546
547 //Test that null attributes throw an exception
548 var passed = false;
549 try{
550 cssClassStore.hasAttribute(item, null);
551 }catch (e){
552 passed = true;
553 }
554 t.assertTrue(passed);
555 d.callback(true);
556 }
557 cssClassStore.fetch({
558 query: {'classSans': 'embeddedTestClass'},
559 onItem: onItem,
560 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
561 });
562 return d;
563 },
564 function testReadAPI_containsValue(t){
565 // summary:
566 // Simple test of the containsValue function of the store
567 // description:
568 // Simple test of the containsValue function of the store
569 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
570
571 var d = new doh.Deferred();
572 function onItem(item){
573 t.assertTrue(item !== null);
574 t.assertTrue(cssClassStore.containsValue(item, 'class', '.embeddedTestClass'));
575 t.assertTrue(cssClassStore.containsValue(item, 'classSans', 'embeddedTestClass'));
576 t.assertTrue(!cssClassStore.containsValue(item, 'class', '.embeddedTestClass2'));
577 t.assertTrue(!cssClassStore.containsValue(item, 'classSans', 'embeddedTestClass '));
578 t.assertTrue(!cssClassStore.containsValue(item, 'class', null));
579
580 //Test that null attributes throw an exception
581 var passed = false;
582 try{
583 cssClassStore.containsValue(item, null, "foo");
584 }catch (e){
585 passed = true;
586 }
587 t.assertTrue(passed);
588 d.callback(true);
589 }
590 cssClassStore.fetch({
591 query: {'classSans': 'embeddedTestClass'},
592 onItem: onItem,
593 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
594 });
595 return d;
596 },
597 function testReadAPI_getAttributes(t){
598 // summary:
599 // Simple test of the getAttributes function of the store
600 // description:
601 // Simple test of the getAttributes function of the store
602 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
603
604 var d = new doh.Deferred();
605 function onItem(item){
606 t.assertTrue(item !== null);
607 t.assertTrue(cssClassStore.isItem(item));
608
609 var attributes = cssClassStore.getAttributes(item);
610 t.is(2, attributes.length);
611 for(var i = 0; i < attributes.length; i++){
612 t.assertTrue((attributes[i] === 'class' || attributes[i] === 'classSans'));
613 }
614 d.callback(true);
615 }
616 cssClassStore.fetch({
617 query: {'classSans': 'embeddedTestClass'},
618 onItem: onItem,
619 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
620 });
621 return d;
622 },
623 function testReadAPI_getFeatures(t){
624 // summary:
625 // Simple test of the getFeatures function of the store
626 // description:
627 // Simple test of the getFeatures function of the store
628 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
629
630 var features = cssClassStore.getFeatures();
631 var count = 0;
632 for(var i in features){
633 t.assertTrue(i === "dojo.data.api.Read" || i === "dojo.data.api.Identity");
634 count++;
635 }
636 t.assertTrue(count === 2);
637 },
638 function testReadAPI_fetch_patternMatch0(t){
639 // summary:
640 // Function to test pattern matching of everything swith Cla in it
641 // description:
642 // Function to test pattern matching of everything with Cla in it
643 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
644 var d = new doh.Deferred();
645 function completed(items, request){
646 t.is(3, items.length);
647 var valueArray = ['linkTestClass', 'importTestClass', 'embeddedTestClass'];
648 t.assertTrue(dojox.data.tests.stores.CssClassStore.verifyItems(cssClassStore, items, 'classSans', valueArray));
649 d.callback(true);
650 }
651
652 cssClassStore.fetch({
653 query: {'class': '*TestCla**'},
654 onComplete: completed,
655 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
656 });
657 return d; //Object
658 },
659 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
660 // summary:
661 // Function to test exact pattern match with case insensitivity set.
662 // description:
663 // Function to test exact pattern match with case insensitivity set.
664 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
665 var d = new doh.Deferred();
666 function completed(items, request){
667 t.is(1, items.length);
668 t.assertTrue(cssClassStore.getValue(items[0], 'class') === '.linkTestClass');
669 d.callback(true);
670 }
671
672 cssClassStore.fetch({
673 query: {'class': '.LINKtEsTclass'},
674 queryOptions: {ignoreCase: true},
675 onComplete: completed,
676 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
677 });
678 return d; //Object
679 },
680 function testReadAPI_fetch_patternMatch_caseSensitive(t){
681 // summary:
682 // Function to test exact pattern match with case insensitivity set.
683 // description:
684 // Function to test exact pattern match with case insensitivity set.
685 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
686 var d = new doh.Deferred();
687 function completed(items, request){
688 t.is(0, items.length);
689 d.callback(true);
690 }
691
692 cssClassStore.fetch({
693 query: {'class': '.LINKtEsTclass'},
694 queryOptions: {ignoreCase: false},
695 onComplete: completed,
696 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
697 });
698 return d; //Object
699 },
700 function testReadAPI_fetch_sortAlphabetic(t){
701 // summary:
702 // Function to test sorting alphabetic ordering.
703 // description:
704 // Function to test sorting alphabetic ordering.
705 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
706 var d = new doh.Deferred();
707 function completed(items, request){
708 //Output should be in this order...
709 var orderedArray = [ '.embeddedTestClass',
710 '.importTestClass',
711 '.linkTestClass'
712 ];
713 t.is(3, items.length);
714 t.assertTrue(dojox.data.tests.stores.CssClassStore.verifyItems(cssClassStore, items, 'class', orderedArray));
715 d.callback(true);
716 }
717
718 var sortAttributes = [{attribute: 'class'}];
719 cssClassStore.fetch({
720 query: {'class': '*TestClass'},
721 sort: sortAttributes,
722 onComplete: completed,
723 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
724 });
725 return d; //Object
726 },
727 function testReadAPI_fetch_sortAlphabeticDescending(t){
728 // summary:
729 // Function to test sorting alphabetic ordering in descending mode.
730 // description:
731 // Function to test sorting alphabetic ordering in descending mode.
732 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
733 var d = new doh.Deferred();
734
735
736 function completed(items, request){
737 //Output should be in this order...
738 var orderedArray = [ 'linkTestClass',
739 'importTestClass',
740 'embeddedTestClass'
741 ];
742
743 console.debug(items);
744
745 t.is(3, items.length);
746 t.assertTrue(dojox.data.tests.stores.CssClassStore.verifyItems(cssClassStore, items, 'classSans', orderedArray));
747 d.callback(true);
748 }
749
750 var sortAttributes = [{attribute: "classSans", descending: true}];
751 cssClassStore.fetch({
752 query: {'class': '*TestClass'},
753 sort: sortAttributes,
754 onComplete: completed,
755 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
756 });
757 return d; //Object
758 },
759 function testReadAPI_functionConformance(t){
760 // summary:
761 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
762 // description:
763 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
764 var testStore = dojox.data.tests.stores.CssClassStore.createStore();
765 var readApi = new dojo.data.api.Read();
766 var passed = true;
767
768 for(var i in readApi){
769 if(i.toString().charAt(0) !== '_')
770 {
771 var member = readApi[i];
772 //Check that all the 'Read' defined functions exist on the test store.
773 if(typeof member === "function"){
774 console.log("Looking at function: [" + i + "]");
775 var testStoreMember = testStore[i];
776 if(!(typeof testStoreMember === "function")){
777 console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
778 passed = false;
779 break;
780 }
781 }
782 }
783 }
784 t.assertTrue(passed);
785 },
786 function testIdentityAPI_fetchItemByIdentity(t){
787 // summary:
788 // Simple test of the fetchItemByIdentity function of the store.
789 // description:
790 // Simple test of the fetchItemByIdentity function of the store.
791 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
792
793 var d = new doh.Deferred();
794 function onItem(item){
795 t.assertTrue(item !== null);
796 d.callback(true);
797 }
798 cssClassStore.fetchItemByIdentity({
799 identity: ".linkTestClass",
800 onItem: onItem,
801 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
802 });
803 return d;
804 },
805 function testIdentityAPI_fetchItemByIdentity_bad1(t){
806 // summary:
807 // Simple test of the fetchItemByIdentity function of the store.
808 // description:
809 // Simple test of the fetchItemByIdentity function of the store.
810 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
811
812 var d = new doh.Deferred();
813 function onItem(item){
814 t.assertTrue(item === null);
815 d.callback(true);
816 }
817 cssClassStore.fetchItemByIdentity({
818 identity: ".bsClass",
819 onItem: onItem,
820 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
821 });
822 return d;
823 },
824 function testIdentityAPI_fetchItemByIdentity_bad2(t){
825 // summary:
826 // Simple test of the fetchItemByIdentity function of the store.
827 // description:
828 // Simple test of the fetchItemByIdentity function of the store.
829 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
830 var d = new doh.Deferred();
831 function onItem(item){
832 t.assertTrue(item === null);
833 d.callback(true);
834 }
835 cssClassStore.fetchItemByIdentity({
836 identity: 'linkTestClass', // missing the '.'!
837 onItem: onItem,
838 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
839 });
840 return d;
841 },
842 function testIdentityAPI_fetchItemByIdentity_bad3(t){
843 // summary:
844 // Simple test of the fetchItemByIdentity function of the store.
845 // description:
846 // Simple test of the fetchItemByIdentity function of the store.
847 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
848 var d = new doh.Deferred();
849 function onItem(item){
850 t.assertTrue(item === null);
851 d.callback(true);
852 }
853 cssClassStore.fetchItemByIdentity({
854 identity: '9999999',
855 onItem: onItem,
856 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
857 });
858 return d;
859 },
860 function testIdentityAPI_getIdentity(t){
861 // summary:
862 // Simple test of the fetchItemByIdentity function of the store.
863 // description:
864 // Simple test of the fetchItemByIdentity function of the store.
865 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
866 var d = new doh.Deferred();
867 function completed(items, request){
868 t.is(3, items.length);
869 t.assertTrue(cssClassStore.getIdentity(items[0]) === '.embeddedTestClass');
870 t.assertTrue(cssClassStore.getIdentity(items[1]) === '.importTestClass');
871 t.assertTrue(cssClassStore.getIdentity(items[2]) === '.linkTestClass');
872 d.callback(true);
873 }
874 //Get everything...
875 cssClassStore.fetch({
876 query: {'class': '*TestClass'},
877 sort: [{attribute: 'class'}],
878 onComplete: completed,
879 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
880 });
881 return d; //Object
882 },
883 function testIdentityAPI_getIdentityAttributes(t){
884 // summary:
885 // Simple test of the getIdentityAttributes
886 // description:
887 // Simple test of the fetchItemByIdentity function of the store.
888 var cssClassStore = dojox.data.tests.stores.CssClassStore.createStore();
889 var d = new doh.Deferred();
890 function onItem(item){
891 t.assertTrue(cssClassStore.isItem(item));
892 var attrs = cssClassStore.getIdentityAttributes(item);
893 t.assertTrue(dojo.isArray(attrs));
894 t.is(1, attrs.length);
895 t.assertEqual(attrs[0], 'class');
896 d.callback(true);
897 }
898 cssClassStore.fetchItemByIdentity({
899 identity: ".linkTestClass",
900 onItem: onItem,
901 onError: dojo.partial(dojox.data.tests.stores.CssClassStore.error, t, d)
902 });
903 return d;
904 }
905 ]
906 );
907