1 | // FIXME: this test assumes the existence of the global object "tests" |
---|
2 | define(["dojo", "doh", "require", "dojo/data/api/Read", "dojo/data/api/Identity", "dojo/date", "dojo/date/stamp"], function(dojo, doh, require) { |
---|
3 | |
---|
4 | dojo.getObject("data.readOnlyItemFileTestTemplates", true, tests); |
---|
5 | |
---|
6 | dojo.declare("tests.data.Wrapper", null, { |
---|
7 | // summary: |
---|
8 | // Simple class to use for typeMap in order to test out |
---|
9 | // 'falsy' values for _value. |
---|
10 | _wrapped: null, |
---|
11 | |
---|
12 | constructor: function(obj){ |
---|
13 | this._wrapped = obj; |
---|
14 | }, |
---|
15 | |
---|
16 | getValue: function() { |
---|
17 | return this._wrapped; |
---|
18 | }, |
---|
19 | |
---|
20 | setValue: function(obj) { |
---|
21 | this._wrapped = obj; |
---|
22 | }, |
---|
23 | |
---|
24 | toString: function(){ |
---|
25 | return "WRAPPER: [" + this._wrapped + "]"; |
---|
26 | } |
---|
27 | }); |
---|
28 | |
---|
29 | |
---|
30 | tests.data.readOnlyItemFileTestTemplates.registerTestsForDatastore = function(/* String */ datastoreClassName){ |
---|
31 | // summary: |
---|
32 | // Given the name of a datastore class to use, this function creates |
---|
33 | // a set of unit tests for that datastore, and registers the new test |
---|
34 | // group with the doh test framework. The new unit tests are based |
---|
35 | // on a set of "template" unit tests. |
---|
36 | var datastoreClass = dojo.getObject(datastoreClassName); |
---|
37 | var testTemplates = tests.data.readOnlyItemFileTestTemplates.testTemplates; |
---|
38 | var testsForDatastore = []; |
---|
39 | var makeNewTestFunction = function(template){ |
---|
40 | return function(t){return template.runTest(datastoreClass, t);}; |
---|
41 | }; |
---|
42 | for(var i = 0; i < testTemplates.length; ++i) { |
---|
43 | var testTemplate = testTemplates[i]; |
---|
44 | var test = {}; |
---|
45 | test.name = testTemplate.name; |
---|
46 | test.runTest = makeNewTestFunction(testTemplate); |
---|
47 | testsForDatastore.push(test); |
---|
48 | } |
---|
49 | var testGroupName = "IFSCommonTests: " + datastoreClassName; |
---|
50 | doh.register(testGroupName, testsForDatastore); |
---|
51 | }; |
---|
52 | |
---|
53 | |
---|
54 | //----------------------------------------------------- |
---|
55 | // testFile data-sets |
---|
56 | tests.data.readOnlyItemFileTestTemplates.getTestData = function(name){ |
---|
57 | var data = null; |
---|
58 | if(name === "countries"){ |
---|
59 | if(dojo.isBrowser){ |
---|
60 | data = {url: require.toUrl("tests/data/countries.json")}; |
---|
61 | }else{ |
---|
62 | data = {data: { |
---|
63 | identifier:"abbr", |
---|
64 | label:"name", |
---|
65 | items:[ |
---|
66 | {abbr:"ec", name:"Ecuador", capital:"Quito"}, |
---|
67 | {abbr:'eg', name:'Egypt', capital:'Cairo'}, |
---|
68 | {abbr:'sv', name:'El Salvador', capital:'San Salvador'}, |
---|
69 | {abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'}, |
---|
70 | {abbr:'er', name:'Eritrea', capital:'Asmara'}, |
---|
71 | {abbr:'ee', name:'Estonia', capital:'Tallinn'}, |
---|
72 | {abbr:'et', name:'Ethiopia', capital:'Addis Ababa'} |
---|
73 | ] |
---|
74 | } }; |
---|
75 | } |
---|
76 | }else if(name === "countries_withNull"){ |
---|
77 | if(dojo.isBrowser){ |
---|
78 | data = {url: require.toUrl("tests/data/countries_withNull.json")}; |
---|
79 | }else{ |
---|
80 | data = {data: { |
---|
81 | identifier:"abbr", |
---|
82 | items:[ |
---|
83 | {abbr:"ec", name:null, capital:"Quito"}, |
---|
84 | {abbr:'eg', name:null, capital:'Cairo'}, |
---|
85 | {abbr:'sv', name:'El Salvador', capital:'San Salvador'}, |
---|
86 | {abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'}, |
---|
87 | {abbr:'er', name:'Eritrea', capital:'Asmara'}, |
---|
88 | {abbr:'ee', name:null, capital:'Tallinn'}, |
---|
89 | {abbr:'et', name:'Ethiopia', capital:'Addis Ababa'} |
---|
90 | ] |
---|
91 | } }; |
---|
92 | } |
---|
93 | }else if(name === "countries_withoutid"){ |
---|
94 | if(dojo.isBrowser){ |
---|
95 | data = {url: require.toUrl("tests/data/countries_withoutid.json")}; |
---|
96 | }else{ |
---|
97 | data = {data: { |
---|
98 | label: "name", |
---|
99 | items:[ |
---|
100 | {abbr:"ec", name:null, capital:"Quito"}, |
---|
101 | {abbr:'eg', name:null, capital:'Cairo'}, |
---|
102 | {abbr:'sv', name:'El Salvador', capital:'San Salvador'}, |
---|
103 | {abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'}, |
---|
104 | {abbr:'er', name:'Eritrea', capital:'Asmara'}, |
---|
105 | {abbr:'ee', name:null, capital:'Tallinn'}, |
---|
106 | {abbr:'et', name:'Ethiopia', capital:'Addis Ababa'} |
---|
107 | ] |
---|
108 | } }; |
---|
109 | } |
---|
110 | }else if (name === "countries_withBoolean"){ |
---|
111 | if(dojo.isBrowser){ |
---|
112 | data = {url: require.toUrl("tests/data/countries_withBoolean.json")}; |
---|
113 | }else{ |
---|
114 | data = {data: { |
---|
115 | identifier:"abbr", |
---|
116 | items:[ |
---|
117 | {abbr:"ec", name:"Ecuador", capital:"Quito", real:true}, |
---|
118 | {abbr:'eg', name:'Egypt', capital:'Cairo', real:true}, |
---|
119 | {abbr:'sv', name:'El Salvador', capital:'San Salvador', real:true}, |
---|
120 | {abbr:'gq', name:'Equatorial Guinea', capital:'Malabo', real:true}, |
---|
121 | {abbr:'er', name:'Eritrea', capital:'Asmara', real:true}, |
---|
122 | {abbr:'ee', name:'Estonia', capital:'Tallinn', real:true}, |
---|
123 | {abbr:'et', name:'Ethiopia', capital:'Addis Ababa', real:true}, |
---|
124 | {abbr:'ut', name:'Utopia', capital:'Paradise', real:false} |
---|
125 | ] |
---|
126 | } }; |
---|
127 | } |
---|
128 | }else if (name === "countries_withDates"){ |
---|
129 | if(dojo.isBrowser){ |
---|
130 | data = {url: require.toUrl("tests/data/countries_withDates.json")}; |
---|
131 | }else{ |
---|
132 | data = {data: { |
---|
133 | identifier:"abbr", |
---|
134 | items:[ |
---|
135 | {abbr:"ec", name:"Ecuador", capital:"Quito"}, |
---|
136 | {abbr:'eg', name:'Egypt', capital:'Cairo'}, |
---|
137 | {abbr:'sv', name:'El Salvador', capital:'San Salvador'}, |
---|
138 | {abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'}, |
---|
139 | {abbr:'er', name:'Eritrea', capital:'Asmara', independence:{_type:'Date', _value:"1993-05-24T00:00:00Z"}}, // May 24, 1993, |
---|
140 | {abbr:'ee', name:'Estonia', capital:'Tallinn', independence:{_type:'Date', _value:"1991-08-20T00:00:00Z"}}, // August 20, 1991 |
---|
141 | {abbr:'et', name:'Ethiopia', capital:'Addis Ababa'} |
---|
142 | ] |
---|
143 | } }; |
---|
144 | } |
---|
145 | }else if (name === "geography_hierarchy_small"){ |
---|
146 | if(dojo.isBrowser){ |
---|
147 | data = {url: require.toUrl("tests/data/geography_hierarchy_small.json")}; |
---|
148 | }else{ |
---|
149 | data = {data: { |
---|
150 | items:[ |
---|
151 | { name:'Africa', countries:[ |
---|
152 | { name:'Egypt', capital:'Cairo' }, |
---|
153 | { name:'Kenya', capital:'Nairobi' }, |
---|
154 | { name:'Sudan', capital:'Khartoum' }]}, |
---|
155 | { name:'Australia', capital:'Canberra' }, |
---|
156 | { name:'North America', countries:[ |
---|
157 | { name:'Canada', population:'33 million', cities:[ |
---|
158 | { name:'Toronto', population:'2.5 million' }, |
---|
159 | { name:'Alberta', population:'1 million' } |
---|
160 | ]}, |
---|
161 | { name: 'United States of America', capital: 'Washington DC', states:[ |
---|
162 | { name: 'Missouri'}, |
---|
163 | { name: 'Arkansas'} |
---|
164 | ]} |
---|
165 | ]} |
---|
166 | ] |
---|
167 | }}; |
---|
168 | } |
---|
169 | }else if (name === "data_multitype"){ |
---|
170 | if(dojo.isBrowser){ |
---|
171 | data = {url: require.toUrl("tests/data/data_multitype.json")}; |
---|
172 | }else{ |
---|
173 | data = {data: { |
---|
174 | "identifier": "count", |
---|
175 | "label": "count", |
---|
176 | items: [ |
---|
177 | { count: 1, value: "true" }, |
---|
178 | { count: 2, value: true }, |
---|
179 | { count: 3, value: "false"}, |
---|
180 | { count: 4, value: false }, |
---|
181 | { count: 5, value: true }, |
---|
182 | { count: 6, value: true }, |
---|
183 | { count: 7, value: "true" }, |
---|
184 | { count: 8, value: "true" }, |
---|
185 | { count: 9, value: "false"}, |
---|
186 | { count: 10, value: false }, |
---|
187 | { count: 11, value: [false, false]}, |
---|
188 | { count: "12", value: [false, "true"]} |
---|
189 | ] |
---|
190 | } |
---|
191 | }; |
---|
192 | } |
---|
193 | }else if (name === "countries_references"){ |
---|
194 | if(dojo.isBrowser){ |
---|
195 | data = {url: require.toUrl("tests/data/countries_references.json")}; |
---|
196 | }else{ |
---|
197 | data = {data: { identifier: 'name', |
---|
198 | label: 'name', |
---|
199 | items: [ |
---|
200 | { name:'Africa', type:'continent', |
---|
201 | children:[{_reference:'Egypt'}, {_reference:'Kenya'}, {_reference:'Sudan'}] }, |
---|
202 | { name:'Egypt', type:'country' }, |
---|
203 | { name:'Kenya', type:'country', |
---|
204 | children:[{_reference:'Nairobi'}, {_reference:'Mombasa'}] }, |
---|
205 | { name:'Nairobi', type:'city' }, |
---|
206 | { name:'Mombasa', type:'city' }, |
---|
207 | { name:'Sudan', type:'country', |
---|
208 | children:{_reference:'Khartoum'} }, |
---|
209 | { name:'Khartoum', type:'city' }, |
---|
210 | { name:'Asia', type:'continent', |
---|
211 | children:[{_reference:'China'}, {_reference:'India'}, {_reference:'Russia'}, {_reference:'Mongolia'}] }, |
---|
212 | { name:'China', type:'country' }, |
---|
213 | { name:'India', type:'country' }, |
---|
214 | { name:'Russia', type:'country' }, |
---|
215 | { name:'Mongolia', type:'country' }, |
---|
216 | { name:'Australia', type:'continent', population:'21 million', |
---|
217 | children:{_reference:'Commonwealth of Australia'}}, |
---|
218 | { name:'Commonwealth of Australia', type:'country', population:'21 million'}, |
---|
219 | { name:'Europe', type:'continent', |
---|
220 | children:[{_reference:'Germany'}, {_reference:'France'}, {_reference:'Spain'}, {_reference:'Italy'}] }, |
---|
221 | { name:'Germany', type:'country' }, |
---|
222 | { name:'France', type:'country' }, |
---|
223 | { name:'Spain', type:'country' }, |
---|
224 | { name:'Italy', type:'country' }, |
---|
225 | { name:'North America', type:'continent', |
---|
226 | children:[{_reference:'Mexico'}, {_reference:'Canada'}, {_reference:'United States of America'}] }, |
---|
227 | { name:'Mexico', type:'country', population:'108 million', area:'1,972,550 sq km', |
---|
228 | children:[{_reference:'Mexico City'}, {_reference:'Guadalajara'}] }, |
---|
229 | { name:'Mexico City', type:'city', population:'19 million', timezone:'-6 UTC'}, |
---|
230 | { name:'Guadalajara', type:'city', population:'4 million', timezone:'-6 UTC' }, |
---|
231 | { name:'Canada', type:'country', population:'33 million', area:'9,984,670 sq km', |
---|
232 | children:[{_reference:'Ottawa'}, {_reference:'Toronto'}] }, |
---|
233 | { name:'Ottawa', type:'city', population:'0.9 million', timezone:'-5 UTC'}, |
---|
234 | { name:'Toronto', type:'city', population:'2.5 million', timezone:'-5 UTC' }, |
---|
235 | { name:'United States of America', type:'country' }, |
---|
236 | { name:'South America', type:'continent', |
---|
237 | children:[{_reference:'Brazil'}, {_reference:'Argentina'}] }, |
---|
238 | { name:'Brazil', type:'country', population:'186 million' }, |
---|
239 | { name:'Argentina', type:'country', population:'40 million' } |
---|
240 | ] |
---|
241 | } |
---|
242 | }; |
---|
243 | } |
---|
244 | } |
---|
245 | return data; |
---|
246 | }; |
---|
247 | |
---|
248 | //----------------------------------------------------- |
---|
249 | // testTemplates |
---|
250 | tests.data.readOnlyItemFileTestTemplates.testTemplates = [ |
---|
251 | { |
---|
252 | name: "Identity API: fetchItemByIdentity()", |
---|
253 | runTest: function(datastore, t){ |
---|
254 | // summary: |
---|
255 | // Simple test of the fetchItemByIdentity function of the store. |
---|
256 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
257 | |
---|
258 | var d = new doh.Deferred(); |
---|
259 | function onItem(item){ |
---|
260 | t.assertTrue(item !== null); |
---|
261 | if(item !== null){ |
---|
262 | var name = store.getValue(item,"name"); |
---|
263 | t.assertEqual(name, "El Salvador"); |
---|
264 | } |
---|
265 | d.callback(true); |
---|
266 | } |
---|
267 | function onError(errData){ |
---|
268 | t.assertTrue(false); |
---|
269 | d.errback(errData); |
---|
270 | } |
---|
271 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
272 | return d; // Deferred |
---|
273 | } |
---|
274 | }, |
---|
275 | { |
---|
276 | name: "Identity API: fetchItemByIdentity() preventCache", |
---|
277 | runTest: function(datastore, t){ |
---|
278 | // summary: |
---|
279 | // Simple test of the fetchItemByIdentity function of the store. |
---|
280 | var args = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
281 | args.urlPreventCache = true; |
---|
282 | var store = new datastore(args); |
---|
283 | |
---|
284 | var d = new doh.Deferred(); |
---|
285 | function onItem(item){ |
---|
286 | t.assertTrue(item !== null); |
---|
287 | if(item !== null){ |
---|
288 | var name = store.getValue(item,"name"); |
---|
289 | t.assertEqual(name, "El Salvador"); |
---|
290 | } |
---|
291 | d.callback(true); |
---|
292 | } |
---|
293 | function onError(errData){ |
---|
294 | t.assertTrue(false); |
---|
295 | d.errback(errData); |
---|
296 | } |
---|
297 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
298 | return d; // Deferred |
---|
299 | } |
---|
300 | }, |
---|
301 | { |
---|
302 | name: "Identity API: fetchItemByIdentity() notFound", |
---|
303 | runTest: function(datastore, t){ |
---|
304 | // summary: |
---|
305 | // Simple test of the fetchItemByIdentity function of the store. |
---|
306 | // description: |
---|
307 | // Simple test of the fetchItemByIdentity function of the store. |
---|
308 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
309 | |
---|
310 | var d = new doh.Deferred(); |
---|
311 | function onItem(item){ |
---|
312 | t.assertTrue(item === null); |
---|
313 | d.callback(true); |
---|
314 | } |
---|
315 | function onError(errData){ |
---|
316 | t.assertTrue(false); |
---|
317 | d.errback(errData); |
---|
318 | } |
---|
319 | store.fetchItemByIdentity({identity: "sv_not", onItem: onItem, onError: onError}); |
---|
320 | return d; // Deferred |
---|
321 | } |
---|
322 | }, |
---|
323 | { |
---|
324 | name: "Identity API: getIdentityAttributes()", |
---|
325 | runTest: function(datastore, t){ |
---|
326 | // summary: |
---|
327 | // Simple test of the getIdentityAttributes function. |
---|
328 | // description: |
---|
329 | // Simple test of the getIdentityAttributes function. |
---|
330 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
331 | |
---|
332 | var d = new doh.Deferred(); |
---|
333 | function onItem(item){ |
---|
334 | t.assertTrue(item !== null); |
---|
335 | var identifiers = store.getIdentityAttributes(item); |
---|
336 | t.assertTrue(dojo.isArray(identifiers)); |
---|
337 | t.assertEqual(1, identifiers.length); |
---|
338 | t.assertEqual("abbr", identifiers[0]); |
---|
339 | d.callback(true); |
---|
340 | } |
---|
341 | function onError(errData){ |
---|
342 | t.assertTrue(false); |
---|
343 | d.errback(errData); |
---|
344 | } |
---|
345 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
346 | return d; // Deferred |
---|
347 | } |
---|
348 | }, |
---|
349 | { |
---|
350 | name: "Identity API: fetchItemByIdentity() commentFilteredJson", |
---|
351 | runTest: function(datastore, t){ |
---|
352 | // summary: |
---|
353 | // Simple test of the fetchItemByIdentity function of the store. |
---|
354 | // description: |
---|
355 | // Simple test of the fetchItemByIdentity function of the store. |
---|
356 | // This tests loading a comment-filtered json file so that people using secure |
---|
357 | // data with this store can bypass the JavaSceipt hijack noted in Fortify's |
---|
358 | // paper. |
---|
359 | |
---|
360 | if(dojo.isBrowser){ |
---|
361 | var store = new datastore({url: require.toUrl("tests/data/countries_commentFiltered.json")}); |
---|
362 | |
---|
363 | var d = new doh.Deferred(); |
---|
364 | function onItem(item){ |
---|
365 | t.assertTrue(item !== null); |
---|
366 | var name = store.getValue(item,"name"); |
---|
367 | t.assertEqual(name, "El Salvador"); |
---|
368 | d.callback(true); |
---|
369 | } |
---|
370 | function onError(errData){ |
---|
371 | t.assertTrue(false); |
---|
372 | d.errback(errData); |
---|
373 | } |
---|
374 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
375 | return d; // Deferred |
---|
376 | } |
---|
377 | } |
---|
378 | }, |
---|
379 | { |
---|
380 | name: "Identity API: fetchItemByIdentity() nullValue", |
---|
381 | runTest: function(datastore, t){ |
---|
382 | // summary: |
---|
383 | // Simple test of the fetchItemByIdentity function of the store, checling a null value. |
---|
384 | // description: |
---|
385 | // Simple test of the fetchItemByIdentity function of the store, checking a null value. |
---|
386 | // This tests handling attributes in json that were defined as null properly. |
---|
387 | // Introduced because of tracker: #3153 |
---|
388 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withNull")); |
---|
389 | |
---|
390 | var d = new doh.Deferred(); |
---|
391 | function onItem(item){ |
---|
392 | t.assertTrue(item !== null); |
---|
393 | var name = store.getValue(item,"name"); |
---|
394 | t.assertEqual(name, null); |
---|
395 | d.callback(true); |
---|
396 | } |
---|
397 | function onError(errData){ |
---|
398 | t.assertTrue(false); |
---|
399 | d.errback(errData); |
---|
400 | } |
---|
401 | store.fetchItemByIdentity({identity: "ec", onItem: onItem, onError: onError}); |
---|
402 | return d; // Deferred |
---|
403 | } |
---|
404 | }, |
---|
405 | { |
---|
406 | name: "Identity API: fetchItemByIdentity() booleanValue", |
---|
407 | runTest: function(datastore, t){ |
---|
408 | // summary: |
---|
409 | // Simple test of the fetchItemByIdentity function of the store, checking a boolean value. |
---|
410 | // description: |
---|
411 | // Simple test of the fetchItemByIdentity function of the store, checking a boolean value. |
---|
412 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withBoolean")); |
---|
413 | |
---|
414 | var d = new doh.Deferred(); |
---|
415 | function onItem(item){ |
---|
416 | t.assertTrue(item !== null); |
---|
417 | var name = store.getValue(item,"name"); |
---|
418 | t.assertEqual(name, "Utopia"); |
---|
419 | var real = store.getValue(item,"real"); |
---|
420 | t.assertEqual(real, false); |
---|
421 | d.callback(true); |
---|
422 | } |
---|
423 | function onError(errData){ |
---|
424 | t.assertTrue(false); |
---|
425 | d.errback(errData); |
---|
426 | } |
---|
427 | store.fetchItemByIdentity({identity: "ut", onItem: onItem, onError: onError}); |
---|
428 | return d; // Deferred |
---|
429 | } |
---|
430 | }, |
---|
431 | { |
---|
432 | name: "Identity API: fetchItemByIdentity() withoutSpecifiedIdInData", |
---|
433 | runTest: function(datastore, t){ |
---|
434 | // summary: |
---|
435 | // Simple test of bug #4691, looking up something by assigned id, not one specified in the JSON data. |
---|
436 | // description: |
---|
437 | // Simple test of bug #4691, looking up something by assigned id, not one specified in the JSON data. |
---|
438 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withoutid")); |
---|
439 | |
---|
440 | var d = new doh.Deferred(); |
---|
441 | function onItem(item){ |
---|
442 | t.assertTrue(item !== null); |
---|
443 | var name = store.getValue(item,"name"); |
---|
444 | t.assertEqual(name, "El Salvador"); |
---|
445 | d.callback(true); |
---|
446 | } |
---|
447 | function onError(errData){ |
---|
448 | t.assertTrue(false); |
---|
449 | d.errback(errData); |
---|
450 | } |
---|
451 | store.fetchItemByIdentity({identity: "2", onItem: onItem, onError: onError}); |
---|
452 | return d; // Deferred |
---|
453 | } |
---|
454 | }, |
---|
455 | { |
---|
456 | name: "Identity API: fetchItemByIdentity() Object.prototype item identifier", |
---|
457 | runTest: function(datastore, t){ |
---|
458 | // summary: |
---|
459 | // Simple test of bug where store would raise an error |
---|
460 | // if the item identifier was the same as an Object property name. |
---|
461 | var data = {identifier: 'id', items: [{id: 'toString', value: 'aha'}]}; |
---|
462 | var store = new datastore({data: data}); |
---|
463 | var d = new doh.Deferred(); |
---|
464 | function onitem(item) { |
---|
465 | t.assertTrue(item.value == 'aha'); |
---|
466 | d.callback(true); |
---|
467 | } |
---|
468 | function onError(errData){ |
---|
469 | t.assertTrue(false); |
---|
470 | d.errback(errData); |
---|
471 | } |
---|
472 | store.fetchItemByIdentity({identity: 'toString', onItem: onitem, onError: onError}); |
---|
473 | return d; // Deferred |
---|
474 | } |
---|
475 | }, |
---|
476 | { |
---|
477 | name: "Identity API: fetchItemByIdentity() Object.prototype item identifier 2", |
---|
478 | runTest: function(datastore, t){ |
---|
479 | // summary: |
---|
480 | // Simple test of bug where store would raise an error |
---|
481 | // if the item identifier was the same as an Object property name. |
---|
482 | var data = {identifier: 'id', items: [{id: 'hasOwnProperty', value: 'yep'}]}; |
---|
483 | var store = new datastore({data: data}); |
---|
484 | var d = new doh.Deferred(); |
---|
485 | function onitem(item) { |
---|
486 | t.assertTrue(item.value == 'yep'); |
---|
487 | d.callback(true); |
---|
488 | } |
---|
489 | function onError(errData){ |
---|
490 | t.assertTrue(false); |
---|
491 | d.errback(errData); |
---|
492 | } |
---|
493 | store.fetchItemByIdentity({identity: 'hasOwnProperty', onItem: onitem, onError: onError}); |
---|
494 | return d; // Deferred |
---|
495 | } |
---|
496 | }, |
---|
497 | { |
---|
498 | name: "Identity API: fetchItemByIdentity() Object.prototype identity", |
---|
499 | runTest: function(datastore, t){ |
---|
500 | // summary: |
---|
501 | // Simple test of bug where fetchItemByIdentity would return |
---|
502 | // an object property. |
---|
503 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withoutid")); |
---|
504 | var d = new doh.Deferred(); |
---|
505 | function onItem(item){ |
---|
506 | t.assertTrue(item === null); |
---|
507 | d.callback(true); |
---|
508 | } |
---|
509 | function onError(errData){ |
---|
510 | t.assertTrue(false); |
---|
511 | d.errback(errData); |
---|
512 | } |
---|
513 | store.fetchItemByIdentity({identity: 'toString', onItem: onItem, onError: onError}); |
---|
514 | return d; // Deferred |
---|
515 | } |
---|
516 | }, |
---|
517 | { |
---|
518 | name: "Identity API: fetchItemByIdentity() Object.prototype identity 2", |
---|
519 | runTest: function(datastore, t){ |
---|
520 | // summary: |
---|
521 | // Simple test of bug where fetchItemByIdentity would return |
---|
522 | // an object property. |
---|
523 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withoutid")); |
---|
524 | var d = new doh.Deferred(); |
---|
525 | function onItem(item){ |
---|
526 | t.assertTrue(item === null); |
---|
527 | d.callback(true); |
---|
528 | } |
---|
529 | function onError(errData){ |
---|
530 | t.assertTrue(false); |
---|
531 | d.errback(errData); |
---|
532 | } |
---|
533 | store.fetchItemByIdentity({identity: 'hasOwnProperty', onItem: onItem, onError: onError}); |
---|
534 | return d; // Deferred |
---|
535 | } |
---|
536 | }, |
---|
537 | { |
---|
538 | name: "Identity API: getIdentity()", |
---|
539 | runTest: function(datastore, t){ |
---|
540 | // summary: |
---|
541 | // Simple test of the getIdentity function of the store. |
---|
542 | // description: |
---|
543 | // Simple test of the getIdentity function of the store. |
---|
544 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
545 | |
---|
546 | var d = new doh.Deferred(); |
---|
547 | function onItem(item){ |
---|
548 | t.assertTrue(item !== null); |
---|
549 | t.assertTrue(store.getIdentity(item) === "sv"); |
---|
550 | d.callback(true); |
---|
551 | } |
---|
552 | function onError(errData){ |
---|
553 | t.assertTrue(false); |
---|
554 | d.errback(errData); |
---|
555 | } |
---|
556 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
557 | return d; // Deferred |
---|
558 | } |
---|
559 | }, |
---|
560 | { |
---|
561 | name: "Identity API: getIdentity() withoutSpecifiedId", |
---|
562 | runTest: function(datastore, t){ |
---|
563 | // summary: |
---|
564 | // Simple test of the #4691 bug |
---|
565 | // description: |
---|
566 | // Simple test of the #4691 bug |
---|
567 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withoutid")); |
---|
568 | |
---|
569 | var d = new doh.Deferred(); |
---|
570 | function onItem(item, request){ |
---|
571 | t.assertTrue(item !== null); |
---|
572 | t.assertTrue(store.getIdentity(item) === 2); |
---|
573 | d.callback(true); |
---|
574 | } |
---|
575 | function onError(errData, request){ |
---|
576 | t.assertTrue(false); |
---|
577 | d.errback(errData); |
---|
578 | } |
---|
579 | store.fetch({ query:{abbr: "sv"}, onItem: onItem, onError: onError}); |
---|
580 | return d; // Deferred |
---|
581 | } |
---|
582 | }, |
---|
583 | { |
---|
584 | name: "Read API: fetch() all", |
---|
585 | runTest: function(datastore, t){ |
---|
586 | // summary: |
---|
587 | // Simple test of a basic fetch on ItemFileReadStore. |
---|
588 | // description: |
---|
589 | // Simple test of a basic fetch on ItemFileReadStore. |
---|
590 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
591 | |
---|
592 | var d = new doh.Deferred(); |
---|
593 | function completedAll(items, request){ |
---|
594 | t.is(7, items.length); |
---|
595 | d.callback(true); |
---|
596 | } |
---|
597 | function error(errData, request){ |
---|
598 | t.assertTrue(false); |
---|
599 | d.errback(errData); |
---|
600 | } |
---|
601 | |
---|
602 | //Get everything... |
---|
603 | store.fetch({ onComplete: completedAll, onError: error}); |
---|
604 | return d; |
---|
605 | } |
---|
606 | }, |
---|
607 | { |
---|
608 | name: "Read API: fetch() all failOk", |
---|
609 | runTest: function(datastore, t){ |
---|
610 | // summary: |
---|
611 | // Simple test of a basic fetch on ItemFileReadStore that fails quietly. |
---|
612 | // description: |
---|
613 | // Simple test of a basic fetch on ItemFileReadStore that fails quietly. |
---|
614 | if(dojo.isBrowser){ |
---|
615 | var storeParams = { |
---|
616 | url: "noSuchUrl", |
---|
617 | failOk: true |
---|
618 | }; |
---|
619 | var store = new datastore(storeParams); |
---|
620 | console.log(store); |
---|
621 | |
---|
622 | var d = new doh.Deferred(); |
---|
623 | var completedAll = function(items, request){ |
---|
624 | d.errback(new Error("Should not be here, should have failed load.")); |
---|
625 | }; |
---|
626 | var error = function(errData, request){ |
---|
627 | d.callback(true); |
---|
628 | }; |
---|
629 | |
---|
630 | //Get everything... |
---|
631 | store.fetch({ onComplete: completedAll, onError: error}); |
---|
632 | return d; |
---|
633 | } |
---|
634 | } |
---|
635 | }, |
---|
636 | { |
---|
637 | name: "Read API: fetch() abort", |
---|
638 | runTest: function(datastore, t){ |
---|
639 | // summary: |
---|
640 | // Simple test of a basic fetch abort on ItemFileReadStore. |
---|
641 | // description: |
---|
642 | // Simple test of a basic fetch abort on ItemFileReadStore. |
---|
643 | //Can only async abort in a browser, so disable this test from rhino |
---|
644 | if(dojo.isBrowser){ |
---|
645 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
646 | |
---|
647 | var d = new doh.Deferred(); |
---|
648 | var abortCalled = false; |
---|
649 | function completedAll(items, request){ |
---|
650 | t.is(7, items.length); |
---|
651 | if(abortCalled){ |
---|
652 | console.log("Made it to complete callback and abort was called. Problem."); |
---|
653 | d.errback(new Error("Should not be here.")); |
---|
654 | }else{ |
---|
655 | //We beat out calling abort, so this is okay. Timing. |
---|
656 | console.log("in onComplete and abort has not been called. Timing. This is okay."); |
---|
657 | d.callback(true); |
---|
658 | } |
---|
659 | } |
---|
660 | function error(errData, request){ |
---|
661 | //An abort should throw a cancel error, so we should |
---|
662 | //reach this. |
---|
663 | t.assertTrue(true); |
---|
664 | d.callback(true); |
---|
665 | } |
---|
666 | |
---|
667 | //Get everything... |
---|
668 | var req = store.fetch({ onComplete: completedAll, onError: error}); |
---|
669 | abortCalled=true; |
---|
670 | console.log("Calling abort."); |
---|
671 | req.abort(); |
---|
672 | return d; |
---|
673 | } |
---|
674 | } |
---|
675 | }, |
---|
676 | { |
---|
677 | name: "Read API: fetch() all (count === Infinity)", |
---|
678 | runTest: function(datastore, t){ |
---|
679 | // summary: |
---|
680 | // Simple test of a basic fetch on ItemFileReadStore and with a count of Infinity. |
---|
681 | // description: |
---|
682 | // Simple test of a basic fetch on ItemFileReadStore and with a count of Infinity. |
---|
683 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
684 | |
---|
685 | var d = new doh.Deferred(); |
---|
686 | function completedAll(items, request){ |
---|
687 | t.is(7, items.length); |
---|
688 | d.callback(true); |
---|
689 | } |
---|
690 | function error(errData, request){ |
---|
691 | t.assertTrue(false); |
---|
692 | d.errback(errData); |
---|
693 | } |
---|
694 | |
---|
695 | //Get everything... |
---|
696 | store.fetch({ onComplete: completedAll, onError: error, start: 0, count: Infinity}); |
---|
697 | return d; |
---|
698 | } |
---|
699 | }, |
---|
700 | { |
---|
701 | name: "Read API: fetch() all PreventCache", |
---|
702 | runTest: function(datastore, t){ |
---|
703 | // summary: |
---|
704 | // Simple test of a basic fetch on ItemFileReadStore. |
---|
705 | // description: |
---|
706 | // Simple test of a basic fetch on ItemFileReadStore. |
---|
707 | var args = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
708 | args.urlPreventCache = true; |
---|
709 | var store = new datastore(args); |
---|
710 | |
---|
711 | var d = new doh.Deferred(); |
---|
712 | function completedAll(items, request){ |
---|
713 | t.is(7, items.length); |
---|
714 | d.callback(true); |
---|
715 | } |
---|
716 | function error(errData, request){ |
---|
717 | t.assertTrue(false); |
---|
718 | d.errback(errData); |
---|
719 | } |
---|
720 | |
---|
721 | //Get everything... |
---|
722 | store.fetch({ onComplete: completedAll, onError: error}); |
---|
723 | return d; |
---|
724 | } |
---|
725 | }, |
---|
726 | { |
---|
727 | name: "Read API: fetch() one", |
---|
728 | runTest: function(datastore, t){ |
---|
729 | // summary: |
---|
730 | // Simple test of a basic fetch on ItemFileReadStore of a single item. |
---|
731 | // description: |
---|
732 | // Simple test of a basic fetch on ItemFileReadStore of a single item. |
---|
733 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
734 | |
---|
735 | var d = new doh.Deferred(); |
---|
736 | function onComplete(items, request){ |
---|
737 | t.assertEqual(items.length, 1); |
---|
738 | d.callback(true); |
---|
739 | } |
---|
740 | function onError(errData, request){ |
---|
741 | t.assertTrue(false); |
---|
742 | d.errback(errData); |
---|
743 | } |
---|
744 | store.fetch({ query: {abbr: "ec"}, |
---|
745 | onComplete: onComplete, |
---|
746 | onError: onError |
---|
747 | }); |
---|
748 | return d; |
---|
749 | } |
---|
750 | }, |
---|
751 | { |
---|
752 | name: "Read API: fetch() shallow", |
---|
753 | runTest: function(datastore, t){ |
---|
754 | // summary: |
---|
755 | // Simple test of a basic fetch on ItemFileReadStore of only toplevel items |
---|
756 | // description: |
---|
757 | // Simple test of a basic fetch on ItemFileReadStore of only toplevel items. |
---|
758 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small")); |
---|
759 | |
---|
760 | var d = new doh.Deferred(); |
---|
761 | function onComplete(items, request){ |
---|
762 | t.assertEqual(items.length, 2); |
---|
763 | d.callback(true); |
---|
764 | } |
---|
765 | function onError(errData, request){ |
---|
766 | t.assertTrue(false); |
---|
767 | d.errback(errData); |
---|
768 | } |
---|
769 | //Find all items starting with A, only toplevel (root) items. |
---|
770 | store.fetch({ query: {name: "A*"}, |
---|
771 | onComplete: onComplete, |
---|
772 | onError: onError |
---|
773 | }); |
---|
774 | return d; |
---|
775 | } |
---|
776 | }, |
---|
777 | { |
---|
778 | name: "Read API: fetch() Multiple", |
---|
779 | runTest: function(datastore, t){ |
---|
780 | // summary: |
---|
781 | // Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load. |
---|
782 | // description: |
---|
783 | // Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load. |
---|
784 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small")); |
---|
785 | |
---|
786 | var d = new doh.Deferred(); |
---|
787 | var done = [false, false]; |
---|
788 | |
---|
789 | function onCompleteOne(items, request){ |
---|
790 | done[0] = true; |
---|
791 | t.assertEqual(items.length, 2); |
---|
792 | if(done[0] && done[1]){ |
---|
793 | d.callback(true); |
---|
794 | } |
---|
795 | } |
---|
796 | function onCompleteTwo(items, request){ |
---|
797 | done[1] = true; |
---|
798 | if(done[0] && done[1]){ |
---|
799 | d.callback(true); |
---|
800 | } |
---|
801 | } |
---|
802 | function onError(errData, request){ |
---|
803 | t.assertTrue(false); |
---|
804 | d.errback(errData); |
---|
805 | } |
---|
806 | //Find all items starting with A, only toplevel (root) items. |
---|
807 | store.fetch({ query: {name: "A*"}, |
---|
808 | onComplete: onCompleteOne, |
---|
809 | onError: onError |
---|
810 | }); |
---|
811 | |
---|
812 | //Find all items starting with A, only toplevel (root) items. |
---|
813 | store.fetch({ query: {name: "N*"}, |
---|
814 | onComplete: onCompleteTwo, |
---|
815 | onError: onError |
---|
816 | }); |
---|
817 | |
---|
818 | return d; |
---|
819 | } |
---|
820 | }, |
---|
821 | { |
---|
822 | name: "Read API: fetch() MultipleMixedFetch", |
---|
823 | runTest: function(datastore, t){ |
---|
824 | // summary: |
---|
825 | // Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load. |
---|
826 | // description: |
---|
827 | // Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load. |
---|
828 | // Tests an item fetch and an identity fetch. |
---|
829 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
830 | |
---|
831 | var d = new doh.Deferred(); |
---|
832 | var done = [false, false]; |
---|
833 | |
---|
834 | function onComplete(items, request){ |
---|
835 | done[0] = true; |
---|
836 | t.assertEqual(items.length, 1); |
---|
837 | if(done[0] && done[1]){ |
---|
838 | d.callback(true); |
---|
839 | } |
---|
840 | } |
---|
841 | function onItem(item){ |
---|
842 | done[1] = true; |
---|
843 | t.assertTrue(item !== null); |
---|
844 | var name = store.getValue(item,"name"); |
---|
845 | t.assertEqual(name, "El Salvador"); |
---|
846 | |
---|
847 | if(done[0] && done[1]){ |
---|
848 | d.callback(true); |
---|
849 | } |
---|
850 | } |
---|
851 | function onError(errData){ |
---|
852 | t.assertTrue(false); |
---|
853 | d.errback(errData); |
---|
854 | } |
---|
855 | |
---|
856 | //Find all items starting with A, only toplevel (root) items. |
---|
857 | store.fetch({ query: {name: "El*"}, |
---|
858 | onComplete: onComplete, |
---|
859 | onError: onError |
---|
860 | }); |
---|
861 | |
---|
862 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
863 | return d; |
---|
864 | } |
---|
865 | }, |
---|
866 | { |
---|
867 | name: "Read API: fetch() deep", |
---|
868 | runTest: function(datastore, t){ |
---|
869 | // summary: |
---|
870 | // Simple test of a basic fetch on ItemFileReadStore of all items (including children (nested)) |
---|
871 | // description: |
---|
872 | // Simple test of a basic fetch on ItemFileReadStore of all items (including children (nested)) |
---|
873 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small")); |
---|
874 | |
---|
875 | var d = new doh.Deferred(); |
---|
876 | function onComplete(items, request){ |
---|
877 | t.assertEqual(items.length, 4); |
---|
878 | d.callback(true); |
---|
879 | } |
---|
880 | function onError(errData, request){ |
---|
881 | t.assertTrue(false); |
---|
882 | d.errback(errData); |
---|
883 | } |
---|
884 | //Find all items starting with A, including child (nested) items. |
---|
885 | store.fetch({ query: {name: "A*"}, |
---|
886 | onComplete: onComplete, |
---|
887 | onError: onError, |
---|
888 | queryOptions: {deep:true} |
---|
889 | }); |
---|
890 | return d; |
---|
891 | } |
---|
892 | }, |
---|
893 | { |
---|
894 | name: "Read API: fetch() hierarchy off", |
---|
895 | runTest: function(datastore, t){ |
---|
896 | // summary: |
---|
897 | // Simple test of a basic fetch on ItemFileReadStore of all items with hierarchy disabled |
---|
898 | // This should turn off processing child objects as data store items. It will still process |
---|
899 | // references and type maps. |
---|
900 | // description: |
---|
901 | // Simple test of a basic fetch on ItemFileReadStore of all items with hierarchy disabled |
---|
902 | // This should turn off processing child objects as data store items. It will still process |
---|
903 | // references and type maps. |
---|
904 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small")); |
---|
905 | |
---|
906 | //Set this as hierarchy off before fetch to make sure it traps and configs right. |
---|
907 | store.hierarchical = false; |
---|
908 | |
---|
909 | var d = new doh.Deferred(); |
---|
910 | function onComplete(items, request){ |
---|
911 | //With hierarchy off, this should only match 2, as only two data store items |
---|
912 | //will be quertied |
---|
913 | t.assertEqual(items.length, 2); |
---|
914 | var i; |
---|
915 | var passed = true; |
---|
916 | for(i = 0; i < items.length; i++){ |
---|
917 | var countries = store.getValues(items[i], "countries"); |
---|
918 | if(countries){ |
---|
919 | var j; |
---|
920 | //Make sure none of the child objects were processed into items. |
---|
921 | for(j = 0; j<countries.length; j++){ |
---|
922 | passed = !store.isItem(countries[j]); |
---|
923 | if(!passed){ |
---|
924 | break; |
---|
925 | } |
---|
926 | } |
---|
927 | } |
---|
928 | if(!passed){ |
---|
929 | break; |
---|
930 | } |
---|
931 | } |
---|
932 | if(!passed){ |
---|
933 | d.errback(new Error("Located a child item with hierarchy off and no references in the data. Error.")); |
---|
934 | }else{ |
---|
935 | d.callback(true); |
---|
936 | } |
---|
937 | } |
---|
938 | function onError(errData, request){ |
---|
939 | t.assertTrue(false); |
---|
940 | d.errback(errData); |
---|
941 | } |
---|
942 | //Find all items starting with A, including child (nested) items. |
---|
943 | store.fetch({ query: {name: "A*"}, |
---|
944 | onComplete: onComplete, |
---|
945 | onError: onError, |
---|
946 | queryOptions: {deep:true} |
---|
947 | }); |
---|
948 | return d; |
---|
949 | } |
---|
950 | }, |
---|
951 | { |
---|
952 | name: "Read API: fetch() hierarchy off refs still parse", |
---|
953 | runTest: function(datastore, t){ |
---|
954 | // summary: |
---|
955 | // Simple test of a basic fetch on ItemFileReadStore of all items with hierarchy disabled |
---|
956 | // This should turn off processing child objects as data store items. It will still process |
---|
957 | // references and type maps. |
---|
958 | // description: |
---|
959 | // Simple test of a basic fetch on ItemFileReadStore of all items with hierarchy disabled |
---|
960 | // This should turn off processing child objects as data store items. It will still process |
---|
961 | // references and type maps. |
---|
962 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_references")); |
---|
963 | |
---|
964 | //Set this as hierarchy off before fetch to make sure it traps and configs right. |
---|
965 | store.hierarchical = false; |
---|
966 | |
---|
967 | var d = new doh.Deferred(); |
---|
968 | function onComplete(items, request){ |
---|
969 | //With hierarchy off, this should only match 2, as only two data store items |
---|
970 | //will be quertied |
---|
971 | t.assertEqual(items.length, 4); |
---|
972 | var i; |
---|
973 | var passed = true; |
---|
974 | for(i = 0; i < items.length; i++){ |
---|
975 | var countries = store.getValues(items[i], "children"); |
---|
976 | if(countries){ |
---|
977 | var j; |
---|
978 | //Make sure none of the child objects were processed into items. |
---|
979 | for(j = 0; j<countries.length; j++){ |
---|
980 | passed = store.isItem(countries[j]); |
---|
981 | if(!passed){ |
---|
982 | break; |
---|
983 | } |
---|
984 | } |
---|
985 | } |
---|
986 | if(!passed){ |
---|
987 | break; |
---|
988 | } |
---|
989 | } |
---|
990 | if(!passed){ |
---|
991 | d.errback(new Error("Found a non-child item in a reference list in a references based input. Error.")); |
---|
992 | }else{ |
---|
993 | d.callback(true); |
---|
994 | } |
---|
995 | } |
---|
996 | function onError(errData, request){ |
---|
997 | t.assertTrue(false); |
---|
998 | d.errback(errData); |
---|
999 | } |
---|
1000 | //Find all items starting with A, including child (nested) items. |
---|
1001 | store.fetch({ query: {name: "A*"}, |
---|
1002 | onComplete: onComplete, |
---|
1003 | onError: onError, |
---|
1004 | queryOptions: {deep:true} |
---|
1005 | }); |
---|
1006 | return d; |
---|
1007 | } |
---|
1008 | }, |
---|
1009 | { |
---|
1010 | name: "Read API: fetch() one_commentFilteredJson", |
---|
1011 | runTest: function(datastore, t){ |
---|
1012 | // summary: |
---|
1013 | // Simple test of a basic fetch on ItemFileReadStore of a single item. |
---|
1014 | // description: |
---|
1015 | // Simple test of a basic fetch on ItemFileReadStore of a single item. |
---|
1016 | // This tests loading a comment-filtered json file so that people using secure |
---|
1017 | // data with this store can bypass the JavaSceipt hijack noted in Fortify's |
---|
1018 | // paper. |
---|
1019 | if(dojo.isBrowser){ |
---|
1020 | var store = new datastore({url: require.toUrl("tests/data/countries_commentFiltered.json")}); |
---|
1021 | |
---|
1022 | var d = new doh.Deferred(); |
---|
1023 | function onComplete(items, request){ |
---|
1024 | t.assertEqual(items.length, 1); |
---|
1025 | d.callback(true); |
---|
1026 | } |
---|
1027 | function onError(errData, request){ |
---|
1028 | t.assertTrue(false); |
---|
1029 | d.errback(errData); |
---|
1030 | } |
---|
1031 | store.fetch({ query: {abbr: "ec"}, |
---|
1032 | onComplete: onComplete, |
---|
1033 | onError: onError |
---|
1034 | }); |
---|
1035 | return d; |
---|
1036 | } |
---|
1037 | } |
---|
1038 | }, |
---|
1039 | { |
---|
1040 | name: "Read API: fetch() withNull", |
---|
1041 | runTest: function(datastore, t){ |
---|
1042 | // summary: |
---|
1043 | // Simple test of a basic fetch on ItemFileReadStore of a single item where some attributes are null. |
---|
1044 | // description: |
---|
1045 | // Simple test of a basic fetch on ItemFileReadStore of a single item where some attributes are null. |
---|
1046 | // Introduced because of tracker: #3153 |
---|
1047 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withNull")); |
---|
1048 | |
---|
1049 | var d = new doh.Deferred(); |
---|
1050 | function onComplete(items, request){ |
---|
1051 | t.assertEqual(4, items.length); |
---|
1052 | d.callback(true); |
---|
1053 | } |
---|
1054 | function onError(errData, request){ |
---|
1055 | t.assertTrue(false); |
---|
1056 | d.errback(errData); |
---|
1057 | } |
---|
1058 | store.fetch({ query: {name: "E*"}, |
---|
1059 | onComplete: onComplete, |
---|
1060 | onError: onError |
---|
1061 | }); |
---|
1062 | return d; |
---|
1063 | } |
---|
1064 | }, |
---|
1065 | { |
---|
1066 | name: "Read API: fetch() all_streaming", |
---|
1067 | runTest: function(datastore, t){ |
---|
1068 | // summary: |
---|
1069 | // Simple test of a basic fetch on ItemFileReadStore. |
---|
1070 | // description: |
---|
1071 | // Simple test of a basic fetch on ItemFileReadStore. |
---|
1072 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1073 | |
---|
1074 | var d = new doh.Deferred(); |
---|
1075 | count = 0; |
---|
1076 | |
---|
1077 | function onBegin(size, requestObj){ |
---|
1078 | t.assertEqual(size, 7); |
---|
1079 | } |
---|
1080 | function onItem(item, requestObj){ |
---|
1081 | t.assertTrue(store.isItem(item)); |
---|
1082 | count++; |
---|
1083 | } |
---|
1084 | function onComplete(items, request){ |
---|
1085 | t.assertEqual(count, 7); |
---|
1086 | t.assertTrue(items === null); |
---|
1087 | d.callback(true); |
---|
1088 | } |
---|
1089 | function onError(errData, request){ |
---|
1090 | t.assertTrue(false); |
---|
1091 | d.errback(errData); |
---|
1092 | } |
---|
1093 | |
---|
1094 | //Get everything... |
---|
1095 | store.fetch({ onBegin: onBegin, |
---|
1096 | onItem: onItem, |
---|
1097 | onComplete: onComplete, |
---|
1098 | onError: onError |
---|
1099 | }); |
---|
1100 | return d; |
---|
1101 | } |
---|
1102 | }, |
---|
1103 | { |
---|
1104 | name: "Read API: fetch() paging", |
---|
1105 | runTest: function(datastore, t){ |
---|
1106 | // summary: |
---|
1107 | // Test of multiple fetches on a single result. Paging, if you will. |
---|
1108 | // description: |
---|
1109 | // Test of multiple fetches on a single result. Paging, if you will. |
---|
1110 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1111 | |
---|
1112 | var d = new doh.Deferred(); |
---|
1113 | function dumpFirstFetch(items, request){ |
---|
1114 | t.assertEqual(items.length, 5); |
---|
1115 | request.start = 3; |
---|
1116 | request.count = 1; |
---|
1117 | request.onComplete = dumpSecondFetch; |
---|
1118 | store.fetch(request); |
---|
1119 | } |
---|
1120 | |
---|
1121 | function dumpSecondFetch(items, request){ |
---|
1122 | t.assertEqual(items.length, 1); |
---|
1123 | request.start = 0; |
---|
1124 | request.count = 5; |
---|
1125 | request.onComplete = dumpThirdFetch; |
---|
1126 | store.fetch(request); |
---|
1127 | } |
---|
1128 | |
---|
1129 | function dumpThirdFetch(items, request){ |
---|
1130 | t.assertEqual(items.length, 5); |
---|
1131 | request.start = 2; |
---|
1132 | request.count = 20; |
---|
1133 | request.onComplete = dumpFourthFetch; |
---|
1134 | store.fetch(request); |
---|
1135 | } |
---|
1136 | |
---|
1137 | function dumpFourthFetch(items, request){ |
---|
1138 | t.assertEqual(items.length, 5); |
---|
1139 | request.start = 9; |
---|
1140 | request.count = 100; |
---|
1141 | request.onComplete = dumpFifthFetch; |
---|
1142 | store.fetch(request); |
---|
1143 | } |
---|
1144 | |
---|
1145 | function dumpFifthFetch(items, request){ |
---|
1146 | t.assertEqual(items.length, 0); |
---|
1147 | request.start = 2; |
---|
1148 | request.count = 20; |
---|
1149 | request.onComplete = dumpSixthFetch; |
---|
1150 | store.fetch(request); |
---|
1151 | } |
---|
1152 | |
---|
1153 | function dumpSixthFetch(items, request){ |
---|
1154 | t.assertEqual(items.length, 5); |
---|
1155 | d.callback(true); |
---|
1156 | } |
---|
1157 | |
---|
1158 | function completed(items, request){ |
---|
1159 | t.assertEqual(items.length, 7); |
---|
1160 | request.start = 1; |
---|
1161 | request.count = 5; |
---|
1162 | request.onComplete = dumpFirstFetch; |
---|
1163 | store.fetch(request); |
---|
1164 | } |
---|
1165 | |
---|
1166 | function error(errData, request){ |
---|
1167 | t.assertTrue(false); |
---|
1168 | d.errback(errData); |
---|
1169 | } |
---|
1170 | store.fetch({onComplete: completed, onError: error}); |
---|
1171 | return d; |
---|
1172 | } |
---|
1173 | }, |
---|
1174 | { |
---|
1175 | name: "Read API: fetch() with MultiType Match", |
---|
1176 | runTest: function(datastore, t){ |
---|
1177 | // summary: |
---|
1178 | // Simple test of a basic fetch againct an attribute that has different types for the value across items |
---|
1179 | // description: |
---|
1180 | // Simple test of a basic fetch againct an attribute that has different types for the value across items |
---|
1181 | // Introduced because of tracker: #4931 |
---|
1182 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("data_multitype")); |
---|
1183 | |
---|
1184 | var d = new doh.Deferred(); |
---|
1185 | function onComplete(items, request){ |
---|
1186 | t.assertEqual(4, items.length); |
---|
1187 | d.callback(true); |
---|
1188 | } |
---|
1189 | function onError(errData, request){ |
---|
1190 | t.assertTrue(false); |
---|
1191 | d.errback(errData); |
---|
1192 | } |
---|
1193 | store.fetch({ query: {count: "1*"}, |
---|
1194 | onComplete: onComplete, |
---|
1195 | onError: onError |
---|
1196 | }); |
---|
1197 | return d; |
---|
1198 | } |
---|
1199 | }, |
---|
1200 | { |
---|
1201 | name: "Read API: fetch() with RegExp Match", |
---|
1202 | runTest: function(datastore, t){ |
---|
1203 | // summary: |
---|
1204 | // Simple test of a basic fetch using a RegExp works with IFRS |
---|
1205 | // description: |
---|
1206 | // Simple test of a basic fetch using a RegExp works with IFRS |
---|
1207 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("data_multitype")); |
---|
1208 | |
---|
1209 | var d = new doh.Deferred(); |
---|
1210 | function onComplete(items, request){ |
---|
1211 | t.assertEqual(4, items.length); |
---|
1212 | d.callback(true); |
---|
1213 | } |
---|
1214 | function onError(errData, request){ |
---|
1215 | t.assertTrue(false); |
---|
1216 | d.errback(errData); |
---|
1217 | } |
---|
1218 | store.fetch({ query: {count: new RegExp("^1.*$", "gi")}, |
---|
1219 | onComplete: onComplete, |
---|
1220 | onError: onError |
---|
1221 | }); |
---|
1222 | return d; |
---|
1223 | } |
---|
1224 | }, |
---|
1225 | { |
---|
1226 | name: "Read API: fetch() with RegExp Match Inline", |
---|
1227 | runTest: function(datastore, t){ |
---|
1228 | // summary: |
---|
1229 | // Simple test of a basic fetch using a RegExp works with IFRS |
---|
1230 | // description: |
---|
1231 | // Simple test of a basic fetch using a RegExp works with IFRS |
---|
1232 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("data_multitype")); |
---|
1233 | |
---|
1234 | var d = new doh.Deferred(); |
---|
1235 | function onComplete(items, request){ |
---|
1236 | t.assertEqual(4, items.length); |
---|
1237 | d.callback(true); |
---|
1238 | } |
---|
1239 | function onError(errData, request){ |
---|
1240 | t.assertTrue(false); |
---|
1241 | d.errback(errData); |
---|
1242 | } |
---|
1243 | store.fetch({ query: {count: /^1.*$/gi}, |
---|
1244 | onComplete: onComplete, |
---|
1245 | onError: onError |
---|
1246 | }); |
---|
1247 | return d; |
---|
1248 | } |
---|
1249 | }, |
---|
1250 | { |
---|
1251 | name: "Read API: fetch() with MultiType, MultiValue Match", |
---|
1252 | runTest: function(datastore, t){ |
---|
1253 | // summary: |
---|
1254 | // Simple test of a basic fetch againct an attribute that has different types for the value across items |
---|
1255 | // description: |
---|
1256 | // Simple test of a basic fetch againct an attribute that has different types for the value across items |
---|
1257 | // Introduced because of tracker: #4931 |
---|
1258 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("data_multitype")); |
---|
1259 | |
---|
1260 | var d = new doh.Deferred(); |
---|
1261 | function onComplete(items, request){ |
---|
1262 | t.assertEqual(7, items.length); |
---|
1263 | d.callback(true); |
---|
1264 | } |
---|
1265 | function onError(errData, request){ |
---|
1266 | t.assertTrue(false); |
---|
1267 | d.errback(errData); |
---|
1268 | } |
---|
1269 | store.fetch({ query: {value: "true"}, |
---|
1270 | onComplete: onComplete, |
---|
1271 | onError: onError |
---|
1272 | }); |
---|
1273 | return d; |
---|
1274 | } |
---|
1275 | }, |
---|
1276 | { |
---|
1277 | name: "Read API: getLabel()", |
---|
1278 | runTest: function(datastore, t){ |
---|
1279 | // summary: |
---|
1280 | // Simple test of the getLabel function against a store set that has a label defined. |
---|
1281 | // description: |
---|
1282 | // Simple test of the getLabel function against a store set that has a label defined. |
---|
1283 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1284 | |
---|
1285 | var d = new doh.Deferred(); |
---|
1286 | function onComplete(items, request){ |
---|
1287 | t.assertEqual(items.length, 1); |
---|
1288 | var label = store.getLabel(items[0]); |
---|
1289 | t.assertTrue(label !== null); |
---|
1290 | t.assertEqual("Ecuador", label); |
---|
1291 | d.callback(true); |
---|
1292 | } |
---|
1293 | function onError(errData, request){ |
---|
1294 | t.assertTrue(false); |
---|
1295 | d.errback(errData); |
---|
1296 | } |
---|
1297 | store.fetch({ query: {abbr: "ec"}, |
---|
1298 | onComplete: onComplete, |
---|
1299 | onError: onError |
---|
1300 | }); |
---|
1301 | return d; |
---|
1302 | } |
---|
1303 | }, |
---|
1304 | { |
---|
1305 | name: "Read API: getLabelAttributes()", |
---|
1306 | runTest: function(datastore, t){ |
---|
1307 | // summary: |
---|
1308 | // Simple test of the getLabelAttributes function against a store set that has a label defined. |
---|
1309 | // description: |
---|
1310 | // Simple test of the getLabelAttributes function against a store set that has a label defined. |
---|
1311 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1312 | |
---|
1313 | var d = new doh.Deferred(); |
---|
1314 | function onComplete(items, request){ |
---|
1315 | t.assertEqual(items.length, 1); |
---|
1316 | var labelList = store.getLabelAttributes(items[0]); |
---|
1317 | t.assertTrue(dojo.isArray(labelList)); |
---|
1318 | t.assertEqual("name", labelList[0]); |
---|
1319 | d.callback(true); |
---|
1320 | } |
---|
1321 | function onError(errData, request){ |
---|
1322 | t.assertTrue(false); |
---|
1323 | d.errback(errData); |
---|
1324 | } |
---|
1325 | store.fetch({ query: {abbr: "ec"}, |
---|
1326 | onComplete: onComplete, |
---|
1327 | onError: onError |
---|
1328 | }); |
---|
1329 | return d; |
---|
1330 | } |
---|
1331 | }, |
---|
1332 | { |
---|
1333 | name: "Read API: getValue()", |
---|
1334 | runTest: function(datastore, t){ |
---|
1335 | // summary: |
---|
1336 | // Simple test of the getValue function of the store. |
---|
1337 | // description: |
---|
1338 | // Simple test of the getValue function of the store. |
---|
1339 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1340 | |
---|
1341 | var d = new doh.Deferred(); |
---|
1342 | function onItem(item){ |
---|
1343 | t.assertTrue(item !== null); |
---|
1344 | var name = store.getValue(item,"name"); |
---|
1345 | t.assertTrue(name === "El Salvador"); |
---|
1346 | d.callback(true); |
---|
1347 | } |
---|
1348 | function onError(errData){ |
---|
1349 | t.assertTrue(false); |
---|
1350 | d.errback(errData); |
---|
1351 | } |
---|
1352 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
1353 | return d; // Deferred |
---|
1354 | } |
---|
1355 | }, |
---|
1356 | { |
---|
1357 | name: "Read API: getValues()", |
---|
1358 | runTest: function(datastore, t){ |
---|
1359 | // summary: |
---|
1360 | // Simple test of the getValues function of the store. |
---|
1361 | // description: |
---|
1362 | // Simple test of the getValues function of the store. |
---|
1363 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1364 | |
---|
1365 | var d = new doh.Deferred(); |
---|
1366 | function onItem(item){ |
---|
1367 | t.assertTrue(item !== null); |
---|
1368 | var names = store.getValues(item,"name"); |
---|
1369 | t.assertTrue(dojo.isArray(names)); |
---|
1370 | t.assertEqual(names.length, 1); |
---|
1371 | t.assertEqual(names[0], "El Salvador"); |
---|
1372 | d.callback(true); |
---|
1373 | } |
---|
1374 | function onError(errData){ |
---|
1375 | t.assertTrue(false); |
---|
1376 | d.errback(errData); |
---|
1377 | } |
---|
1378 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
1379 | return d; // Deferred |
---|
1380 | } |
---|
1381 | }, |
---|
1382 | { |
---|
1383 | name: "Read API: isItem()", |
---|
1384 | runTest: function(datastore, t){ |
---|
1385 | // summary: |
---|
1386 | // Simple test of the isItem function of the store |
---|
1387 | // description: |
---|
1388 | // Simple test of the isItem function of the store |
---|
1389 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1390 | |
---|
1391 | var d = new doh.Deferred(); |
---|
1392 | function onItem(item){ |
---|
1393 | t.assertTrue(item !== null); |
---|
1394 | t.assertTrue(store.isItem(item)); |
---|
1395 | t.assertTrue(!store.isItem({})); |
---|
1396 | d.callback(true); |
---|
1397 | } |
---|
1398 | function onError(errData){ |
---|
1399 | t.assertTrue(false); |
---|
1400 | d.errback(errData); |
---|
1401 | } |
---|
1402 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
1403 | return d; // Deferred |
---|
1404 | } |
---|
1405 | }, |
---|
1406 | { |
---|
1407 | name: "Read API: isItem() multistore", |
---|
1408 | runTest: function(datastore, t){ |
---|
1409 | // summary: |
---|
1410 | // Simple test of the isItem function of the store |
---|
1411 | // to verify two different store instances do not accept |
---|
1412 | // items from each other. |
---|
1413 | // description: |
---|
1414 | // Simple test of the isItem function of the store |
---|
1415 | // to verify two different store instances do not accept |
---|
1416 | // items from each other. |
---|
1417 | |
---|
1418 | // Two different instances, even if they read from the same URL |
---|
1419 | // should not accept items between each other! |
---|
1420 | var store1 = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1421 | var store2 = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1422 | |
---|
1423 | var d = new doh.Deferred(); |
---|
1424 | function onItem1(item1){ |
---|
1425 | t.assertTrue(item1 !== null); |
---|
1426 | |
---|
1427 | function onItem2(item2){ |
---|
1428 | t.assertTrue(item1 !== null); |
---|
1429 | t.assertTrue(item2 !== null); |
---|
1430 | t.assertTrue(store1.isItem(item1)); |
---|
1431 | t.assertTrue(store2.isItem(item2)); |
---|
1432 | t.assertTrue(!store1.isItem(item2)); |
---|
1433 | t.assertTrue(!store2.isItem(item1)); |
---|
1434 | d.callback(true); |
---|
1435 | } |
---|
1436 | store2.fetchItemByIdentity({identity: "sv", onItem: onItem2, onError: onError}); |
---|
1437 | |
---|
1438 | } |
---|
1439 | function onError(errData){ |
---|
1440 | t.assertTrue(false); |
---|
1441 | d.errback(errData); |
---|
1442 | } |
---|
1443 | store1.fetchItemByIdentity({identity: "sv", onItem: onItem1, onError: onError}); |
---|
1444 | return d; // Deferred |
---|
1445 | } |
---|
1446 | }, |
---|
1447 | { |
---|
1448 | name: "Read API: hasAttribute()", |
---|
1449 | runTest: function(datastore, t){ |
---|
1450 | // summary: |
---|
1451 | // Simple test of the hasAttribute function of the store |
---|
1452 | // description: |
---|
1453 | // Simple test of the hasAttribute function of the store |
---|
1454 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1455 | |
---|
1456 | var d = new doh.Deferred(); |
---|
1457 | function onItem(item){ |
---|
1458 | try{ |
---|
1459 | t.assertTrue(item !== null); |
---|
1460 | |
---|
1461 | t.assertTrue(store.hasAttribute(item, "abbr")); |
---|
1462 | t.assertTrue(!store.hasAttribute(item, "abbr_not")); |
---|
1463 | |
---|
1464 | //Test that null attributes throw an exception |
---|
1465 | var passed = false; |
---|
1466 | try{ |
---|
1467 | store.hasAttribute(item, null); |
---|
1468 | }catch (e){ |
---|
1469 | passed = true; |
---|
1470 | } |
---|
1471 | t.assertTrue(passed); |
---|
1472 | d.callback(true); |
---|
1473 | }catch(e){ |
---|
1474 | d.errback(e); |
---|
1475 | } |
---|
1476 | } |
---|
1477 | function onError(errData){ |
---|
1478 | t.assertTrue(false); |
---|
1479 | d.errback(errData); |
---|
1480 | } |
---|
1481 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
1482 | return d; // Deferred |
---|
1483 | } |
---|
1484 | }, |
---|
1485 | { |
---|
1486 | name: "Read API: containsValue()", |
---|
1487 | runTest: function(datastore, t){ |
---|
1488 | // summary: |
---|
1489 | // Simple test of the containsValue function of the store |
---|
1490 | // description: |
---|
1491 | // Simple test of the containsValue function of the store |
---|
1492 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1493 | |
---|
1494 | var d = new doh.Deferred(); |
---|
1495 | function onItem(item){ |
---|
1496 | t.assertTrue(item !== null); |
---|
1497 | t.assertTrue(store.containsValue(item, "abbr", "sv")); |
---|
1498 | t.assertTrue(!store.containsValue(item, "abbr", "sv1")); |
---|
1499 | t.assertTrue(!store.containsValue(item, "abbr", null)); |
---|
1500 | |
---|
1501 | //Test that null attributes throw an exception |
---|
1502 | var passed = false; |
---|
1503 | try{ |
---|
1504 | store.containsValue(item, null, "foo"); |
---|
1505 | }catch (e){ |
---|
1506 | passed = true; |
---|
1507 | } |
---|
1508 | t.assertTrue(passed); |
---|
1509 | d.callback(true); |
---|
1510 | } |
---|
1511 | function onError(errData){ |
---|
1512 | t.assertTrue(false); |
---|
1513 | d.errback(errData); |
---|
1514 | } |
---|
1515 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
1516 | return d; // Deferred |
---|
1517 | } |
---|
1518 | }, |
---|
1519 | { |
---|
1520 | name: "Read API: getAttributes()", |
---|
1521 | runTest: function(datastore, t){ |
---|
1522 | // summary: |
---|
1523 | // Simple test of the getAttributes function of the store |
---|
1524 | // description: |
---|
1525 | // Simple test of the getAttributes function of the store |
---|
1526 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1527 | |
---|
1528 | var d = new doh.Deferred(); |
---|
1529 | function onItem(item){ |
---|
1530 | t.assertTrue(item !== null); |
---|
1531 | t.assertTrue(store.isItem(item)); |
---|
1532 | |
---|
1533 | var attributes = store.getAttributes(item); |
---|
1534 | t.assertEqual(attributes.length, 3); |
---|
1535 | for(var i = 0; i < attributes.length; i++){ |
---|
1536 | t.assertTrue((attributes[i] === "name" || attributes[i] === "abbr" || attributes[i] === "capital")); |
---|
1537 | } |
---|
1538 | d.callback(true); |
---|
1539 | } |
---|
1540 | function onError(errData){ |
---|
1541 | t.assertTrue(false); |
---|
1542 | d.errback(errData); |
---|
1543 | } |
---|
1544 | store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); |
---|
1545 | return d; // Deferred |
---|
1546 | } |
---|
1547 | }, |
---|
1548 | { |
---|
1549 | name: "Read API: getFeatures()", |
---|
1550 | runTest: function(datastore, t){ |
---|
1551 | // summary: |
---|
1552 | // Simple test of the getFeatures function of the store |
---|
1553 | // description: |
---|
1554 | // Simple test of the getFeatures function of the store |
---|
1555 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1556 | |
---|
1557 | var features = store.getFeatures(); |
---|
1558 | t.assertTrue(features["dojo.data.api.Read"] != null); |
---|
1559 | t.assertTrue(features["dojo.data.api.Identity"] != null); |
---|
1560 | } |
---|
1561 | }, |
---|
1562 | { |
---|
1563 | name: "Read API: fetch() patternMatch0", |
---|
1564 | runTest: function(datastore, t){ |
---|
1565 | // summary: |
---|
1566 | // Function to test pattern matching of everything starting with lowercase e |
---|
1567 | // description: |
---|
1568 | // Function to test pattern matching of everything starting with lowercase e |
---|
1569 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
1570 | |
---|
1571 | var d = new doh.Deferred(); |
---|
1572 | function completed(items, request) { |
---|
1573 | t.assertEqual(items.length, 5); |
---|
1574 | var passed = true; |
---|
1575 | for(var i = 0; i < items.length; i++){ |
---|
1576 | var value = store.getValue(items[i], "abbr"); |
---|
1577 | if(!(value === "ec" || value === "eg" || value === "er" || value === "ee" || value === "et")){ |
---|
1578 | passed=false; |
---|
1579 | break; |
---|
1580 | } |
---|
1581 | } |
---|
1582 | t.assertTrue(passed); |
---|
1583 | if (passed){ |
---|
1584 | d.callback(true); |
---|
1585 | }else{ |
---|
1586 | d.errback(new Error("Unexpected abbreviation found, match failure.")); |
---|
1587 | } |
---|
1588 | } |
---|
1589 | function error(error, request) { |
---|
1590 | t.assertTrue(false); |
---|
1591 | d.errback(error); |
---|
1592 | } |
---|
1593 | store.fetch({query: {abbr: "e*"}, onComplete: completed, onError: error}); |
---|
1594 | return d; |
---|
1595 | } |
---|
1596 | }, |
---|
1597 | { |
---|
1598 | name: "Read API: fetch() patternMatch1", |
---|
1599 | runTest: function(datastore, t){ |
---|
1600 | // summary: |
---|
1601 | // Function to test pattern matching of everything with $ in it. |
---|
1602 | // description: |
---|
1603 | // Function to test pattern matching of everything with $ in it. |
---|
1604 | |
---|
1605 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1606 | items: [ {uniqueId: 1, value:"foo*bar"}, |
---|
1607 | {uniqueId: 2, value:"bar*foo"}, |
---|
1608 | {uniqueId: 3, value:"boomBam"}, |
---|
1609 | {uniqueId: 4, value:"bit$Bite"}, |
---|
1610 | {uniqueId: 5, value:"ouagadogou"}, |
---|
1611 | {uniqueId: 6, value:"BaBaMaSaRa***Foo"}, |
---|
1612 | {uniqueId: 7, value:"squawl"}, |
---|
1613 | {uniqueId: 8, value:"seaweed"}, |
---|
1614 | {uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"} |
---|
1615 | ] |
---|
1616 | } |
---|
1617 | }); |
---|
1618 | |
---|
1619 | var d = new doh.Deferred(); |
---|
1620 | function completed(items, request){ |
---|
1621 | t.assertEqual(items.length, 2); |
---|
1622 | var passed = true; |
---|
1623 | for(var i = 0; i < items.length; i++){ |
---|
1624 | var value = store.getValue(items[i], "value"); |
---|
1625 | if(!(value === "bit$Bite" || value === "jfq4@#!$!@Rf14r14i5u")){ |
---|
1626 | passed=false; |
---|
1627 | break; |
---|
1628 | } |
---|
1629 | } |
---|
1630 | t.assertTrue(passed); |
---|
1631 | if (passed){ |
---|
1632 | d.callback(true); |
---|
1633 | }else{ |
---|
1634 | d.errback(new Error("Unexpected pattern matched. Filter failure.")); |
---|
1635 | } |
---|
1636 | } |
---|
1637 | function error(error, request){ |
---|
1638 | t.assertTrue(false); |
---|
1639 | d.errback(error); |
---|
1640 | } |
---|
1641 | store.fetch({query: {value: "*$*"}, onComplete: completed, onError: error}); |
---|
1642 | return d; |
---|
1643 | } |
---|
1644 | }, |
---|
1645 | { |
---|
1646 | name: "Read API: fetch() patternMatch2", |
---|
1647 | runTest: function(datastore, t){ |
---|
1648 | // summary: |
---|
1649 | // Function to test exact pattern match |
---|
1650 | // description: |
---|
1651 | // Function to test exact pattern match |
---|
1652 | |
---|
1653 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1654 | items: [ {uniqueId: 1, value:"foo*bar"}, |
---|
1655 | {uniqueId: 2, value:"bar*foo"}, |
---|
1656 | {uniqueId: 3, value:"boomBam"}, |
---|
1657 | {uniqueId: 4, value:"bit$Bite"}, |
---|
1658 | {uniqueId: 5, value:"ouagadogou"}, |
---|
1659 | {uniqueId: 6, value:"BaBaMaSaRa***Foo"}, |
---|
1660 | {uniqueId: 7, value:"squawl"}, |
---|
1661 | {uniqueId: 8, value:"seaweed"}, |
---|
1662 | {uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"} |
---|
1663 | ] |
---|
1664 | } |
---|
1665 | }); |
---|
1666 | |
---|
1667 | var d = new doh.Deferred(); |
---|
1668 | function completed(items, request){ |
---|
1669 | t.assertEqual(items.length, 1); |
---|
1670 | var passed = true; |
---|
1671 | for(var i = 0; i < items.length; i++){ |
---|
1672 | var value = store.getValue(items[i], "value"); |
---|
1673 | if(!(value === "bar*foo")){ |
---|
1674 | passed=false; |
---|
1675 | break; |
---|
1676 | } |
---|
1677 | } |
---|
1678 | t.assertTrue(passed); |
---|
1679 | if (passed){ |
---|
1680 | d.callback(true); |
---|
1681 | }else{ |
---|
1682 | d.errback(new Error("Unexpected abbreviation found, match failure.")); |
---|
1683 | } |
---|
1684 | } |
---|
1685 | function error(error, request){ |
---|
1686 | t.assertTrue(false); |
---|
1687 | d.errback(error); |
---|
1688 | } |
---|
1689 | store.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: error}); |
---|
1690 | return d; |
---|
1691 | } |
---|
1692 | }, |
---|
1693 | { |
---|
1694 | name: "Read API: fetch() patternMatch_caseSensitive", |
---|
1695 | runTest: function(datastore, t){ |
---|
1696 | // summary: |
---|
1697 | // Function to test pattern matching of a pattern case-sensitively |
---|
1698 | // description: |
---|
1699 | // Function to test pattern matching of a pattern case-sensitively |
---|
1700 | |
---|
1701 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1702 | items: [ {uniqueId: 1, value:"foo*bar"}, |
---|
1703 | {uniqueId: 2, value:"bar*foo"}, |
---|
1704 | {uniqueId: 3, value:"BAR*foo"}, |
---|
1705 | {uniqueId: 4, value:"BARBananafoo"} |
---|
1706 | ] |
---|
1707 | } |
---|
1708 | }); |
---|
1709 | |
---|
1710 | var d = new doh.Deferred(); |
---|
1711 | function completed(items, request){ |
---|
1712 | t.assertEqual(1, items.length); |
---|
1713 | var passed = true; |
---|
1714 | for(var i = 0; i < items.length; i++){ |
---|
1715 | var value = store.getValue(items[i], "value"); |
---|
1716 | if(!(value === "bar*foo")){ |
---|
1717 | passed=false; |
---|
1718 | break; |
---|
1719 | } |
---|
1720 | } |
---|
1721 | t.assertTrue(passed); |
---|
1722 | if (passed){ |
---|
1723 | d.callback(true); |
---|
1724 | }else{ |
---|
1725 | d.errback(new Error("Unexpected pattern matched. Filter failure.")); |
---|
1726 | } |
---|
1727 | } |
---|
1728 | function error(error, request){ |
---|
1729 | t.assertTrue(false); |
---|
1730 | d.errback(error); |
---|
1731 | } |
---|
1732 | store.fetch({query: {value: "bar\\*foo"}, queryOptions: {ignoreCase: false} , onComplete: completed, onError: error}); |
---|
1733 | return d; |
---|
1734 | } |
---|
1735 | }, |
---|
1736 | { |
---|
1737 | name: "Read API: fetch() patternMatch_caseInsensitive", |
---|
1738 | runTest: function(datastore, t){ |
---|
1739 | // summary: |
---|
1740 | // Function to test pattern matching of a pattern case-insensitively |
---|
1741 | // description: |
---|
1742 | // Function to test pattern matching of a pattern case-insensitively |
---|
1743 | |
---|
1744 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1745 | items: [ {uniqueId: 1, value:"foo*bar"}, |
---|
1746 | {uniqueId: 2, value:"bar*foo"}, |
---|
1747 | {uniqueId: 3, value:"BAR*foo"}, |
---|
1748 | {uniqueId: 4, value:"BARBananafoo"} |
---|
1749 | ] |
---|
1750 | } |
---|
1751 | }); |
---|
1752 | |
---|
1753 | var d = new doh.Deferred(); |
---|
1754 | function completed(items, request){ |
---|
1755 | t.assertEqual(items.length, 2); |
---|
1756 | var passed = true; |
---|
1757 | for(var i = 0; i < items.length; i++){ |
---|
1758 | var value = store.getValue(items[i], "value"); |
---|
1759 | if(!(value === "BAR*foo" || value === "bar*foo")){ |
---|
1760 | passed=false; |
---|
1761 | break; |
---|
1762 | } |
---|
1763 | } |
---|
1764 | t.assertTrue(passed); |
---|
1765 | if (passed){ |
---|
1766 | d.callback(true); |
---|
1767 | }else{ |
---|
1768 | d.errback(new Error("Unexpected pattern matched. Filter failure.")); |
---|
1769 | } |
---|
1770 | } |
---|
1771 | function error(error, request){ |
---|
1772 | t.assertTrue(false); |
---|
1773 | d.errback(error); |
---|
1774 | } |
---|
1775 | store.fetch({query: {value: "bar\\*foo"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: error}); |
---|
1776 | return d; |
---|
1777 | } |
---|
1778 | }, |
---|
1779 | { |
---|
1780 | name: "Read API: fetch() sortNumeric", |
---|
1781 | runTest: function(datastore, t){ |
---|
1782 | // summary: |
---|
1783 | // Function to test sorting numerically. |
---|
1784 | // description: |
---|
1785 | // Function to test sorting numerically. |
---|
1786 | |
---|
1787 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1788 | items: [ {uniqueId: 0, value:"fo|o*b.ar"}, |
---|
1789 | {uniqueId: 1, value:"ba|r*foo"}, |
---|
1790 | {uniqueId: 2, value:"boomBam"}, |
---|
1791 | {uniqueId: 3, value:"bit$Bite"}, |
---|
1792 | {uniqueId: 4, value:"ouagadogou"}, |
---|
1793 | {uniqueId: 5, value:"jfq4@#!$!@|f1.$4r14i5u"}, |
---|
1794 | {uniqueId: 6, value:"BaB{aMa|SaRa***F}oo"}, |
---|
1795 | {uniqueId: 7, value:"squawl"}, |
---|
1796 | {uniqueId: 9, value:"seaweed"}, |
---|
1797 | {uniqueId: 10, value:"zulu"}, |
---|
1798 | {uniqueId: 8, value:"seaweed"} |
---|
1799 | ] |
---|
1800 | } |
---|
1801 | }); |
---|
1802 | |
---|
1803 | var d = new doh.Deferred(); |
---|
1804 | function completed(items, request){ |
---|
1805 | t.assertEqual(items.length, 11); |
---|
1806 | var passed = true; |
---|
1807 | for(var i = 0; i < items.length; i++){ |
---|
1808 | var value = store.getValue(items[i], "value"); |
---|
1809 | if(!(store.getValue(items[i], "uniqueId") === i)){ |
---|
1810 | passed=false; |
---|
1811 | break; |
---|
1812 | } |
---|
1813 | } |
---|
1814 | t.assertTrue(passed); |
---|
1815 | if (passed){ |
---|
1816 | d.callback(true); |
---|
1817 | }else{ |
---|
1818 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
1819 | } |
---|
1820 | } |
---|
1821 | |
---|
1822 | function error(error, request){ |
---|
1823 | t.assertTrue(false); |
---|
1824 | d.errback(error); |
---|
1825 | } |
---|
1826 | |
---|
1827 | var sortAttributes = [{attribute: "uniqueId"}]; |
---|
1828 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
1829 | return d; |
---|
1830 | } |
---|
1831 | }, |
---|
1832 | { |
---|
1833 | name: "Read API: fetch() sortNumericDescending", |
---|
1834 | runTest: function(datastore, t){ |
---|
1835 | // summary: |
---|
1836 | // Function to test sorting numerically. |
---|
1837 | // description: |
---|
1838 | // Function to test sorting numerically. |
---|
1839 | |
---|
1840 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1841 | items: [ {uniqueId: 0, value:"fo|o*b.ar"}, |
---|
1842 | {uniqueId: 1, value:"ba|r*foo"}, |
---|
1843 | {uniqueId: 2, value:"boomBam"}, |
---|
1844 | {uniqueId: 3, value:"bit$Bite"}, |
---|
1845 | {uniqueId: 4, value:"ouagadogou"}, |
---|
1846 | {uniqueId: 5, value:"jfq4@#!$!@|f1.$4r14i5u"}, |
---|
1847 | {uniqueId: 6, value:"BaB{aMa|SaRa***F}oo"}, |
---|
1848 | {uniqueId: 7, value:"squawl"}, |
---|
1849 | {uniqueId: 9, value:"seaweed"}, |
---|
1850 | {uniqueId: 10, value:"zulu"}, |
---|
1851 | {uniqueId: 8, value:"seaweed"} |
---|
1852 | ] |
---|
1853 | } |
---|
1854 | }); |
---|
1855 | var d = new doh.Deferred(); |
---|
1856 | function completed(items, request){ |
---|
1857 | t.assertEqual(items.length, 11); |
---|
1858 | var passed = true; |
---|
1859 | for(var i = 0; i < items.length; i++){ |
---|
1860 | var value = store.getValue(items[i], "value"); |
---|
1861 | if(!((items.length - (store.getValue(items[i], "uniqueId") + 1)) === i)){ |
---|
1862 | passed=false; |
---|
1863 | break; |
---|
1864 | } |
---|
1865 | } |
---|
1866 | t.assertTrue(passed); |
---|
1867 | if (passed){ |
---|
1868 | d.callback(true); |
---|
1869 | }else{ |
---|
1870 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
1871 | } |
---|
1872 | } |
---|
1873 | |
---|
1874 | function error(error, request){ |
---|
1875 | t.assertTrue(false); |
---|
1876 | d.errback(error); |
---|
1877 | } |
---|
1878 | |
---|
1879 | var sortAttributes = [{attribute: "uniqueId", descending: true}]; |
---|
1880 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
1881 | return d; |
---|
1882 | } |
---|
1883 | }, |
---|
1884 | { |
---|
1885 | name: "Read API: fetch() sortNumericWithCount", |
---|
1886 | runTest: function(datastore, t){ |
---|
1887 | // summary: |
---|
1888 | // Function to test sorting numerically in descending order, returning only a specified number of them. |
---|
1889 | // description: |
---|
1890 | // Function to test sorting numerically in descending order, returning only a specified number of them. |
---|
1891 | |
---|
1892 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1893 | items: [ {uniqueId: 0, value:"fo|o*b.ar"}, |
---|
1894 | {uniqueId: 1, value:"ba|r*foo"}, |
---|
1895 | {uniqueId: 2, value:"boomBam"}, |
---|
1896 | {uniqueId: 3, value:"bit$Bite"}, |
---|
1897 | {uniqueId: 4, value:"ouagadogou"}, |
---|
1898 | {uniqueId: 5, value:"jfq4@#!$!@|f1.$4r14i5u"}, |
---|
1899 | {uniqueId: 6, value:"BaB{aMa|SaRa***F}oo"}, |
---|
1900 | {uniqueId: 7, value:"squawl"}, |
---|
1901 | {uniqueId: 9, value:"seaweed"}, |
---|
1902 | {uniqueId: 10, value:"zulu"}, |
---|
1903 | {uniqueId: 8, value:"seaweed"} |
---|
1904 | ] |
---|
1905 | } |
---|
1906 | }); |
---|
1907 | |
---|
1908 | var d = new doh.Deferred(); |
---|
1909 | function completed(items, request){ |
---|
1910 | t.assertEqual(items.length, 5); |
---|
1911 | var itemId = 10; |
---|
1912 | var passed = true; |
---|
1913 | for(var i = 0; i < items.length; i++){ |
---|
1914 | var value = store.getValue(items[i], "value"); |
---|
1915 | if(!(store.getValue(items[i], "uniqueId") === itemId)){ |
---|
1916 | passed=false; |
---|
1917 | break; |
---|
1918 | } |
---|
1919 | itemId--; // Decrement the item id. We are descending sorted, so it should go 10, 9, 8, etc. |
---|
1920 | } |
---|
1921 | t.assertTrue(passed); |
---|
1922 | if (passed){ |
---|
1923 | d.callback(true); |
---|
1924 | }else{ |
---|
1925 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
1926 | } |
---|
1927 | } |
---|
1928 | |
---|
1929 | function error(error, request){ |
---|
1930 | t.assertTrue(false); |
---|
1931 | d.errback(error); |
---|
1932 | } |
---|
1933 | |
---|
1934 | var sortAttributes = [{attribute: "uniqueId", descending: true}]; |
---|
1935 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes, count: 5}); |
---|
1936 | return d; |
---|
1937 | } |
---|
1938 | }, |
---|
1939 | { |
---|
1940 | name: "Read API: fetch() sortAlphabetic", |
---|
1941 | runTest: function(datastore, t){ |
---|
1942 | // summary: |
---|
1943 | // Function to test sorting alphabetic ordering. |
---|
1944 | // description: |
---|
1945 | // Function to test sorting alphabetic ordering. |
---|
1946 | |
---|
1947 | var store = new datastore({data: { identifier: "uniqueId", |
---|
1948 | items: [ {uniqueId: 0, value:"abc"}, |
---|
1949 | {uniqueId: 1, value:"bca"}, |
---|
1950 | {uniqueId: 2, value:"abcd"}, |
---|
1951 | {uniqueId: 3, value:"abcdefg"}, |
---|
1952 | {uniqueId: 4, value:"lmnop"}, |
---|
1953 | {uniqueId: 5, value:"foghorn"}, |
---|
1954 | {uniqueId: 6, value:"qberty"}, |
---|
1955 | {uniqueId: 7, value:"qwerty"}, |
---|
1956 | {uniqueId: 8, value:""}, |
---|
1957 | {uniqueId: 9, value:"seaweed"}, |
---|
1958 | {uniqueId: 10, value:"123abc"} |
---|
1959 | |
---|
1960 | ] |
---|
1961 | } |
---|
1962 | }); |
---|
1963 | |
---|
1964 | var d = new doh.Deferred(); |
---|
1965 | function completed(items, request){ |
---|
1966 | //Output should be in this order... |
---|
1967 | var orderedArray = [ "", |
---|
1968 | "123abc", |
---|
1969 | "abc", |
---|
1970 | "abcd", |
---|
1971 | "abcdefg", |
---|
1972 | "bca", |
---|
1973 | "foghorn", |
---|
1974 | "lmnop", |
---|
1975 | "qberty", |
---|
1976 | "qwerty", |
---|
1977 | "seaweed" |
---|
1978 | ]; |
---|
1979 | t.assertEqual(items.length, 11); |
---|
1980 | var passed = true; |
---|
1981 | for(var i = 0; i < items.length; i++){ |
---|
1982 | var value = store.getValue(items[i], "value"); |
---|
1983 | if(!(store.getValue(items[i], "value") === orderedArray[i])){ |
---|
1984 | passed=false; |
---|
1985 | break; |
---|
1986 | } |
---|
1987 | } |
---|
1988 | t.assertTrue(passed); |
---|
1989 | if (passed){ |
---|
1990 | d.callback(true); |
---|
1991 | }else{ |
---|
1992 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
1993 | } |
---|
1994 | } |
---|
1995 | |
---|
1996 | function error(error, request) { |
---|
1997 | t.assertTrue(false); |
---|
1998 | d.errback(error); |
---|
1999 | } |
---|
2000 | |
---|
2001 | var sortAttributes = [{attribute: "value"}]; |
---|
2002 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2003 | return d; |
---|
2004 | } |
---|
2005 | }, |
---|
2006 | { |
---|
2007 | name: "Read API: fetch() sortAlphabeticDescending", |
---|
2008 | runTest: function(datastore, t){ |
---|
2009 | // summary: |
---|
2010 | // Function to test sorting alphabetic ordering in descending mode. |
---|
2011 | // description: |
---|
2012 | // Function to test sorting alphabetic ordering in descending mode. |
---|
2013 | |
---|
2014 | var store = new datastore({data: { identifier: "uniqueId", |
---|
2015 | items: [ {uniqueId: 0, value:"abc"}, |
---|
2016 | {uniqueId: 1, value:"bca"}, |
---|
2017 | {uniqueId: 2, value:"abcd"}, |
---|
2018 | {uniqueId: 3, value:"abcdefg"}, |
---|
2019 | {uniqueId: 4, value:"lmnop"}, |
---|
2020 | {uniqueId: 5, value:"foghorn"}, |
---|
2021 | {uniqueId: 6, value:"qberty"}, |
---|
2022 | {uniqueId: 7, value:"qwerty"}, |
---|
2023 | {uniqueId: 8, value:""}, |
---|
2024 | {uniqueId: 9, value:"seaweed"}, |
---|
2025 | {uniqueId: 10, value:"123abc"} |
---|
2026 | |
---|
2027 | ] |
---|
2028 | } |
---|
2029 | }); |
---|
2030 | var d = new doh.Deferred(); |
---|
2031 | function completed(items, request){ |
---|
2032 | //Output should be in this order... |
---|
2033 | var orderedArray = [ "", |
---|
2034 | "123abc", |
---|
2035 | "abc", |
---|
2036 | "abcd", |
---|
2037 | "abcdefg", |
---|
2038 | "bca", |
---|
2039 | "foghorn", |
---|
2040 | "lmnop", |
---|
2041 | "qberty", |
---|
2042 | "qwerty", |
---|
2043 | "seaweed" |
---|
2044 | ]; |
---|
2045 | orderedArray = orderedArray.reverse(); |
---|
2046 | t.assertEqual(items.length, 11); |
---|
2047 | |
---|
2048 | var passed = true; |
---|
2049 | for(var i = 0; i < items.length; i++){ |
---|
2050 | var value = store.getValue(items[i], "value"); |
---|
2051 | if(!(store.getValue(items[i], "value") === orderedArray[i])){ |
---|
2052 | passed=false; |
---|
2053 | break; |
---|
2054 | } |
---|
2055 | } |
---|
2056 | t.assertTrue(passed); |
---|
2057 | if (passed){ |
---|
2058 | d.callback(true); |
---|
2059 | }else{ |
---|
2060 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
2061 | } |
---|
2062 | } |
---|
2063 | |
---|
2064 | function error(error, request) { |
---|
2065 | t.assertTrue(false); |
---|
2066 | d.errback(error); |
---|
2067 | } |
---|
2068 | |
---|
2069 | var sortAttributes = [{attribute: "value", descending: true}]; |
---|
2070 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2071 | return d; |
---|
2072 | } |
---|
2073 | }, |
---|
2074 | { |
---|
2075 | name: "Read API: fetch() sortDate", |
---|
2076 | runTest: function(datastore, t){ |
---|
2077 | // summary: |
---|
2078 | // Function to test sorting date. |
---|
2079 | // description: |
---|
2080 | // Function to test sorting date. |
---|
2081 | |
---|
2082 | var store = new datastore({data: { identifier: "uniqueId", |
---|
2083 | items: [ {uniqueId: 0, value: new Date(0)}, |
---|
2084 | {uniqueId: 1, value: new Date(100)}, |
---|
2085 | {uniqueId: 2, value:new Date(1000)}, |
---|
2086 | {uniqueId: 3, value:new Date(2000)}, |
---|
2087 | {uniqueId: 4, value:new Date(3000)}, |
---|
2088 | {uniqueId: 5, value:new Date(4000)}, |
---|
2089 | {uniqueId: 6, value:new Date(5000)}, |
---|
2090 | {uniqueId: 7, value:new Date(6000)}, |
---|
2091 | {uniqueId: 8, value:new Date(7000)}, |
---|
2092 | {uniqueId: 9, value:new Date(8000)}, |
---|
2093 | {uniqueId: 10, value:new Date(9000)} |
---|
2094 | |
---|
2095 | ] |
---|
2096 | } |
---|
2097 | }); |
---|
2098 | |
---|
2099 | var d = new doh.Deferred(); |
---|
2100 | function completed(items,request){ |
---|
2101 | var orderedArray = [0,100,1000,2000,3000,4000,5000,6000,7000,8000,9000]; |
---|
2102 | t.assertEqual(items.length, 11); |
---|
2103 | var passed = true; |
---|
2104 | for(var i = 0; i < items.length; i++){ |
---|
2105 | var value = store.getValue(items[i], "value"); |
---|
2106 | if(!(store.getValue(items[i], "value").getTime() === orderedArray[i])){ |
---|
2107 | passed=false; |
---|
2108 | break; |
---|
2109 | } |
---|
2110 | } |
---|
2111 | t.assertTrue(passed); |
---|
2112 | if (passed){ |
---|
2113 | d.callback(true); |
---|
2114 | }else{ |
---|
2115 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
2116 | } |
---|
2117 | } |
---|
2118 | |
---|
2119 | function error(error, request){ |
---|
2120 | t.assertTrue(false); |
---|
2121 | d.errback(error); |
---|
2122 | } |
---|
2123 | |
---|
2124 | var sortAttributes = [{attribute: "value"}]; |
---|
2125 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2126 | return d; |
---|
2127 | } |
---|
2128 | }, |
---|
2129 | { |
---|
2130 | name: "Read API: fetch() sortDateDescending", |
---|
2131 | runTest: function(datastore, t){ |
---|
2132 | // summary: |
---|
2133 | // Function to test sorting date in descending order. |
---|
2134 | // description: |
---|
2135 | // Function to test sorting date in descending order. |
---|
2136 | |
---|
2137 | var store = new datastore({data: { identifier: "uniqueId", |
---|
2138 | items: [ {uniqueId: 0, value: new Date(0)}, |
---|
2139 | {uniqueId: 1, value: new Date(100)}, |
---|
2140 | {uniqueId: 2, value:new Date(1000)}, |
---|
2141 | {uniqueId: 3, value:new Date(2000)}, |
---|
2142 | {uniqueId: 4, value:new Date(3000)}, |
---|
2143 | {uniqueId: 5, value:new Date(4000)}, |
---|
2144 | {uniqueId: 6, value:new Date(5000)}, |
---|
2145 | {uniqueId: 7, value:new Date(6000)}, |
---|
2146 | {uniqueId: 8, value:new Date(7000)}, |
---|
2147 | {uniqueId: 9, value:new Date(8000)}, |
---|
2148 | {uniqueId: 10, value:new Date(9000)} |
---|
2149 | |
---|
2150 | ] |
---|
2151 | } |
---|
2152 | }); |
---|
2153 | |
---|
2154 | var d = new doh.Deferred(); |
---|
2155 | function completed(items,request){ |
---|
2156 | var orderedArray = [0,100,1000,2000,3000,4000,5000,6000,7000,8000,9000]; |
---|
2157 | orderedArray = orderedArray.reverse(); |
---|
2158 | t.assertEqual(items.length, 11); |
---|
2159 | var passed = true; |
---|
2160 | for(var i = 0; i < items.length; i++){ |
---|
2161 | var value = store.getValue(items[i], "value"); |
---|
2162 | if(!(store.getValue(items[i], "value").getTime() === orderedArray[i])){ |
---|
2163 | passed=false; |
---|
2164 | break; |
---|
2165 | } |
---|
2166 | } |
---|
2167 | t.assertTrue(passed); |
---|
2168 | if (passed){ |
---|
2169 | d.callback(true); |
---|
2170 | }else{ |
---|
2171 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
2172 | } |
---|
2173 | } |
---|
2174 | |
---|
2175 | function error(error, request){ |
---|
2176 | t.assertTrue(false); |
---|
2177 | d.errback(error); |
---|
2178 | } |
---|
2179 | |
---|
2180 | var sortAttributes = [{attribute: "value", descending: true}]; |
---|
2181 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2182 | return d; |
---|
2183 | } |
---|
2184 | }, |
---|
2185 | { |
---|
2186 | name: "Read API: fetch() sortMultiple", |
---|
2187 | runTest: function(datastore, t){ |
---|
2188 | // summary: |
---|
2189 | // Function to test sorting on multiple attributes. |
---|
2190 | // description: |
---|
2191 | // Function to test sorting on multiple attributes. |
---|
2192 | |
---|
2193 | var store = new datastore({data: { identifier: "uniqueId", |
---|
2194 | items: [ {uniqueId: 1, value:"fo|o*b.ar"}, |
---|
2195 | {uniqueId: 2, value:"ba|r*foo"}, |
---|
2196 | {uniqueId: 3, value:"boomBam"}, |
---|
2197 | {uniqueId: 4, value:"bit$Bite"}, |
---|
2198 | {uniqueId: 5, value:"ouagadogou"}, |
---|
2199 | {uniqueId: 6, value:"jfq4@#!$!@|f1.$4r14i5u"}, |
---|
2200 | {uniqueId: 7, value:"BaB{aMa|SaRa***F}oo"}, |
---|
2201 | {uniqueId: 8, value:"squawl"}, |
---|
2202 | {uniqueId: 10, value:"seaweed"}, |
---|
2203 | {uniqueId: 12, value:"seaweed"}, |
---|
2204 | {uniqueId: 11, value:"zulu"}, |
---|
2205 | {uniqueId: 9, value:"seaweed"} |
---|
2206 | ] |
---|
2207 | } |
---|
2208 | }); |
---|
2209 | |
---|
2210 | var d = new doh.Deferred(); |
---|
2211 | function completed(items, request){ |
---|
2212 | var orderedArray0 = [7,2,4,3,1,6,5,12,10,9,8,11]; |
---|
2213 | var orderedArray1 = [ "BaB{aMa|SaRa***F}oo", |
---|
2214 | "ba|r*foo", |
---|
2215 | "bit$Bite", |
---|
2216 | "boomBam", |
---|
2217 | "fo|o*b.ar", |
---|
2218 | "jfq4@#!$!@|f1.$4r14i5u", |
---|
2219 | "ouagadogou", |
---|
2220 | "seaweed", |
---|
2221 | "seaweed", |
---|
2222 | "seaweed", |
---|
2223 | "squawl", |
---|
2224 | "zulu" |
---|
2225 | ]; |
---|
2226 | var passed = true; |
---|
2227 | for(var i = 0; i < items.length; i++){ |
---|
2228 | var value = store.getValue(items[i], "value"); |
---|
2229 | if(!( (store.getValue(items[i], "uniqueId") === orderedArray0[i])&& |
---|
2230 | (store.getValue(items[i], "value") === orderedArray1[i])) |
---|
2231 | ){ |
---|
2232 | passed=false; |
---|
2233 | break; |
---|
2234 | } |
---|
2235 | } |
---|
2236 | t.assertTrue(passed); |
---|
2237 | if (passed){ |
---|
2238 | d.callback(true); |
---|
2239 | }else{ |
---|
2240 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
2241 | } |
---|
2242 | } |
---|
2243 | |
---|
2244 | function error(error, request){ |
---|
2245 | t.assertTrue(false); |
---|
2246 | d.errback(error); |
---|
2247 | } |
---|
2248 | |
---|
2249 | var sortAttributes = [{ attribute: "value"}, { attribute: "uniqueId", descending: true}]; |
---|
2250 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2251 | return d; |
---|
2252 | } |
---|
2253 | }, |
---|
2254 | { |
---|
2255 | name: "Read API: fetch() sortMultipleSpecialComparator", |
---|
2256 | runTest: function(datastore, t){ |
---|
2257 | // summary: |
---|
2258 | // Function to test sorting on multiple attributes with a custom comparator. |
---|
2259 | // description: |
---|
2260 | // Function to test sorting on multiple attributes with a custom comparator. |
---|
2261 | |
---|
2262 | var store = new datastore({data: { identifier: "uniqueId", |
---|
2263 | items: [ {uniqueId: 1, status:"CLOSED"}, |
---|
2264 | {uniqueId: 2, status:"OPEN"}, |
---|
2265 | {uniqueId: 3, status:"PENDING"}, |
---|
2266 | {uniqueId: 4, status:"BLOCKED"}, |
---|
2267 | {uniqueId: 5, status:"CLOSED"}, |
---|
2268 | {uniqueId: 6, status:"OPEN"}, |
---|
2269 | {uniqueId: 7, status:"PENDING"}, |
---|
2270 | {uniqueId: 8, status:"PENDING"}, |
---|
2271 | {uniqueId: 10, status:"BLOCKED"}, |
---|
2272 | {uniqueId: 12, status:"BLOCKED"}, |
---|
2273 | {uniqueId: 11, status:"OPEN"}, |
---|
2274 | {uniqueId: 9, status:"CLOSED"} |
---|
2275 | ] |
---|
2276 | } |
---|
2277 | }); |
---|
2278 | |
---|
2279 | |
---|
2280 | store.comparatorMap = {}; |
---|
2281 | store.comparatorMap["status"] = function(a,b) { |
---|
2282 | var ret = 0; |
---|
2283 | // We want to map these by what the priority of these items are, not by alphabetical. |
---|
2284 | // So, custom comparator. |
---|
2285 | var enumMap = { OPEN: 3, BLOCKED: 2, PENDING: 1, CLOSED: 0}; |
---|
2286 | if (enumMap[a] > enumMap[b]) { |
---|
2287 | ret = 1; |
---|
2288 | } |
---|
2289 | if (enumMap[a] < enumMap[b]) { |
---|
2290 | ret = -1; |
---|
2291 | } |
---|
2292 | return ret; |
---|
2293 | }; |
---|
2294 | |
---|
2295 | var sortAttributes = [{attribute: "status", descending: true}, { attribute: "uniqueId", descending: true}]; |
---|
2296 | |
---|
2297 | var d = new doh.Deferred(); |
---|
2298 | function completed(items, findResult){ |
---|
2299 | var orderedArray = [11,6,2,12,10,4,8,7,3,9,5,1]; |
---|
2300 | var passed = true; |
---|
2301 | for(var i = 0; i < items.length; i++){ |
---|
2302 | var value = store.getValue(items[i], "value"); |
---|
2303 | if(!(store.getValue(items[i], "uniqueId") === orderedArray[i])){ |
---|
2304 | passed=false; |
---|
2305 | break; |
---|
2306 | } |
---|
2307 | } |
---|
2308 | t.assertTrue(passed); |
---|
2309 | if (passed){ |
---|
2310 | d.callback(true); |
---|
2311 | }else{ |
---|
2312 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
2313 | } |
---|
2314 | } |
---|
2315 | |
---|
2316 | function error(errData, request){ |
---|
2317 | t.assertTrue(false); |
---|
2318 | d.errback(errData); |
---|
2319 | } |
---|
2320 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2321 | return d; |
---|
2322 | } |
---|
2323 | }, |
---|
2324 | { |
---|
2325 | name: "Read API: fetch() sortAlphabeticWithUndefined", |
---|
2326 | runTest: function(datastore, t){ |
---|
2327 | // summary: |
---|
2328 | // Function to test sorting alphabetic ordering. |
---|
2329 | // description: |
---|
2330 | // Function to test sorting alphabetic ordering. |
---|
2331 | |
---|
2332 | var store = new datastore({data: { identifier: "uniqueId", |
---|
2333 | items: [ {uniqueId: 0, value:"abc"}, |
---|
2334 | {uniqueId: 1, value:"bca"}, |
---|
2335 | {uniqueId: 2, value:"abcd"}, |
---|
2336 | {uniqueId: 3, value:"abcdefg"}, |
---|
2337 | {uniqueId: 4, value:"lmnop"}, |
---|
2338 | {uniqueId: 5, value:"foghorn"}, |
---|
2339 | {uniqueId: 6, value:"qberty"}, |
---|
2340 | {uniqueId: 7, value:"qwerty"}, |
---|
2341 | {uniqueId: 8 }, //Deliberate undefined value |
---|
2342 | {uniqueId: 9, value:"seaweed"}, |
---|
2343 | {uniqueId: 10, value:"123abc"} |
---|
2344 | |
---|
2345 | ] |
---|
2346 | } |
---|
2347 | }); |
---|
2348 | |
---|
2349 | var d = new doh.Deferred(); |
---|
2350 | function completed(items, request){ |
---|
2351 | //Output should be in this order... |
---|
2352 | var orderedArray = [10,0,2,3,1,5,4,6,7,9,8]; |
---|
2353 | t.assertEqual(items.length, 11); |
---|
2354 | var passed = true; |
---|
2355 | for(var i = 0; i < items.length; i++){ |
---|
2356 | if(!(store.getValue(items[i], "uniqueId") === orderedArray[i])){ |
---|
2357 | passed=false; |
---|
2358 | break; |
---|
2359 | } |
---|
2360 | } |
---|
2361 | t.assertTrue(passed); |
---|
2362 | if (passed){ |
---|
2363 | d.callback(true); |
---|
2364 | }else{ |
---|
2365 | d.errback(new Error("Unexpected sorting order found, sort failure.")); |
---|
2366 | } |
---|
2367 | } |
---|
2368 | |
---|
2369 | function error(error, request) { |
---|
2370 | t.assertTrue(false); |
---|
2371 | d.errback(error); |
---|
2372 | } |
---|
2373 | |
---|
2374 | var sortAttributes = [{attribute: "value"}]; |
---|
2375 | store.fetch({onComplete: completed, onError: error, sort: sortAttributes}); |
---|
2376 | return d; |
---|
2377 | } |
---|
2378 | }, |
---|
2379 | { |
---|
2380 | name: "Read API: errorCondition_idCollision_inMemory", |
---|
2381 | runTest: function(datastore, t){ |
---|
2382 | // summary: |
---|
2383 | // Simple test of the errors thrown when there is an id collision in the data. |
---|
2384 | // Added because of tracker: #2546 |
---|
2385 | // description: |
---|
2386 | // Simple test of the errors thrown when there is an id collision in the data. |
---|
2387 | // Added because of tracker: #2546 |
---|
2388 | |
---|
2389 | var store = new datastore({ data: { identifier: "uniqueId", |
---|
2390 | items: [{uniqueId: 12345, value:"foo"}, |
---|
2391 | {uniqueId: 123456, value:"bar"}, |
---|
2392 | {uniqueId: 12345, value:"boom"}, |
---|
2393 | {uniqueId: 123457, value:"bit"} |
---|
2394 | ] |
---|
2395 | } |
---|
2396 | }); |
---|
2397 | var d = new doh.Deferred(); |
---|
2398 | function onComplete(items, request){ |
---|
2399 | //This is bad if this fires, this case should fail and not call onComplete. |
---|
2400 | t.assertTrue(false); |
---|
2401 | d.callback(false); |
---|
2402 | } |
---|
2403 | |
---|
2404 | function reportError(errData, request){ |
---|
2405 | //This is good if this fires, it is expected. |
---|
2406 | t.assertTrue(true); |
---|
2407 | d.callback(true); |
---|
2408 | } |
---|
2409 | store.fetch({onComplete: onComplete, onError: reportError}); |
---|
2410 | return d; |
---|
2411 | } |
---|
2412 | }, |
---|
2413 | { |
---|
2414 | name: "Read API: errorCondition_idCollision_xhr", |
---|
2415 | runTest: function(datastore, t){ |
---|
2416 | // summary: |
---|
2417 | // Simple test of the errors thrown when there is an id collision in the data. |
---|
2418 | // Added because of tracker: #2546 |
---|
2419 | // description: |
---|
2420 | // Simple test of the errors thrown when there is an id collision in the data. |
---|
2421 | // Added because of tracker: #2546 |
---|
2422 | |
---|
2423 | if(dojo.isBrowser){ |
---|
2424 | var store = new datastore({url: require.toUrl("tests/data/countries_idcollision.json")}); |
---|
2425 | var d = new doh.Deferred(); |
---|
2426 | function onComplete(items, request){ |
---|
2427 | //This is bad if this fires, this case should fail and not call onComplete. |
---|
2428 | t.assertTrue(false); |
---|
2429 | d.callback(false); |
---|
2430 | } |
---|
2431 | |
---|
2432 | function reportError(errData, request){ |
---|
2433 | //This is good if this fires, it is expected. |
---|
2434 | t.assertTrue(true); |
---|
2435 | d.callback(true); |
---|
2436 | } |
---|
2437 | store.fetch({onComplete: onComplete, onError: reportError}); |
---|
2438 | return d; |
---|
2439 | } |
---|
2440 | } |
---|
2441 | }, |
---|
2442 | { |
---|
2443 | name: "Read API: Date_datatype", |
---|
2444 | runTest: function(datastore, t){ |
---|
2445 | //var store = new datastore(tests.data.readOnlyItemFileTestTemplates.testFile["countries_withDates"]); |
---|
2446 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withDates")); |
---|
2447 | |
---|
2448 | var d = new doh.Deferred(); |
---|
2449 | function onItem(item){ |
---|
2450 | t.assertTrue(item !== null); |
---|
2451 | var independenceDate = store.getValue(item, "independence"); |
---|
2452 | t.assertTrue(independenceDate instanceof Date); |
---|
2453 | //Check to see if the value was deserialized properly. Since the store stores in UTC/GMT, it |
---|
2454 | //should also be compared in the UTC/GMT mode |
---|
2455 | t.assertTrue(dojo.date.stamp.toISOString(independenceDate, {zulu:true}) === "1993-05-24T00:00:00Z"); |
---|
2456 | d.callback(true); |
---|
2457 | } |
---|
2458 | function onError(errData){ |
---|
2459 | t.assertTrue(false); |
---|
2460 | d.errback(errData); |
---|
2461 | } |
---|
2462 | store.fetchItemByIdentity({identity:"er", onItem:onItem, onError:onError}); |
---|
2463 | return d; // Deferred |
---|
2464 | } |
---|
2465 | }, |
---|
2466 | { |
---|
2467 | name: "Read API: custom_datatype_Color_SimpleMapping", |
---|
2468 | runTest: function(datastore, t){ |
---|
2469 | // summary: |
---|
2470 | // Function to test using literal values with custom datatypes |
---|
2471 | var dataset = { |
---|
2472 | identifier:'name', |
---|
2473 | items: [ |
---|
2474 | { name:'Kermit', species:'frog', color:{_type:'Color', _value:'green'} }, |
---|
2475 | { name:'Beaker', hairColor:{_type:'Color', _value:'red'} } |
---|
2476 | ] |
---|
2477 | }; |
---|
2478 | var store = new datastore({ |
---|
2479 | data:dataset, |
---|
2480 | typeMap:{'Color': dojo.Color} |
---|
2481 | }); |
---|
2482 | var d = new doh.Deferred(); |
---|
2483 | function onItem(item){ |
---|
2484 | t.assertTrue(item !== null); |
---|
2485 | var beaker = item; |
---|
2486 | var hairColor = store.getValue(beaker, "hairColor"); |
---|
2487 | t.assertTrue(hairColor instanceof dojo.Color); |
---|
2488 | t.assertTrue(hairColor.toHex() == "#ff0000"); |
---|
2489 | d.callback(true); |
---|
2490 | } |
---|
2491 | function onError(errData){ |
---|
2492 | d.errback(errData); |
---|
2493 | } |
---|
2494 | store.fetchItemByIdentity({identity:"Beaker", onItem:onItem, onError:onError}); |
---|
2495 | return d; // Deferred |
---|
2496 | } |
---|
2497 | }, |
---|
2498 | { |
---|
2499 | name: "Read API: custom_datatype_Color_GeneralMapping", |
---|
2500 | runTest: function(datastore, t){ |
---|
2501 | // summary: |
---|
2502 | // Function to test using literal values with custom datatypes |
---|
2503 | var dataset = { |
---|
2504 | identifier:'name', |
---|
2505 | items: [ |
---|
2506 | { name:'Kermit', species:'frog', color:{_type:'Color', _value:'green'} }, |
---|
2507 | { name:'Beaker', hairColor:{_type:'Color', _value:'red'} } |
---|
2508 | ] |
---|
2509 | }; |
---|
2510 | var store = new datastore({ |
---|
2511 | data:dataset, |
---|
2512 | typeMap:{'Color': { |
---|
2513 | type: dojo.Color, |
---|
2514 | deserialize: function(value){ |
---|
2515 | return new dojo.Color(value); |
---|
2516 | } |
---|
2517 | } |
---|
2518 | } |
---|
2519 | }); |
---|
2520 | var d = new doh.Deferred(); |
---|
2521 | function onItem(item){ |
---|
2522 | t.assertTrue(item !== null); |
---|
2523 | var beaker = item; |
---|
2524 | var hairColor = store.getValue(beaker, "hairColor"); |
---|
2525 | t.assertTrue(hairColor instanceof dojo.Color); |
---|
2526 | t.assertTrue(hairColor.toHex() == "#ff0000"); |
---|
2527 | d.callback(true); |
---|
2528 | } |
---|
2529 | function onError(errData){ |
---|
2530 | d.errback(errData); |
---|
2531 | } |
---|
2532 | store.fetchItemByIdentity({identity:"Beaker", onItem:onItem, onError:onError}); |
---|
2533 | return d; // Deferred |
---|
2534 | } |
---|
2535 | }, |
---|
2536 | { |
---|
2537 | name: "Read API: custom_datatype_CustomObject 0 (False) value", |
---|
2538 | runTest: function(datastore, t){ |
---|
2539 | // summary: |
---|
2540 | // Function to test type mapping and _values that are false-like |
---|
2541 | var dataset = { |
---|
2542 | identifier:'name', |
---|
2543 | items: [ |
---|
2544 | { name:'Bob', species:'human', age: {_type:'tests.data.Wrapper', _value:0} }, |
---|
2545 | { name:'Nancy', species:'human', age: {_type:'tests.data.Wrapper', _value:32} } |
---|
2546 | ] |
---|
2547 | }; |
---|
2548 | var store = new datastore({ |
---|
2549 | data:dataset, |
---|
2550 | typeMap:{'tests.data.Wrapper': { |
---|
2551 | type: tests.data.Wrapper, |
---|
2552 | deserialize: function(value){ |
---|
2553 | return new tests.data.Wrapper(value); |
---|
2554 | } |
---|
2555 | } |
---|
2556 | } |
---|
2557 | }); |
---|
2558 | var d = new doh.Deferred(); |
---|
2559 | function onItem(item){ |
---|
2560 | t.assertTrue(item !== null); |
---|
2561 | var bob = item; |
---|
2562 | var age = store.getValue(item, "age"); |
---|
2563 | t.assertTrue(age instanceof tests.data.Wrapper); |
---|
2564 | t.assertTrue(age.toString() == "WRAPPER: [0]"); |
---|
2565 | d.callback(true); |
---|
2566 | } |
---|
2567 | function onError(errData){ |
---|
2568 | d.errback(errData); |
---|
2569 | } |
---|
2570 | store.fetchItemByIdentity({identity:"Bob", onItem:onItem, onError:onError}); |
---|
2571 | return d; // Deferred |
---|
2572 | } |
---|
2573 | }, |
---|
2574 | { |
---|
2575 | name: "Read API: custom_datatype_CustomObject Boolean False values", |
---|
2576 | runTest: function(datastore, t){ |
---|
2577 | // summary: |
---|
2578 | // Function to test type mapping and _values that are false-like |
---|
2579 | var dataset = { |
---|
2580 | identifier:'name', |
---|
2581 | items: [ |
---|
2582 | { name:'Bob', isHuman: {_type:'tests.data.Wrapper', _value:false} }, |
---|
2583 | { name:'Nancy', isHuman: {_type:'tests.data.Wrapper', _value: true} } |
---|
2584 | ] |
---|
2585 | }; |
---|
2586 | var store = new datastore({ |
---|
2587 | data:dataset, |
---|
2588 | typeMap:{'tests.data.Wrapper': { |
---|
2589 | type: tests.data.Wrapper, |
---|
2590 | deserialize: function(value){ |
---|
2591 | return new tests.data.Wrapper(value); |
---|
2592 | } |
---|
2593 | } |
---|
2594 | } |
---|
2595 | }); |
---|
2596 | var d = new doh.Deferred(); |
---|
2597 | function onItem(item){ |
---|
2598 | t.assertTrue(item !== null); |
---|
2599 | var bob = item; |
---|
2600 | var isHuman = store.getValue(item, "isHuman"); |
---|
2601 | t.assertTrue(isHuman instanceof tests.data.Wrapper); |
---|
2602 | t.assertTrue(isHuman.toString() == "WRAPPER: [false]"); |
---|
2603 | d.callback(true); |
---|
2604 | } |
---|
2605 | function onError(errData){ |
---|
2606 | d.errback(errData); |
---|
2607 | } |
---|
2608 | store.fetchItemByIdentity({identity:"Bob", onItem:onItem, onError:onError}); |
---|
2609 | return d; // Deferred |
---|
2610 | } |
---|
2611 | }, |
---|
2612 | { |
---|
2613 | name: "Read API: custom_datatype_CustomObject Empty String values", |
---|
2614 | runTest: function(datastore, t){ |
---|
2615 | // summary: |
---|
2616 | // Function to test type mapping and _values that are false-like |
---|
2617 | var dataset = { |
---|
2618 | identifier:'name', |
---|
2619 | items: [ |
---|
2620 | { name:'Bob', lastName: {_type:'tests.data.Wrapper', _value:""} }, |
---|
2621 | { name:'Nancy', lastName: {_type:'tests.data.Wrapper', _value: "Doe"} } |
---|
2622 | ] |
---|
2623 | }; |
---|
2624 | var store = new datastore({ |
---|
2625 | data:dataset, |
---|
2626 | typeMap:{'tests.data.Wrapper': { |
---|
2627 | type: tests.data.Wrapper, |
---|
2628 | deserialize: function(value){ |
---|
2629 | return new tests.data.Wrapper(value); |
---|
2630 | } |
---|
2631 | } |
---|
2632 | } |
---|
2633 | }); |
---|
2634 | var d = new doh.Deferred(); |
---|
2635 | function onItem(item){ |
---|
2636 | t.assertTrue(item !== null); |
---|
2637 | var bob = item; |
---|
2638 | var lastName = store.getValue(item, "lastName"); |
---|
2639 | t.assertTrue(lastName instanceof tests.data.Wrapper); |
---|
2640 | t.assertTrue(lastName.toString() == "WRAPPER: []"); |
---|
2641 | d.callback(true); |
---|
2642 | } |
---|
2643 | function onError(errData){ |
---|
2644 | d.errback(errData); |
---|
2645 | } |
---|
2646 | store.fetchItemByIdentity({identity:"Bob", onItem:onItem, onError:onError}); |
---|
2647 | return d; // Deferred |
---|
2648 | } |
---|
2649 | }, |
---|
2650 | { |
---|
2651 | name: "Read API: custom_datatype_CustomObject explicit null values", |
---|
2652 | runTest: function(datastore, t){ |
---|
2653 | // summary: |
---|
2654 | // Function to test type mapping and _values that are false-like |
---|
2655 | var dataset = { |
---|
2656 | identifier:'name', |
---|
2657 | items: [ |
---|
2658 | { name:'Bob', lastName: {_type:'tests.data.Wrapper', _value:null} }, |
---|
2659 | { name:'Nancy', lastName: {_type:'tests.data.Wrapper', _value: "Doe"} } |
---|
2660 | ] |
---|
2661 | }; |
---|
2662 | var store = new datastore({ |
---|
2663 | data:dataset, |
---|
2664 | typeMap:{'tests.data.Wrapper': { |
---|
2665 | type: tests.data.Wrapper, |
---|
2666 | deserialize: function(value){ |
---|
2667 | return new tests.data.Wrapper(value); |
---|
2668 | } |
---|
2669 | } |
---|
2670 | } |
---|
2671 | }); |
---|
2672 | var d = new doh.Deferred(); |
---|
2673 | function onItem(item){ |
---|
2674 | t.assertTrue(item !== null); |
---|
2675 | var bob = item; |
---|
2676 | var lastName = store.getValue(item, "lastName"); |
---|
2677 | t.assertTrue(lastName instanceof tests.data.Wrapper); |
---|
2678 | t.assertTrue(lastName.toString() == "WRAPPER: [null]"); |
---|
2679 | d.callback(true); |
---|
2680 | } |
---|
2681 | function onError(errData){ |
---|
2682 | d.errback(errData); |
---|
2683 | } |
---|
2684 | store.fetchItemByIdentity({identity:"Bob", onItem:onItem, onError:onError}); |
---|
2685 | return d; // Deferred |
---|
2686 | } |
---|
2687 | }, |
---|
2688 | { |
---|
2689 | name: "Read API: custom_datatype_CustomObject explicit undefined value", |
---|
2690 | runTest: function(datastore, t){ |
---|
2691 | // summary: |
---|
2692 | // Function to test type mapping and _values that are false-like |
---|
2693 | var dataset = { |
---|
2694 | identifier:'name', |
---|
2695 | items: [ |
---|
2696 | { name:'Bob', lastName: {_type:'tests.data.Wrapper', _value: undefined} }, |
---|
2697 | { name:'Nancy', lastName: {_type:'tests.data.Wrapper', _value: "Doe"} } |
---|
2698 | ] |
---|
2699 | }; |
---|
2700 | var store = new datastore({ |
---|
2701 | data:dataset, |
---|
2702 | typeMap:{'tests.data.Wrapper': { |
---|
2703 | type: tests.data.Wrapper, |
---|
2704 | deserialize: function(value){ |
---|
2705 | return new tests.data.Wrapper(value); |
---|
2706 | } |
---|
2707 | } |
---|
2708 | } |
---|
2709 | }); |
---|
2710 | var d = new doh.Deferred(); |
---|
2711 | function onItem(item){ |
---|
2712 | t.assertTrue(item !== null); |
---|
2713 | var bob = item; |
---|
2714 | var lastName = store.getValue(item, "lastName"); |
---|
2715 | t.assertTrue(lastName instanceof tests.data.Wrapper); |
---|
2716 | t.assertTrue(lastName.toString() == "WRAPPER: [undefined]"); |
---|
2717 | d.callback(true); |
---|
2718 | } |
---|
2719 | function onError(errData){ |
---|
2720 | d.errback(errData); |
---|
2721 | } |
---|
2722 | store.fetchItemByIdentity({identity:"Bob", onItem:onItem, onError:onError}); |
---|
2723 | return d; // Deferred |
---|
2724 | } |
---|
2725 | }, |
---|
2726 | { |
---|
2727 | name: "Read API: hierarchical_data", |
---|
2728 | runTest: function(datastore, t){ |
---|
2729 | //var store = new datastore(tests.data.readOnlyItemFileTestTemplates.testFile["geography_hierarchy_small"]); |
---|
2730 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small")); |
---|
2731 | var d = new doh.Deferred(); |
---|
2732 | function onComplete(items, request){ |
---|
2733 | t.assertEqual(items.length, 1); |
---|
2734 | var northAmerica = items[0]; |
---|
2735 | var canada = store.getValue(northAmerica, "countries"); |
---|
2736 | var toronto = store.getValue(canada, "cities"); |
---|
2737 | t.assertEqual(store.getValue(canada, "name"), "Canada"); |
---|
2738 | t.assertEqual(store.getValue(toronto, "name"), "Toronto"); |
---|
2739 | d.callback(true); |
---|
2740 | } |
---|
2741 | function onError(errData){ |
---|
2742 | d.errback(errData); |
---|
2743 | } |
---|
2744 | store.fetch({ |
---|
2745 | query: {name: "North America"}, |
---|
2746 | onComplete: onComplete, |
---|
2747 | onError: onError |
---|
2748 | }); |
---|
2749 | |
---|
2750 | return d; // Deferred |
---|
2751 | } |
---|
2752 | }, |
---|
2753 | { |
---|
2754 | name: "Read API: close (clearOnClose: true)", |
---|
2755 | runTest: function(datastore, t){ |
---|
2756 | // summary: |
---|
2757 | // Function to test the close api properly clears the store for reload when clearOnClose is set. |
---|
2758 | if (dojo.isBrowser) { |
---|
2759 | var params = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
2760 | params.clearOnClose = true; |
---|
2761 | params.urlPreventCache = true; |
---|
2762 | var store = new datastore(params); |
---|
2763 | |
---|
2764 | var d = new doh.Deferred(); |
---|
2765 | function onItem(item){ |
---|
2766 | var error = null; |
---|
2767 | try { |
---|
2768 | t.assertTrue(item !== null); |
---|
2769 | var ec = item; |
---|
2770 | var val = store.getValue(ec, "name"); |
---|
2771 | t.assertEqual("Ecuador", val); |
---|
2772 | |
---|
2773 | store.close(); |
---|
2774 | //Check some internals here. Do not normally access these! |
---|
2775 | t.assertTrue(store._arrayOfAllItems.length === 0); |
---|
2776 | t.assertTrue(store._loadFinished === false); |
---|
2777 | }catch (e){ |
---|
2778 | error = e; |
---|
2779 | } |
---|
2780 | if (error) { |
---|
2781 | d.errback(error); |
---|
2782 | }else{ |
---|
2783 | d.callback(true); |
---|
2784 | } |
---|
2785 | } |
---|
2786 | function onError(errData){ |
---|
2787 | d.errback(errData); |
---|
2788 | } |
---|
2789 | store.fetchItemByIdentity({identity:"ec", onItem:onItem, onError:onError}); |
---|
2790 | return d; // Deferred |
---|
2791 | } |
---|
2792 | } |
---|
2793 | }, |
---|
2794 | { |
---|
2795 | name: "Read API: close (clearOnClose: true, reset url.)", |
---|
2796 | runTest: function(datastore, t){ |
---|
2797 | // summary: |
---|
2798 | // Function to test the close api properly clears the store for reload when clearOnClose is set. |
---|
2799 | if (dojo.isBrowser) { |
---|
2800 | var params = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
2801 | params.clearOnClose = true; |
---|
2802 | params.urlPreventCache = true; |
---|
2803 | var store = new datastore(params); |
---|
2804 | |
---|
2805 | var d = new doh.Deferred(); |
---|
2806 | function onItem(item){ |
---|
2807 | var error = null; |
---|
2808 | try { |
---|
2809 | t.assertTrue(item !== null); |
---|
2810 | var ec = item; |
---|
2811 | var val = store.getValue(ec, "name"); |
---|
2812 | t.assertEqual("Ecuador", val); |
---|
2813 | |
---|
2814 | store.close(); |
---|
2815 | //Check some internals here. Do not normally access these! |
---|
2816 | t.assertTrue(store._arrayOfAllItems.length === 0); |
---|
2817 | t.assertTrue(store._loadFinished === false); |
---|
2818 | |
---|
2819 | store.url = require.toUrl("tests/data/countries_withNull.json"); |
---|
2820 | function onItem2 (item){ |
---|
2821 | var err; |
---|
2822 | try{ |
---|
2823 | t.assertTrue(item !== null); |
---|
2824 | var val = store.getValue(item, "name"); |
---|
2825 | t.assertEqual(null, val); |
---|
2826 | }catch(e){ |
---|
2827 | err = e; |
---|
2828 | } |
---|
2829 | if(err){ |
---|
2830 | d.errback(err); |
---|
2831 | }else{ |
---|
2832 | d.callback(true); |
---|
2833 | } |
---|
2834 | } |
---|
2835 | store.fetchItemByIdentity({identity:"ec", onItem:onItem2, onError:onError}); |
---|
2836 | }catch (e){ |
---|
2837 | error = e; |
---|
2838 | } |
---|
2839 | if (error) { |
---|
2840 | d.errback(error); |
---|
2841 | } |
---|
2842 | } |
---|
2843 | function onError(errData){ |
---|
2844 | d.errback(errData); |
---|
2845 | } |
---|
2846 | store.fetchItemByIdentity({identity:"ec", onItem:onItem, onError:onError}); |
---|
2847 | return d; // Deferred |
---|
2848 | } |
---|
2849 | } |
---|
2850 | }, |
---|
2851 | { |
---|
2852 | name: "Read API: fetch, close (clearOnClose: true, reset url.)", |
---|
2853 | runTest: function(datastore, t){ |
---|
2854 | // summary: |
---|
2855 | // Function to test the close api properly clears the store for reload when clearOnClose is set. |
---|
2856 | if (dojo.isBrowser) { |
---|
2857 | var params = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
2858 | params.clearOnClose = true; |
---|
2859 | params.urlPreventCache = true; |
---|
2860 | var store = new datastore(params); |
---|
2861 | |
---|
2862 | var d = new doh.Deferred(); |
---|
2863 | function onItem(item){ |
---|
2864 | var error = null; |
---|
2865 | try { |
---|
2866 | t.assertTrue(item !== null); |
---|
2867 | var ec = item; |
---|
2868 | var val = store.getValue(ec, "name"); |
---|
2869 | t.assertEqual("Ecuador", val); |
---|
2870 | |
---|
2871 | store.close(); |
---|
2872 | //Check some internals here. Do not normally access these! |
---|
2873 | t.assertTrue(store._arrayOfAllItems.length === 0); |
---|
2874 | t.assertTrue(store._loadFinished === false); |
---|
2875 | |
---|
2876 | store.url = require.toUrl("tests/data/countries_withNull.json"); |
---|
2877 | function onComplete (items){ |
---|
2878 | var err; |
---|
2879 | try{ |
---|
2880 | t.assertEqual(1, items.length); |
---|
2881 | var item = items[0]; |
---|
2882 | t.assertTrue(item !== null); |
---|
2883 | var val = store.getValue(item, "name"); |
---|
2884 | t.assertEqual(null, val); |
---|
2885 | }catch(e){ |
---|
2886 | err = e; |
---|
2887 | } |
---|
2888 | if(err){ |
---|
2889 | d.errback(err); |
---|
2890 | }else{ |
---|
2891 | d.callback(true); |
---|
2892 | } |
---|
2893 | } |
---|
2894 | store.fetch({query: {abbr:"ec"}, onComplete:onComplete, onError:onError}); |
---|
2895 | }catch (e){ |
---|
2896 | error = e; |
---|
2897 | } |
---|
2898 | if (error) { |
---|
2899 | d.errback(error); |
---|
2900 | } |
---|
2901 | } |
---|
2902 | function onError(errData){ |
---|
2903 | d.errback(errData); |
---|
2904 | } |
---|
2905 | store.fetchItemByIdentity({identity:"ec", onItem:onItem, onError:onError}); |
---|
2906 | return d; // Deferred |
---|
2907 | } |
---|
2908 | } |
---|
2909 | }, |
---|
2910 | { |
---|
2911 | name: "Read API: close (clearOnClose: true, reset _jsonFileUrl.)", |
---|
2912 | runTest: function(datastore, t){ |
---|
2913 | // summary: |
---|
2914 | // Function to test the close api properly clears the store for reload when clearOnClose is set. |
---|
2915 | if (dojo.isBrowser) { |
---|
2916 | var params = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
2917 | params.clearOnClose = true; |
---|
2918 | params.urlPreventCache = true; |
---|
2919 | var store = new datastore(params); |
---|
2920 | |
---|
2921 | var d = new doh.Deferred(); |
---|
2922 | function onItem(item){ |
---|
2923 | var error = null; |
---|
2924 | try { |
---|
2925 | t.assertTrue(item !== null); |
---|
2926 | var ec = item; |
---|
2927 | var val = store.getValue(ec, "name"); |
---|
2928 | t.assertEqual("Ecuador", val); |
---|
2929 | |
---|
2930 | store.close(); |
---|
2931 | //Check some internals here. Do not normally access these! |
---|
2932 | t.assertTrue(store._arrayOfAllItems.length === 0); |
---|
2933 | t.assertTrue(store._loadFinished === false); |
---|
2934 | |
---|
2935 | store._jsonFileUrl = require.toUrl("tests/data/countries_withNull.json"); |
---|
2936 | function onItem2 (item){ |
---|
2937 | var err; |
---|
2938 | try{ |
---|
2939 | t.assertTrue(item !== null); |
---|
2940 | var val = store.getValue(item, "name"); |
---|
2941 | t.assertEqual(null, val); |
---|
2942 | }catch(e){ |
---|
2943 | err = e; |
---|
2944 | } |
---|
2945 | if(err){ |
---|
2946 | d.errback(err); |
---|
2947 | }else{ |
---|
2948 | d.callback(true); |
---|
2949 | } |
---|
2950 | } |
---|
2951 | store.fetchItemByIdentity({identity:"ec", onItem:onItem2, onError:onError}); |
---|
2952 | }catch (e){ |
---|
2953 | error = e; |
---|
2954 | } |
---|
2955 | if (error) { |
---|
2956 | d.errback(error); |
---|
2957 | } |
---|
2958 | } |
---|
2959 | function onError(errData){ |
---|
2960 | d.errback(errData); |
---|
2961 | } |
---|
2962 | store.fetchItemByIdentity({identity:"ec", onItem:onItem, onError:onError}); |
---|
2963 | return d; // Deferred |
---|
2964 | } |
---|
2965 | } |
---|
2966 | }, |
---|
2967 | { |
---|
2968 | name: "Read API: close (clearOnClose: false)", |
---|
2969 | runTest: function(datastore, t){ |
---|
2970 | // summary: |
---|
2971 | // Function to test the close api properly clears the store for reload when clearOnClose is set. |
---|
2972 | if (dojo.isBrowser) { |
---|
2973 | var params = tests.data.readOnlyItemFileTestTemplates.getTestData("countries"); |
---|
2974 | params.urlPreventCache = true; |
---|
2975 | var store = new datastore(params); |
---|
2976 | |
---|
2977 | var d = new doh.Deferred(); |
---|
2978 | function onItem(item){ |
---|
2979 | var error = null; |
---|
2980 | try { |
---|
2981 | t.assertTrue(item !== null); |
---|
2982 | var ec = item; |
---|
2983 | var val = store.getValue(ec, "name"); |
---|
2984 | t.assertEqual("Ecuador", val); |
---|
2985 | |
---|
2986 | store.close(); |
---|
2987 | //Check some internals here. Do not normally access these! |
---|
2988 | t.assertTrue(store._arrayOfAllItems.length !== 0); |
---|
2989 | t.assertTrue(store._loadFinished === true); |
---|
2990 | }catch (e){ |
---|
2991 | error = e; |
---|
2992 | } |
---|
2993 | if (error) { |
---|
2994 | d.errback(error); |
---|
2995 | }else{ |
---|
2996 | d.callback(true); |
---|
2997 | } |
---|
2998 | } |
---|
2999 | function onError(errData){ |
---|
3000 | d.errback(errData); |
---|
3001 | } |
---|
3002 | store.fetchItemByIdentity({identity:"ec", onItem:onItem, onError:onError}); |
---|
3003 | return d; // Deferred |
---|
3004 | } |
---|
3005 | } |
---|
3006 | }, |
---|
3007 | { |
---|
3008 | name: "Read API: close (clearOnClose: true, reset data.)", |
---|
3009 | runTest: function(datastore, t){ |
---|
3010 | // summary: |
---|
3011 | // Function to test that clear on close and reset of data works. |
---|
3012 | // description: |
---|
3013 | // Function to test that clear on close and reset of data works. |
---|
3014 | var store = new datastore({data: { identifier: "uniqueId", |
---|
3015 | items: [ {uniqueId: 1, value:"foo*bar"}, |
---|
3016 | {uniqueId: 2, value:"bar*foo"}, |
---|
3017 | {uniqueId: 3, value:"boomBam"}, |
---|
3018 | {uniqueId: 4, value:"bit$Bite"}, |
---|
3019 | {uniqueId: 5, value:"ouagadogou"}, |
---|
3020 | {uniqueId: 6, value:"BaBaMaSaRa***Foo"}, |
---|
3021 | {uniqueId: 7, value:"squawl"}, |
---|
3022 | {uniqueId: 8, value:"seaweed"}, |
---|
3023 | {uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"} |
---|
3024 | ] |
---|
3025 | } |
---|
3026 | }); |
---|
3027 | |
---|
3028 | var d = new doh.Deferred(); |
---|
3029 | var firstComplete = function(items, request){ |
---|
3030 | t.assertEqual(items.length, 1); |
---|
3031 | var firstItem = items[0]; |
---|
3032 | |
---|
3033 | //Set the store clearing options and the new data |
---|
3034 | store.clearOnClose = true; |
---|
3035 | store.data = { identifier: "uniqueId", |
---|
3036 | items: [ |
---|
3037 | {uniqueId: 1, value:"foo*bar"}, |
---|
3038 | {uniqueId: 2, value:"bar*foo"}, |
---|
3039 | {uniqueId: 3, value:"boomBam"}, |
---|
3040 | {uniqueId: 4, value:"bit$Bite"}, |
---|
3041 | {uniqueId: 5, value:"ouagadogou"}, |
---|
3042 | {uniqueId: 6, value:"BaBaMaSaRa***Foo"}, |
---|
3043 | {uniqueId: 7, value:"squawl"}, |
---|
3044 | {uniqueId: 8, value:"seaweed"}, |
---|
3045 | {uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"} |
---|
3046 | ] |
---|
3047 | }; |
---|
3048 | store.close(); |
---|
3049 | |
---|
3050 | //Do the next fetch and verify that the next item you get is not |
---|
3051 | //a reference to the same item (data cleared and reloaded. |
---|
3052 | var secondComplete = function(items, request){ |
---|
3053 | try{ |
---|
3054 | t.assertEqual(items.length, 1); |
---|
3055 | var secondItem = items[0]; |
---|
3056 | t.assertTrue(firstItem != null); |
---|
3057 | t.assertTrue(secondItem != null); |
---|
3058 | t.assertTrue(firstItem != secondItem); |
---|
3059 | d.callback(true); |
---|
3060 | }catch(e){ |
---|
3061 | d.errback(e); |
---|
3062 | } |
---|
3063 | } |
---|
3064 | store.fetch({query: {value: "bar\*foo"}, onComplete: secondComplete, onError: error}); |
---|
3065 | }; |
---|
3066 | function error(error, request){ |
---|
3067 | t.assertTrue(false); |
---|
3068 | d.errback(error); |
---|
3069 | } |
---|
3070 | store.fetch({query: {value: "bar\*foo"}, onComplete: firstComplete, onError: error}); |
---|
3071 | return d; |
---|
3072 | } |
---|
3073 | }, |
---|
3074 | { |
---|
3075 | name: "Identity API: no_identifier_specified", |
---|
3076 | runTest: function(datastore, t){ |
---|
3077 | var arrayOfItems = [ |
---|
3078 | {name:"Kermit", color:"green"}, |
---|
3079 | {name:"Miss Piggy", likes:"Kermit"}, |
---|
3080 | {name:"Beaker", hairColor:"red"} |
---|
3081 | ]; |
---|
3082 | var store = new datastore({data:{items:arrayOfItems}}); |
---|
3083 | var d = new doh.Deferred(); |
---|
3084 | function onComplete(items, request){ |
---|
3085 | var features = store.getFeatures(); |
---|
3086 | var hasIdentityFeature = Boolean(features['dojo.data.api.Identity']); |
---|
3087 | t.assertTrue(hasIdentityFeature); |
---|
3088 | for(var i = 0; i < items.length; ++i){ |
---|
3089 | var item = items[i]; |
---|
3090 | var identifier = store.getIdentityAttributes(item); |
---|
3091 | t.assertTrue(identifier === null); |
---|
3092 | var identity = store.getIdentity(item); |
---|
3093 | t.assertTrue(typeof identity == "number"); |
---|
3094 | } |
---|
3095 | d.callback(true); |
---|
3096 | } |
---|
3097 | function reportError(errData, request){ |
---|
3098 | d.errback(true); |
---|
3099 | } |
---|
3100 | store.fetch({onComplete: onComplete, onError: reportError}); |
---|
3101 | return d; // Deferred |
---|
3102 | } |
---|
3103 | }, |
---|
3104 | { |
---|
3105 | name: "Identity API: hierarchical_data", |
---|
3106 | runTest: function(datastore, t){ |
---|
3107 | var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small")); |
---|
3108 | var d = new doh.Deferred(); |
---|
3109 | function onComplete(items, request){ |
---|
3110 | var features = store.getFeatures(); |
---|
3111 | var hasIdentityFeature = Boolean(features['dojo.data.api.Identity']); |
---|
3112 | t.assertTrue(hasIdentityFeature); |
---|
3113 | for(var i = 0; i < items.length; ++i){ |
---|
3114 | var item = items[i]; |
---|
3115 | var identifier = store.getIdentityAttributes(item); |
---|
3116 | t.assertTrue(identifier === null); |
---|
3117 | var identity = store.getIdentity(item); |
---|
3118 | t.assertTrue(typeof identity == "number"); |
---|
3119 | } |
---|
3120 | d.callback(true); |
---|
3121 | } |
---|
3122 | function reportError(errData, request){ |
---|
3123 | d.errback(true); |
---|
3124 | } |
---|
3125 | store.fetch({onComplete: onComplete, onError: reportError}); |
---|
3126 | return d; // Deferred |
---|
3127 | } |
---|
3128 | }, |
---|
3129 | { |
---|
3130 | name: "Read API: functionConformance", |
---|
3131 | runTest: function(datastore, t){ |
---|
3132 | // summary: |
---|
3133 | // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances. |
---|
3134 | // description: |
---|
3135 | // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances. |
---|
3136 | var testStore = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
3137 | var readApi = new dojo.data.api.Read(); |
---|
3138 | var passed = true; |
---|
3139 | |
---|
3140 | for(i in readApi){ |
---|
3141 | if(i.toString().charAt(0) !== '_') |
---|
3142 | { |
---|
3143 | var member = readApi[i]; |
---|
3144 | //Check that all the 'Read' defined functions exist on the test store. |
---|
3145 | if(typeof member === "function"){ |
---|
3146 | var testStoreMember = testStore[i]; |
---|
3147 | if(!(typeof testStoreMember === "function")){ |
---|
3148 | passed = false; |
---|
3149 | break; |
---|
3150 | } |
---|
3151 | } |
---|
3152 | } |
---|
3153 | } |
---|
3154 | t.assertTrue(passed); |
---|
3155 | } |
---|
3156 | }, |
---|
3157 | { |
---|
3158 | name: "Identity API: functionConformance", |
---|
3159 | runTest: function(datastore, t){ |
---|
3160 | // summary: |
---|
3161 | // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances. |
---|
3162 | // description: |
---|
3163 | // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances. |
---|
3164 | var testStore = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); |
---|
3165 | var identityApi = new dojo.data.api.Identity(); |
---|
3166 | var passed = true; |
---|
3167 | |
---|
3168 | for(i in identityApi){ |
---|
3169 | |
---|
3170 | if(i.toString().charAt(0) !== '_') |
---|
3171 | { |
---|
3172 | var member = identityApi[i]; |
---|
3173 | //Check that all the 'Read' defined functions exist on the test store. |
---|
3174 | if(typeof member === "function"){ |
---|
3175 | var testStoreMember = testStore[i]; |
---|
3176 | if(!(typeof testStoreMember === "function")){ |
---|
3177 | passed = false; |
---|
3178 | break; |
---|
3179 | } |
---|
3180 | } |
---|
3181 | } |
---|
3182 | } |
---|
3183 | t.assertTrue(passed); |
---|
3184 | } |
---|
3185 | } |
---|
3186 | ]; |
---|
3187 | |
---|
3188 | }); |
---|