2150 |
mathias |
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");
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
dojox.data.tests.stores.FlickrStore.error = function(t, d, errData){
|
|
|
9 |
// summary:
|
|
|
10 |
// The error callback function to be used for all of the tests.
|
|
|
11 |
d.errback(errData);
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
doh.register("dojox.data.tests.stores.FlickrStore",
|
|
|
15 |
[
|
|
|
16 |
{
|
|
|
17 |
name: "ReadAPI: Fetch_One",
|
|
|
18 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
19 |
runTest: function(t) {
|
|
|
20 |
// summary:
|
|
|
21 |
// Simple test of a basic fetch on FlickrStore of a single item.
|
|
|
22 |
// description:
|
|
|
23 |
// Simple test of a basic fetch on FlickrStore of a single item.
|
|
|
24 |
|
|
|
25 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
26 |
|
|
|
27 |
var d = new doh.Deferred();
|
|
|
28 |
function onComplete(items, request){
|
|
|
29 |
t.is(1, items.length);
|
|
|
30 |
d.callback(true);
|
|
|
31 |
}
|
|
|
32 |
flickrStore.fetch({ query: {tags: "animals"},
|
|
|
33 |
count: 1,
|
|
|
34 |
onComplete: onComplete,
|
|
|
35 |
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, doh, d)
|
|
|
36 |
});
|
|
|
37 |
return d; //Object
|
|
|
38 |
}
|
|
|
39 |
},
|
|
|
40 |
{
|
|
|
41 |
name: "ReadAPI: Fetch_20_Streaming",
|
|
|
42 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
43 |
runTest: function(t) {
|
|
|
44 |
// summary:
|
|
|
45 |
// Simple test of a basic fetch on FlickrStore.
|
|
|
46 |
// description:
|
|
|
47 |
// Simple test of a basic fetch on FlickrStore.
|
|
|
48 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
49 |
|
|
|
50 |
var d = new doh.Deferred();
|
|
|
51 |
count = 0;
|
|
|
52 |
|
|
|
53 |
function onBegin(size, requestObj){
|
|
|
54 |
t.is(20, size);
|
|
|
55 |
}
|
|
|
56 |
function onItem(item, requestObj){
|
|
|
57 |
t.assertTrue(flickrStore.isItem(item));
|
|
|
58 |
count++;
|
|
|
59 |
}
|
|
|
60 |
function onComplete(items, request){
|
|
|
61 |
t.is(20, count);
|
|
|
62 |
t.is(null, items);
|
|
|
63 |
d.callback(true);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
//Get everything...
|
|
|
67 |
flickrStore.fetch({ onBegin: onBegin,
|
|
|
68 |
count: 20,
|
|
|
69 |
onItem: onItem,
|
|
|
70 |
onComplete: onComplete,
|
|
|
71 |
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
|
|
|
72 |
});
|
|
|
73 |
return d; //Object
|
|
|
74 |
}
|
|
|
75 |
},
|
|
|
76 |
{
|
|
|
77 |
name: "ReadAPI: Fetch_Paging",
|
|
|
78 |
timeout: 30000, //30 seconds. Flickr can sometimes be slow.
|
|
|
79 |
runTest: function(t) {
|
|
|
80 |
// summary:
|
|
|
81 |
// Test of multiple fetches on a single result. Paging, if you will.
|
|
|
82 |
// description:
|
|
|
83 |
// Test of multiple fetches on a single result. Paging, if you will.
|
|
|
84 |
|
|
|
85 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
86 |
|
|
|
87 |
var d = new doh.Deferred();
|
|
|
88 |
function dumpFirstFetch(items, request){
|
|
|
89 |
t.is(5, items.length);
|
|
|
90 |
request.start = 3;
|
|
|
91 |
request.count = 1;
|
|
|
92 |
request.onComplete = dumpSecondFetch;
|
|
|
93 |
flickrStore.fetch(request);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
function dumpSecondFetch(items, request){
|
|
|
97 |
t.is(1, items.length);
|
|
|
98 |
request.start = 0;
|
|
|
99 |
request.count = 5;
|
|
|
100 |
request.onComplete = dumpThirdFetch;
|
|
|
101 |
flickrStore.fetch(request);
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
function dumpThirdFetch(items, request){
|
|
|
105 |
t.is(5, items.length);
|
|
|
106 |
request.start = 2;
|
|
|
107 |
request.count = 20;
|
|
|
108 |
request.onComplete = dumpFourthFetch;
|
|
|
109 |
flickrStore.fetch(request);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
function dumpFourthFetch(items, request){
|
|
|
113 |
t.is(18, items.length);
|
|
|
114 |
request.start = 9;
|
|
|
115 |
request.count = 100;
|
|
|
116 |
request.onComplete = dumpFifthFetch;
|
|
|
117 |
flickrStore.fetch(request);
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
function dumpFifthFetch(items, request){
|
|
|
121 |
t.is(11, items.length);
|
|
|
122 |
request.start = 2;
|
|
|
123 |
request.count = 20;
|
|
|
124 |
request.onComplete = dumpSixthFetch;
|
|
|
125 |
flickrStore.fetch(request);
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
function dumpSixthFetch(items, request){
|
|
|
129 |
t.is(18, items.length);
|
|
|
130 |
d.callback(true);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
function completed(items, request){
|
|
|
134 |
t.is(7, items.length);
|
|
|
135 |
request.start = 1;
|
|
|
136 |
request.count = 5;
|
|
|
137 |
request.onComplete = dumpFirstFetch;
|
|
|
138 |
flickrStore.fetch(request);
|
|
|
139 |
}
|
|
|
140 |
flickrStore.fetch({count: 7, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
|
|
|
141 |
return d; //Object
|
|
|
142 |
}
|
|
|
143 |
},
|
|
|
144 |
{
|
|
|
145 |
name: "ReadAPI: getLabel",
|
|
|
146 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
147 |
runTest: function(t) {
|
|
|
148 |
// summary:
|
|
|
149 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
150 |
// description:
|
|
|
151 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
152 |
|
|
|
153 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
154 |
|
|
|
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);
|
|
|
160 |
d.callback(true);
|
|
|
161 |
}
|
|
|
162 |
flickrStore.fetch({ query: {tags: "animals"},
|
|
|
163 |
count: 1,
|
|
|
164 |
onComplete: onComplete,
|
|
|
165 |
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
|
|
|
166 |
});
|
|
|
167 |
return d;
|
|
|
168 |
}
|
|
|
169 |
},
|
|
|
170 |
{
|
|
|
171 |
name: "ReadAPI: getLabelAttributes",
|
|
|
172 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
173 |
runTest: function(t) {
|
|
|
174 |
// summary:
|
|
|
175 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
176 |
// description:
|
|
|
177 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
178 |
|
|
|
179 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
180 |
|
|
|
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]);
|
|
|
187 |
d.callback(true);
|
|
|
188 |
}
|
|
|
189 |
flickrStore.fetch({ query: {tags: "animals"},
|
|
|
190 |
count: 1,
|
|
|
191 |
onComplete: onComplete,
|
|
|
192 |
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
|
|
|
193 |
});
|
|
|
194 |
return d;
|
|
|
195 |
}
|
|
|
196 |
},
|
|
|
197 |
{
|
|
|
198 |
name: "ReadAPI: getValue",
|
|
|
199 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
200 |
runTest: function(t) {
|
|
|
201 |
// summary:
|
|
|
202 |
// Simple test of the getValue function of the store.
|
|
|
203 |
// description:
|
|
|
204 |
// Simple test of the getValue function of the store.
|
|
|
205 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
206 |
|
|
|
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);
|
|
|
214 |
d.callback(true);
|
|
|
215 |
}
|
|
|
216 |
|
|
|
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)});
|
|
|
219 |
return d; //Object
|
|
|
220 |
}
|
|
|
221 |
},
|
|
|
222 |
{
|
|
|
223 |
name: "ReadAPI: getValues",
|
|
|
224 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
225 |
runTest: function(t) {
|
|
|
226 |
// summary:
|
|
|
227 |
// Simple test of the getValue function of the store.
|
|
|
228 |
// description:
|
|
|
229 |
// Simple test of the getValue function of the store.
|
|
|
230 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
231 |
|
|
|
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);
|
|
|
240 |
d.callback(true);
|
|
|
241 |
}
|
|
|
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)});
|
|
|
244 |
return d; //Object
|
|
|
245 |
}
|
|
|
246 |
},
|
|
|
247 |
{
|
|
|
248 |
name: "ReadAPI: isItem",
|
|
|
249 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
250 |
runTest: function(t) {
|
|
|
251 |
// summary:
|
|
|
252 |
// Simple test of the isItem function of the store
|
|
|
253 |
// description:
|
|
|
254 |
// Simple test of the isItem function of the store
|
|
|
255 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
256 |
|
|
|
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]));
|
|
|
262 |
}
|
|
|
263 |
d.callback(true);
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
//Get everything...
|
|
|
267 |
flickrStore.fetch({ count: 5, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
|
|
|
268 |
return d; //Object
|
|
|
269 |
}
|
|
|
270 |
},
|
|
|
271 |
{
|
|
|
272 |
name: "ReadAPI: hasAttribute",
|
|
|
273 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
274 |
runTest: function(t) {
|
|
|
275 |
// summary:
|
|
|
276 |
// Simple test of the hasAttribute function of the store
|
|
|
277 |
// description:
|
|
|
278 |
// Simple test of the hasAttribute function of the store
|
|
|
279 |
|
|
|
280 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
281 |
|
|
|
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"));
|
|
|
291 |
|
|
|
292 |
//Test that null attributes throw an exception
|
|
|
293 |
var passed = false;
|
|
|
294 |
try{
|
|
|
295 |
flickrStore.hasAttribute(items[0], null);
|
|
|
296 |
}catch (e){
|
|
|
297 |
passed = true;
|
|
|
298 |
}
|
|
|
299 |
t.assertTrue(passed);
|
|
|
300 |
d.callback(true);
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
//Get one item...
|
|
|
304 |
flickrStore.fetch({ query: {tags: "animals"},
|
|
|
305 |
count: 1,
|
|
|
306 |
onComplete: onComplete,
|
|
|
307 |
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
|
|
|
308 |
});
|
|
|
309 |
return d; //Object
|
|
|
310 |
}
|
|
|
311 |
},
|
|
|
312 |
{
|
|
|
313 |
name: "ReadAPI: containsValue",
|
|
|
314 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
315 |
runTest: function(t) {
|
|
|
316 |
// summary:
|
|
|
317 |
// Simple test of the containsValue function of the store
|
|
|
318 |
// description:
|
|
|
319 |
// Simple test of the containsValue function of the store
|
|
|
320 |
|
|
|
321 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
322 |
|
|
|
323 |
var d = new doh.Deferred();
|
|
|
324 |
function onComplete(items){
|
|
|
325 |
t.is(1, items.length);
|
|
|
326 |
d.callback(true);
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
//Get one item...
|
|
|
330 |
flickrStore.fetch({ query: {tags: "animals"},
|
|
|
331 |
count: 1,
|
|
|
332 |
onComplete: onComplete,
|
|
|
333 |
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
|
|
|
334 |
});
|
|
|
335 |
return d; //Object
|
|
|
336 |
}
|
|
|
337 |
},
|
|
|
338 |
{
|
|
|
339 |
name: "ReadAPI: getAttributes",
|
|
|
340 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
341 |
runTest: function(t) {
|
|
|
342 |
// summary:
|
|
|
343 |
// Simple test of the getAttributes function of the store
|
|
|
344 |
// description:
|
|
|
345 |
// Simple test of the getAttributes function of the store
|
|
|
346 |
|
|
|
347 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
348 |
|
|
|
349 |
var d = new doh.Deferred();
|
|
|
350 |
function onComplete(items){
|
|
|
351 |
t.is(1, items.length);
|
|
|
352 |
t.assertTrue(flickrStore.isItem(items[0]));
|
|
|
353 |
|
|
|
354 |
var attributes = flickrStore.getAttributes(items[0]);
|
|
|
355 |
t.is(10, attributes.length);
|
|
|
356 |
d.callback(true);
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
//Get everything...
|
|
|
360 |
flickrStore.fetch({ count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
|
|
|
361 |
return d; //Object
|
|
|
362 |
}
|
|
|
363 |
},
|
|
|
364 |
function testReadAPI_getFeatures(t){
|
|
|
365 |
// summary:
|
|
|
366 |
// Simple test of the getFeatures function of the store
|
|
|
367 |
// description:
|
|
|
368 |
// Simple test of the getFeatures function of the store
|
|
|
369 |
|
|
|
370 |
var flickrStore = new dojox.data.FlickrStore();
|
|
|
371 |
|
|
|
372 |
var features = flickrStore.getFeatures();
|
|
|
373 |
var count = 0;
|
|
|
374 |
for(i in features){
|
|
|
375 |
t.assertTrue((i === "dojo.data.api.Read"));
|
|
|
376 |
count++;
|
|
|
377 |
}
|
|
|
378 |
t.assertTrue(count === 1);
|
|
|
379 |
},
|
|
|
380 |
function testReadAPI_functionConformance(t){
|
|
|
381 |
// summary:
|
|
|
382 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
383 |
// description:
|
|
|
384 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
385 |
|
|
|
386 |
var testStore = new dojox.data.FlickrStore();
|
|
|
387 |
var readApi = new dojo.data.api.Read();
|
|
|
388 |
var passed = true;
|
|
|
389 |
|
|
|
390 |
for(i in readApi){
|
|
|
391 |
if(i.toString().charAt(0) !== '_')
|
|
|
392 |
{
|
|
|
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")){
|
|
|
398 |
passed = false;
|
|
|
399 |
break;
|
|
|
400 |
}
|
|
|
401 |
}
|
|
|
402 |
}
|
|
|
403 |
}
|
|
|
404 |
t.assertTrue(passed);
|
|
|
405 |
}
|
|
|
406 |
]
|
|
|
407 |
);
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
}
|