1 if(!dojo._hasResource["dojox.data.tests.stores.FlickrStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.FlickrStore"] = true;
3 dojo.provide("dojox.data.tests.stores.FlickrStore");
4 dojo.require("dojox.data.FlickrStore");
5 dojo.require("dojo.data.api.Read");
8 dojox.data.tests.stores.FlickrStore.error = function(t, d, errData){
10 // The error callback function to be used for all of the tests.
14 doh.register("dojox.data.tests.stores.FlickrStore",
17 name: "ReadAPI: Fetch_One",
18 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
19 runTest: function(t) {
21 // Simple test of a basic fetch on FlickrStore of a single item.
23 // Simple test of a basic fetch on FlickrStore of a single item.
25 var flickrStore = new dojox.data.FlickrStore();
27 var d = new doh.Deferred();
28 function onComplete(items, request){
29 t.is(1, items.length);
32 flickrStore.fetch({ query: {tags: "animals"},
34 onComplete: onComplete,
35 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, doh, d)
41 name: "ReadAPI: Fetch_20_Streaming",
42 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
43 runTest: function(t) {
45 // Simple test of a basic fetch on FlickrStore.
47 // Simple test of a basic fetch on FlickrStore.
48 var flickrStore = new dojox.data.FlickrStore();
50 var d = new doh.Deferred();
53 function onBegin(size, requestObj){
56 function onItem(item, requestObj){
57 t.assertTrue(flickrStore.isItem(item));
60 function onComplete(items, request){
67 flickrStore.fetch({ onBegin: onBegin,
70 onComplete: onComplete,
71 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
77 name: "ReadAPI: Fetch_Paging",
78 timeout: 30000, //30 seconds. Flickr can sometimes be slow.
79 runTest: function(t) {
81 // Test of multiple fetches on a single result. Paging, if you will.
83 // Test of multiple fetches on a single result. Paging, if you will.
85 var flickrStore = new dojox.data.FlickrStore();
87 var d = new doh.Deferred();
88 function dumpFirstFetch(items, request){
89 t.is(5, items.length);
92 request.onComplete = dumpSecondFetch;
93 flickrStore.fetch(request);
96 function dumpSecondFetch(items, request){
97 t.is(1, items.length);
100 request.onComplete = dumpThirdFetch;
101 flickrStore.fetch(request);
104 function dumpThirdFetch(items, request){
105 t.is(5, items.length);
108 request.onComplete = dumpFourthFetch;
109 flickrStore.fetch(request);
112 function dumpFourthFetch(items, request){
113 t.is(18, items.length);
116 request.onComplete = dumpFifthFetch;
117 flickrStore.fetch(request);
120 function dumpFifthFetch(items, request){
121 t.is(11, items.length);
124 request.onComplete = dumpSixthFetch;
125 flickrStore.fetch(request);
128 function dumpSixthFetch(items, request){
129 t.is(18, items.length);
133 function completed(items, request){
134 t.is(7, items.length);
137 request.onComplete = dumpFirstFetch;
138 flickrStore.fetch(request);
140 flickrStore.fetch({count: 7, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
145 name: "ReadAPI: getLabel",
146 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
147 runTest: function(t) {
149 // Simple test of the getLabel function against a store set that has a label defined.
151 // Simple test of the getLabel function against a store set that has a label defined.
153 var flickrStore = new dojox.data.FlickrStore();
155 var d = new doh.Deferred();
156 function onComplete(items, request){
157 t.assertEqual(items.length, 1);
158 var label = flickrStore.getLabel(items[0]);
159 t.assertTrue(label !== null);
162 flickrStore.fetch({ query: {tags: "animals"},
164 onComplete: onComplete,
165 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
171 name: "ReadAPI: getLabelAttributes",
172 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
173 runTest: function(t) {
175 // Simple test of the getLabelAttributes function against a store set that has a label defined.
177 // Simple test of the getLabelAttributes function against a store set that has a label defined.
179 var flickrStore = new dojox.data.FlickrStore();
181 var d = new doh.Deferred();
182 function onComplete(items, request){
183 t.assertEqual(items.length, 1);
184 var labelList = flickrStore.getLabelAttributes(items[0]);
185 t.assertTrue(dojo.isArray(labelList));
186 t.assertEqual("title", labelList[0]);
189 flickrStore.fetch({ query: {tags: "animals"},
191 onComplete: onComplete,
192 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
198 name: "ReadAPI: getValue",
199 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
200 runTest: function(t) {
202 // Simple test of the getValue function of the store.
204 // Simple test of the getValue function of the store.
205 var flickrStore = new dojox.data.FlickrStore();
207 var d = new doh.Deferred();
208 function completedAll(items){
209 t.is(1, items.length);
210 t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
211 t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
212 t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
213 t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
217 //Get one item and look at it.
218 flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
223 name: "ReadAPI: getValues",
224 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
225 runTest: function(t) {
227 // Simple test of the getValue function of the store.
229 // Simple test of the getValue function of the store.
230 var flickrStore = new dojox.data.FlickrStore();
232 var d = new doh.Deferred();
233 function completedAll(items){
234 t.is(1, items.length);
235 t.assertTrue(flickrStore.getValues(items[0], "title") instanceof Array);
236 t.assertTrue(flickrStore.getValues(items[0], "description") instanceof Array);
237 t.assertTrue(flickrStore.getValues(items[0], "imageUrl") instanceof Array);
238 t.assertTrue(flickrStore.getValues(items[0], "imageUrlSmall") instanceof Array);
239 t.assertTrue(flickrStore.getValues(items[0], "imageUrlMedium") instanceof Array);
242 //Get one item and look at it.
243 flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
248 name: "ReadAPI: isItem",
249 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
250 runTest: function(t) {
252 // Simple test of the isItem function of the store
254 // Simple test of the isItem function of the store
255 var flickrStore = new dojox.data.FlickrStore();
257 var d = new doh.Deferred();
258 function completedAll(items){
259 t.is(5, items.length);
260 for(var i=0; i < items.length; i++){
261 t.assertTrue(flickrStore.isItem(items[i]));
267 flickrStore.fetch({ count: 5, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
272 name: "ReadAPI: hasAttribute",
273 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
274 runTest: function(t) {
276 // Simple test of the hasAttribute function of the store
278 // Simple test of the hasAttribute function of the store
280 var flickrStore = new dojox.data.FlickrStore();
282 var d = new doh.Deferred();
283 function onComplete(items){
284 t.is(1, items.length);
285 t.assertTrue(items[0] !== null);
286 t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
287 t.assertTrue(flickrStore.hasAttribute(items[0], "description"));
288 t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
289 t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
290 t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
292 //Test that null attributes throw an exception
295 flickrStore.hasAttribute(items[0], null);
299 t.assertTrue(passed);
304 flickrStore.fetch({ query: {tags: "animals"},
306 onComplete: onComplete,
307 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
313 name: "ReadAPI: containsValue",
314 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
315 runTest: function(t) {
317 // Simple test of the containsValue function of the store
319 // Simple test of the containsValue function of the store
321 var flickrStore = new dojox.data.FlickrStore();
323 var d = new doh.Deferred();
324 function onComplete(items){
325 t.is(1, items.length);
330 flickrStore.fetch({ query: {tags: "animals"},
332 onComplete: onComplete,
333 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
339 name: "ReadAPI: getAttributes",
340 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
341 runTest: function(t) {
343 // Simple test of the getAttributes function of the store
345 // Simple test of the getAttributes function of the store
347 var flickrStore = new dojox.data.FlickrStore();
349 var d = new doh.Deferred();
350 function onComplete(items){
351 t.is(1, items.length);
352 t.assertTrue(flickrStore.isItem(items[0]));
354 var attributes = flickrStore.getAttributes(items[0]);
355 t.is(10, attributes.length);
360 flickrStore.fetch({ count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
364 function testReadAPI_getFeatures(t){
366 // Simple test of the getFeatures function of the store
368 // Simple test of the getFeatures function of the store
370 var flickrStore = new dojox.data.FlickrStore();
372 var features = flickrStore.getFeatures();
375 t.assertTrue((i === "dojo.data.api.Read"));
378 t.assertTrue(count === 1);
380 function testReadAPI_functionConformance(t){
382 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
384 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
386 var testStore = new dojox.data.FlickrStore();
387 var readApi = new dojo.data.api.Read();
391 if(i.toString().charAt(0) !== '_')
393 var member = readApi[i];
394 //Check that all the 'Read' defined functions exist on the test store.
395 if(typeof member === "function"){
396 var testStoreMember = testStore[i];
397 if(!(typeof testStoreMember === "function")){
404 t.assertTrue(passed);