Debian Codegraph @

dojox/data/tests/stores/WikipediaStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.WikipediaStore");
2
3 dojo.require("dojox.data.WikipediaStore");
4 dojo.require("dojo.data.api.Read");
5 dojo.require("dojo.data.api.Identity");
6
7 dojox.data.tests.stores.WikipediaStore.getStore = function(){
8 return new dojox.data.WikipediaStore();
9 };
10
11 dojox.data.tests.stores.WikipediaStore.error = function(t, d, errData){
12 // summary:
13 // Our shared error callback
14 d.errback(errData);
15 };
16
17 doh.register("dojox.data.tests.stores.WikipediaStore",[
18 {
19 name: "ReadAPI: containsValue",
20 timeout: 30000,
21 runTest: function(t) {
22 // summary:
23 // Verify the containsValue method functions correctly.
24 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
25 var d = new doh.Deferred();
26
27 // hopefully Wikipedia doesn't rename the Main Page!
28 ws.fetch({
29 query: { title: "Main Page" },
30 onComplete: function(items, length){
31 t.is(1, items.length);
32 t.t(ws.containsValue(items[0], "title", "Main Page"));
33 d.callback(true);
34 },
35 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
36 });
37 return d;
38 }
39 },
40 {
41 name: "ReadAPI: fetch (one)",
42 timeout: 30000,
43 runTest: function(t) {
44 // summary:
45 // Test a single page fetch from Wikipedia
46 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
47 var d = new doh.Deferred();
48
49 ws.fetch({
50 query: { title: "Main Page" },
51 onItem: function(item, request){
52 t.t(item.title && item.title.length && item.title.length > 0);
53 d.callback(true);
54 },
55 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, doh, d)
56 });
57 return d;
58 }
59 },
60 {
61 name: "ReadAPI: fetch (query 30)",
62 timeout: 30000,
63 runTest: function(t) {
64 // summary:
65 // Test a full text search from Wikipedia
66 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
67 var d = new doh.Deferred();
68
69 ws.fetch({
70 query: { action: "query", text: "dojo" },
71 count: 30,
72 onComplete: function(items, request){
73 t.is(30, items.length);
74 d.callback(true);
75 },
76 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
77 });
78 return d;
79 }
80 },
81 {
82 name: "ReadAPI: fetch (paged)",
83 timeout: 30000,
84 runTest: function(t) {
85 // summary:
86 // Test multiple fetches on a single full text search.
87 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
88 var d = new doh.Deferred();
89 var count = 0;
90
91 ws.fetch({
92 query: { action: "query", text: "dojo" },
93 count: 15,
94 onComplete: function(items, request){
95 t.is(15, items.length);
96 count = items.length;
97 ws.fetch({
98 query: { action: "query", text: "dojo" },
99 start: count+1,
100 count: 15,
101 onComplete: function(items, request){
102 t.is(30, count + items.length);
103 d.callback(true);
104 }
105 });
106 },
107 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
108 });
109 return d;
110 }
111 },
112 {
113 name: "ReadAPI: getAttributes",
114 timeout: 30000,
115 runTest: function(t) {
116 // summary:
117 // Verify the getAttributes method functions correctly
118 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
119 var d = new doh.Deferred();
120
121 ws.fetch({
122 query: { title: "Main Page" },
123 onComplete: function(items, request){
124 t.is(1, items.length);
125 t.t(ws.isItem(items[0]));
126 t.t(ws.getAttributes(items[0]).length > 0);
127 d.callback(true);
128 },
129 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
130 });
131 return d;
132 }
133 },
134 {
135 name: "ReadAPI: getLabel",
136 timeout: 30000,
137 runTest: function(t) {
138 // summary:
139 // Test that the store correctly sets a label.
140 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
141 var d = new doh.Deferred();
142
143 ws.fetch({
144 query: { action: "query", text: "dojo" },
145 count: 1,
146 onComplete: function(items, request){
147 t.is(1, items.length);
148 t.t(ws.getLabel(items[0]) !== null);
149 d.callback(true);
150 },
151 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
152 });
153 return d;
154 }
155 },
156 {
157 name: "ReadAPI: getLabelAttributes",
158 timeout: 30000,
159 runTest: function(t) {
160 // summary:
161 // Test that the store correctly enumerates the label attributes.
162 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
163 var d = new doh.Deferred();
164
165 ws.fetch({
166 query: { action: "query", text: "dojo" },
167 count: 1,
168 onComplete: function(items, request){
169 t.is(1, items.length);
170 var labels = ws.getLabelAttributes(items[0]);
171 t.t(dojo.isArray(labels));
172 t.is("title", labels[0]);
173 d.callback(true);
174 },
175 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
176 });
177 return d;
178 }
179 },
180 {
181 name: "ReadAPI: getValue",
182 timeout: 30000,
183 runTest: function(t) {
184 // summary:
185 // Verify that getValue does what it should.
186 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
187 var d = new doh.Deferred();
188
189 ws.fetch({
190 query: { title: "Main Page" },
191 onComplete: function(items, request){
192 t.is(1, items.length);
193 var i = items[0];
194 t.t(ws.getValue(i, "text") !== null);
195 t.t(ws.getValue(i, "links") !== null);
196 t.t(ws.getValue(i, "categories") !== null);
197 t.t(ws.getValue(i, "images") !== null);
198 d.callback(true);
199 },
200 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
201 });
202 return d;
203 }
204 },
205 {
206 name: "ReadAPI: getValues",
207 timeout: 30000,
208 runTest: function(t) {
209 // summary:
210 // Verify that getValues does what it should
211 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
212 var d = new doh.Deferred();
213
214 ws.fetch({
215 query: { title: "Main Page" },
216 onComplete: function(items, request){
217 t.is(1, items.length);
218 var i = items[0];
219 t.t(dojo.isArray(ws.getValues(i, "text")));
220 t.t(dojo.isArray(ws.getValues(i, "links")));
221 t.t(dojo.isArray(ws.getValues(i, "categories")));
222 t.t(dojo.isArray(ws.getValues(i, "images")));
223 d.callback(true);
224 },
225 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
226 });
227 return d;
228 }
229 },
230 {
231 name: "ReadAPI: hasAttribute",
232 timeout: 30000,
233 runTest: function(t) {
234 // summary:
235 // Verify the hasAttribute method
236 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
237 var d = new doh.Deferred();
238
239 ws.fetch({
240 query: { title: "Main Page" },
241 onComplete: function(items, request){
242 t.is(1, items.length);
243 var i = items[0];
244 t.t(i !== null);
245 t.t(ws.hasAttribute(i, "title"));
246 t.t(ws.hasAttribute(i, "text"));
247 t.t(ws.hasAttribute(i, "links"));
248 t.t(ws.hasAttribute(i, "categories"));
249 t.t(ws.hasAttribute(i, "images"));
250 d.callback(true);
251 },
252 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
253 });
254 return d;
255 }
256 },
257 {
258 name: "ReadAPI: isItem",
259 timeout: 30000,
260 runTest: function(t) {
261 // summary:
262 // Verify the isItem method
263 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
264 var d = new doh.Deferred();
265
266 ws.fetch({
267 query: { action: "query", text: "dojo" },
268 count: 10,
269 onComplete: function(items, request){
270 t.is(10, items.length);
271 for(var i=0; i<items.length; i++){
272 t.t(ws.isItem(items[i]));
273 }
274 d.callback(true);
275 },
276 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
277 });
278 return d;
279 }
280 },
281 {
282 name: "ReadAPI: isItemLoaded",
283 timeout: 30000,
284 runTest: function(t) {
285 // summary:
286 // Verify the isItemLoaded method
287 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
288 var d = new doh.Deferred();
289
290 ws.fetch({
291 query: { action: "query", text: "dojo" },
292 count: 5,
293 onComplete: function(items, request){
294 t.is(5, items.length);
295 ws.loadItem({
296 item: items[0],
297 onItem: function(loadedItem, loadedRequest){
298 t.t(ws.isItemLoaded(loadedItem));
299 t.f(ws.isItemLoaded(items[1])); // test an invalid item
300 d.callback(true);
301 }
302 });
303 },
304 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
305 });
306 return d;
307 }
308 },
309 {
310 name: "IdentityAPI: getIdentity",
311 timeout: 30000,
312 runTest: function(t) {
313 // summary:
314 // Verify the getIdentity method returns the correct value
315 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
316 var d = new doh.Deferred();
317
318 ws.fetch({
319 query: { title: "Main Page" },
320 onComplete: function(items, request){
321 t.is(1, items.length);
322 t.t(ws.isItem(items[0]));
323 t.t(ws.getIdentity(items[0]) === "Main Page");
324 d.callback(true);
325 },
326 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
327 });
328 return d;
329 }
330 },
331 {
332 name: "ReadAPI: loadItem",
333 timeout: 30000,
334 runTest: function(t) {
335 // summary:
336 // Verify the loadItem method
337 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
338 var d = new doh.Deferred();
339
340 ws.fetch({
341 query: { action: "query", text: "dojo" },
342 count: 5,
343 onComplete: function(items, request){
344 t.is(5, items.length);
345 t.t(ws.isItem(items[0]));
346 t.t(ws.getIdentityAttributes(items[0]).length > 0);
347 ws.loadItem({
348 item: items[0],
349 onItem: function(item, request){
350 t.t(ws.isItem(item));
351 t.t(ws.isItemLoaded(item));
352 d.callback(true);
353 }
354 });
355 },
356 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
357 });
358 return d;
359 }
360 },
361 {
362 name: "IdentityAPI: getIdentityAttributes",
363 timeout: 30000,
364 runTest: function(t) {
365 // summary:
366 // Verify the getIdentityAttributes method functions correctly
367 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
368 var d = new doh.Deferred();
369
370 ws.fetch({
371 query: { title: "Main Page" },
372 onComplete: function(items, request){
373 t.is(1, items.length);
374 t.t(ws.isItem(items[0]));
375 t.t(ws.getIdentityAttributes(items[0]).length > 0);
376 d.callback(true);
377 },
378 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
379 });
380 return d;
381 }
382 },
383 {
384 name: "IdentityAPI: fetchItemByIdentity",
385 timeout: 30000,
386 runTest: function(t) {
387 // summary:
388 // Verify the fetchItemByIdentity method works
389 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
390 var d = new doh.Deferred();
391
392 ws.fetch({
393 query: { title: "Main Page" },
394 onComplete: function(items, request){
395 var firstItem = items[0];
396 t.is(1, items.length);
397 t.t(ws.isItem(firstItem));
398 ws.fetchItemByIdentity({
399 identity: "Main Page",
400 onItem: function(item, request){
401 t.t(ws.isItem(item));
402 t.t(ws.getValue(firstItem, "title") === ws.getValue(item, "title"));
403 d.callback(true);
404 }
405 });
406 },
407 onError: dojo.partial(dojox.data.tests.stores.WikipediaStore.error, t, d)
408 });
409 return d;
410 }
411 },
412
413
414 function testIdentityAPI_getFeatures(t){
415 // summary:
416 // Test that the store correctly advertises its capabilities
417 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
418
419 var features = ws.getFeatures();
420 var count = 0;
421 for(var i in features){
422 if(i === "dojo.data.api.Read") count++;
423 if(i === "dojo.data.api.Identity") count++;
424 }
425 t.assertTrue(count === 2);
426 },
427
428 function testIdentityAPI_functionConformance(t){
429 // summary:
430 // Tests for Identity API conformance by checking to see that all declared functions are actual functions on the instances.
431 var ws = dojox.data.tests.stores.WikipediaStore.getStore();
432 var identityApi = new dojo.data.api.Identity();
433 var passed = true;
434 for(var i in identityApi){
435 if(i.toString().charAt(0) === '_'){
436 continue;
437 }
438 // check that every function defined in the Identity API is defined on the store
439 if(typeof identityApi[i] === "function"){
440 if(!(typeof ws[i] === "function")){
441 console.log("Error:" + i + " should be a function but is: " + typeof ws[i]);
442 passed = false;
443 break;
444 }
445 }
446 }
447 t.assertTrue(passed);
448 }
449 ]);