| 1 |
dojo.provide("dojox.data.tests.stores.OpmlStore"); |
| 2 |
dojo.require("dojox.data.OpmlStore"); |
| 3 |
dojo.require("dojo.data.api.Read"); |
| 4 |
dojo.require("dojo.data.api.Identity"); |
| 5 |
|
| 6 |
dojox.data.tests.stores.OpmlStore.getDatasource = function(filepath){ |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
var dataSource = {}; |
| 13 |
if(dojo.isBrowser){ |
| 14 |
dataSource.url = require.toUrl("dojox/data/tests/" + filepath).toString(); |
| 15 |
}else{ |
| 16 |
|
| 17 |
|
| 18 |
switch(filepath){ |
| 19 |
case "stores/geography.xml": |
| 20 |
var opmlData = ""; |
| 21 |
opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n'; |
| 22 |
opmlData += ' <opml version="1.0">\n'; |
| 23 |
opmlData += ' <head>\n'; |
| 24 |
opmlData += ' <title>geography.opml</title>\n'; |
| 25 |
opmlData += ' <dateCreated>2006-11-10</dateCreated>\n'; |
| 26 |
opmlData += ' <dateModified>2006-11-13</dateModified>\n'; |
| 27 |
opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n'; |
| 28 |
opmlData += ' </head>\n'; |
| 29 |
opmlData += ' <body>\n'; |
| 30 |
opmlData += ' <outline text="Africa" type="continent">\n'; |
| 31 |
opmlData += ' <outline text="Egypt" type="country"/>\n'; |
| 32 |
opmlData += ' <outline text="Kenya" type="country">\n'; |
| 33 |
opmlData += ' <outline text="Nairobi" type="city"/>\n'; |
| 34 |
opmlData += ' <outline text="Mombasa" type="city"/>\n'; |
| 35 |
opmlData += ' </outline>\n'; |
| 36 |
opmlData += ' <outline text="Sudan" type="country">\n'; |
| 37 |
opmlData += ' <outline text="Khartoum" type="city"/>\n'; |
| 38 |
opmlData += ' </outline>\n'; |
| 39 |
opmlData += ' </outline>\n'; |
| 40 |
opmlData += ' <outline text="Asia" type="continent">\n'; |
| 41 |
opmlData += ' <outline text="China" type="country"/>\n'; |
| 42 |
opmlData += ' <outline text="India" type="country"/>\n'; |
| 43 |
opmlData += ' <outline text="Russia" type="country"/>\n'; |
| 44 |
opmlData += ' <outline text="Mongolia" type="country"/>\n'; |
| 45 |
opmlData += ' </outline>\n'; |
| 46 |
opmlData += ' <outline text="Australia" type="continent" population="21 million">\n'; |
| 47 |
opmlData += ' <outline text="Australia" type="country" population="21 million"/>\n'; |
| 48 |
opmlData += ' </outline>\n'; |
| 49 |
opmlData += ' <outline text="Europe" type="continent">\n'; |
| 50 |
opmlData += ' <outline text="Germany" type="country"/>\n'; |
| 51 |
opmlData += ' <outline text="France" type="country"/>\n'; |
| 52 |
opmlData += ' <outline text="Spain" type="country"/>\n'; |
| 53 |
opmlData += ' <outline text="Italy" type="country"/>\n'; |
| 54 |
opmlData += ' </outline>\n'; |
| 55 |
opmlData += ' <outline text="North America" type="continent">\n'; |
| 56 |
opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n'; |
| 57 |
opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n'; |
| 58 |
opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n'; |
| 59 |
opmlData += ' </outline>\n'; |
| 60 |
opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n'; |
| 61 |
opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n'; |
| 62 |
opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n'; |
| 63 |
opmlData += ' </outline>\n'; |
| 64 |
opmlData += ' <outline text="United States of America" type="country"/>\n'; |
| 65 |
opmlData += ' </outline>\n'; |
| 66 |
opmlData += ' <outline text="South America" type="continent">\n'; |
| 67 |
opmlData += ' <outline text="Brazil" type="country" population="186 million"/>\n'; |
| 68 |
opmlData += ' <outline text="Argentina" type="country" population="40 million"/>\n'; |
| 69 |
opmlData += ' </outline>\n'; |
| 70 |
opmlData += ' </body>\n'; |
| 71 |
opmlData += ' </opml>\n'; |
| 72 |
break; |
| 73 |
case "stores/geography_withspeciallabel.xml": |
| 74 |
var opmlData = ""; |
| 75 |
opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n'; |
| 76 |
opmlData += '<opml version="1.0">\n'; |
| 77 |
opmlData += ' <head>\n'; |
| 78 |
opmlData += ' <title>geography.opml</title>\n'; |
| 79 |
opmlData += ' <dateCreated>2006-11-10</dateCreated>\n'; |
| 80 |
opmlData += ' <dateModified>2006-11-13</dateModified>\n'; |
| 81 |
opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n'; |
| 82 |
opmlData += ' </head>\n'; |
| 83 |
opmlData += ' <body>\n'; |
| 84 |
opmlData += ' <outline text="Africa" type="continent" label="Continent/Africa">\n'; |
| 85 |
opmlData += ' <outline text="Egypt" type="country" label="Country/Egypt"/>\n'; |
| 86 |
opmlData += ' <outline text="Kenya" type="country" label="Country/Kenya">\n'; |
| 87 |
opmlData += ' <outline text="Nairobi" type="city" label="City/Nairobi"/>\n'; |
| 88 |
opmlData += ' <outline text="Mombasa" type="city" label="City/Mombasa"/>\n'; |
| 89 |
opmlData += ' </outline>\n'; |
| 90 |
opmlData += ' <outline text="Sudan" type="country" label="Country/Sudan">\n'; |
| 91 |
opmlData += ' <outline text="Khartoum" type="city" label="City/Khartoum"/>\n'; |
| 92 |
opmlData += ' </outline>\n'; |
| 93 |
opmlData += ' </outline>\n'; |
| 94 |
opmlData += ' <outline text="Asia" type="continent" label="Continent/Asia">\n'; |
| 95 |
opmlData += ' <outline text="China" type="country" label="Country/China"/>\n'; |
| 96 |
opmlData += ' <outline text="India" type="country" label="Country/India"/>\n'; |
| 97 |
opmlData += ' <outline text="Russia" type="country" label="Country/Russia"/>\n'; |
| 98 |
opmlData += ' <outline text="Mongolia" type="country" label="Country/Mongolia"/>\n'; |
| 99 |
opmlData += ' </outline>\n'; |
| 100 |
opmlData += ' <outline text="Australia" type="continent" population="21 million" label="Continent/Australia">\n'; |
| 101 |
opmlData += ' <outline text="Australia" type="country" population="21 million" label="Country/Australia"/>\n'; |
| 102 |
opmlData += ' </outline>\n'; |
| 103 |
opmlData += ' <outline text="Europe" type="continent" label="Contintent/Europe">\n'; |
| 104 |
opmlData += ' <outline text="Germany" type="country" label="Country/Germany"/>\n'; |
| 105 |
opmlData += ' <outline text="France" type="country" label="Country/France"/>\n'; |
| 106 |
opmlData += ' <outline text="Spain" type="country" label="Country/Spain"/>\n'; |
| 107 |
opmlData += ' <outline text="Italy" type="country" label="Country/Italy"/>\n'; |
| 108 |
opmlData += ' </outline>\n'; |
| 109 |
opmlData += ' <outline text="North America" type="continent" label="Continent/North America">\n'; |
| 110 |
opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">\n'; |
| 111 |
opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>\n'; |
| 112 |
opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>\n'; |
| 113 |
opmlData += ' </outline>\n'; |
| 114 |
opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">\n'; |
| 115 |
opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>\n'; |
| 116 |
opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>\n'; |
| 117 |
opmlData += ' </outline>\n'; |
| 118 |
opmlData += ' <outline text="United States of America" type="country" label="Country/United States of America"/>\n'; |
| 119 |
opmlData += ' </outline>\n'; |
| 120 |
opmlData += ' <outline text="South America" type="continent" label="Continent/South America">\n'; |
| 121 |
opmlData += ' <outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>\n'; |
| 122 |
opmlData += ' <outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>\n'; |
| 123 |
opmlData += ' </outline>\n'; |
| 124 |
opmlData += ' </body>\n'; |
| 125 |
opmlData += '</opml>\n'; |
| 126 |
break; |
| 127 |
} |
| 128 |
dataSource.data = opmlData; |
| 129 |
} |
| 130 |
return dataSource; |
| 131 |
}; |
| 132 |
|
| 133 |
dojox.data.tests.stores.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){ |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
if(items.length != compareArray.length){ return false; } |
| 138 |
for(var i = 0; i < items.length; i++){ |
| 139 |
if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){ |
| 140 |
return false; |
| 141 |
} |
| 142 |
} |
| 143 |
return true; |
| 144 |
}; |
| 145 |
|
| 146 |
dojox.data.tests.stores.OpmlStore.error = function(t, d, errData){ |
| 147 |
|
| 148 |
|
| 149 |
d.errback(errData); |
| 150 |
}; |
| 151 |
|
| 152 |
doh.register("dojox.data.tests.stores.OpmlStore", |
| 153 |
[ |
| 154 |
function testReadAPI_fetch_all(t){ |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 161 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 162 |
|
| 163 |
var d = new doh.Deferred(); |
| 164 |
function completedAll(items){ |
| 165 |
t.is(6, items.length); |
| 166 |
d.callback(true); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 171 |
return d; |
| 172 |
}, |
| 173 |
function testReadAPI_fetch_one(t){ |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 180 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 181 |
|
| 182 |
var d = new doh.Deferred(); |
| 183 |
function onComplete(items, request){ |
| 184 |
t.is(1, items.length); |
| 185 |
d.callback(true); |
| 186 |
} |
| 187 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 188 |
onComplete: onComplete, |
| 189 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 190 |
}); |
| 191 |
return d; |
| 192 |
}, |
| 193 |
|
| 194 |
function testReadAPI_fetch_one_Multiple(t){ |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 201 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 202 |
|
| 203 |
var d = new doh.Deferred(); |
| 204 |
var done = [false,false]; |
| 205 |
function onCompleteOne(items, request){ |
| 206 |
done[0] = true; |
| 207 |
t.is(1, items.length); |
| 208 |
if(done[0] && done[1]){ |
| 209 |
d.callback(true); |
| 210 |
} |
| 211 |
} |
| 212 |
function onCompleteTwo(items, request){ |
| 213 |
done[1] = true; |
| 214 |
t.is(1, items.length); |
| 215 |
if(done[0] && done[1]){ |
| 216 |
d.callback(true); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 221 |
onComplete: onCompleteOne, |
| 222 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 223 |
}); |
| 224 |
|
| 225 |
opmlStore.fetch({ query: {text: "North America"}, |
| 226 |
onComplete: onCompleteTwo, |
| 227 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 228 |
}); |
| 229 |
|
| 230 |
return d; |
| 231 |
}, |
| 232 |
|
| 233 |
function testReadAPI_fetch_one_MultipleMixed(t){ |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 240 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 241 |
|
| 242 |
var d = new doh.Deferred(); |
| 243 |
|
| 244 |
var done = [false, false]; |
| 245 |
function onComplete(items, request){ |
| 246 |
done[0] = true; |
| 247 |
t.is(1, items.length); |
| 248 |
console.log("Found item: " + opmlStore.getValue(items[0],"text") + " with identity: " + opmlStore.getIdentity(items[0])); |
| 249 |
t.is(0, opmlStore.getIdentity(items[0])); |
| 250 |
if(done[0] && done[1]){ |
| 251 |
d.callback(true); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
function onItem(item){ |
| 256 |
done[1] = true; |
| 257 |
t.assertTrue(item !== null); |
| 258 |
console.log("Found item: " + opmlStore.getValue(item,"text")); |
| 259 |
t.is('Egypt', opmlStore.getValue(item,"text")); |
| 260 |
t.is(1, opmlStore.getIdentity(item)); |
| 261 |
if(done[0] && done[1]){ |
| 262 |
d.callback(true); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
opmlStore.fetch({ query: {text: "Africa"}, |
| 267 |
onComplete: onComplete, |
| 268 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 269 |
}); |
| 270 |
|
| 271 |
opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 272 |
|
| 273 |
return d; |
| 274 |
}, |
| 275 |
|
| 276 |
function testReadAPI_fetch_one_deep(t){ |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 283 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 284 |
|
| 285 |
var d = new doh.Deferred(); |
| 286 |
function onComplete(items, request){ |
| 287 |
t.is(1, items.length); |
| 288 |
d.callback(true); |
| 289 |
} |
| 290 |
opmlStore.fetch({ query: {text: "Mexico City"}, |
| 291 |
queryOptions: {deep:true}, |
| 292 |
onComplete: onComplete, |
| 293 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 294 |
}); |
| 295 |
return d; |
| 296 |
}, |
| 297 |
|
| 298 |
function testReadAPI_fetch_one_deep_off(t){ |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 305 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 306 |
|
| 307 |
var d = new doh.Deferred(); |
| 308 |
function onComplete(items, request){ |
| 309 |
|
| 310 |
t.is(0, items.length); |
| 311 |
d.callback(true); |
| 312 |
} |
| 313 |
opmlStore.fetch({ query: {text: "Mexico City"}, |
| 314 |
onComplete: onComplete, |
| 315 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 316 |
}); |
| 317 |
return d; |
| 318 |
}, |
| 319 |
|
| 320 |
function testReadAPI_fetch_all_streaming(t){ |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 327 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 328 |
|
| 329 |
var d = new doh.Deferred(); |
| 330 |
count = 0; |
| 331 |
|
| 332 |
function onBegin(size, requestObj){ |
| 333 |
t.is(6, size); |
| 334 |
} |
| 335 |
function onItem(item, requestObj){ |
| 336 |
t.assertTrue(opmlStore.isItem(item)); |
| 337 |
count++; |
| 338 |
} |
| 339 |
function onComplete(items, request){ |
| 340 |
t.is(6, count); |
| 341 |
t.is(null, items); |
| 342 |
d.callback(true); |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
opmlStore.fetch({ onBegin: onBegin, |
| 347 |
onItem: onItem, |
| 348 |
onComplete: onComplete, |
| 349 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 350 |
}); |
| 351 |
return d; |
| 352 |
}, |
| 353 |
function testReadAPI_fetch_paging(t){ |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 360 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 361 |
|
| 362 |
var d = new doh.Deferred(); |
| 363 |
function dumpFirstFetch(items, request){ |
| 364 |
t.is(5, items.length); |
| 365 |
request.start = 3; |
| 366 |
request.count = 1; |
| 367 |
request.onComplete = dumpSecondFetch; |
| 368 |
opmlStore.fetch(request); |
| 369 |
} |
| 370 |
|
| 371 |
function dumpSecondFetch(items, request){ |
| 372 |
t.is(1, items.length); |
| 373 |
request.start = 0; |
| 374 |
request.count = 5; |
| 375 |
request.onComplete = dumpThirdFetch; |
| 376 |
opmlStore.fetch(request); |
| 377 |
} |
| 378 |
|
| 379 |
function dumpThirdFetch(items, request){ |
| 380 |
t.is(5, items.length); |
| 381 |
request.start = 2; |
| 382 |
request.count = 20; |
| 383 |
request.onComplete = dumpFourthFetch; |
| 384 |
opmlStore.fetch(request); |
| 385 |
} |
| 386 |
|
| 387 |
function dumpFourthFetch(items, request){ |
| 388 |
t.is(4, items.length); |
| 389 |
request.start = 9; |
| 390 |
request.count = 100; |
| 391 |
request.onComplete = dumpFifthFetch; |
| 392 |
opmlStore.fetch(request); |
| 393 |
} |
| 394 |
|
| 395 |
function dumpFifthFetch(items, request){ |
| 396 |
t.is(0, items.length); |
| 397 |
request.start = 2; |
| 398 |
request.count = 20; |
| 399 |
request.onComplete = dumpSixthFetch; |
| 400 |
opmlStore.fetch(request); |
| 401 |
} |
| 402 |
|
| 403 |
function dumpSixthFetch(items, request){ |
| 404 |
t.is(4, items.length); |
| 405 |
d.callback(true); |
| 406 |
} |
| 407 |
|
| 408 |
function completed(items, request){ |
| 409 |
t.is(6, items.length); |
| 410 |
request.start = 1; |
| 411 |
request.count = 5; |
| 412 |
request.onComplete = dumpFirstFetch; |
| 413 |
opmlStore.fetch(request); |
| 414 |
} |
| 415 |
|
| 416 |
opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 417 |
return d; |
| 418 |
|
| 419 |
}, |
| 420 |
function testReadAPI_getLabel(t){ |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 427 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 428 |
|
| 429 |
var d = new doh.Deferred(); |
| 430 |
function onComplete(items, request){ |
| 431 |
t.assertEqual(items.length, 1); |
| 432 |
var label = opmlStore.getLabel(items[0]); |
| 433 |
t.assertTrue(label !== null); |
| 434 |
t.assertEqual("Asia", label); |
| 435 |
d.callback(true); |
| 436 |
} |
| 437 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 438 |
onComplete: onComplete, |
| 439 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 440 |
}); |
| 441 |
return d; |
| 442 |
}, |
| 443 |
function testReadAPI_getLabelAttributes(t){ |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 450 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 451 |
|
| 452 |
var d = new doh.Deferred(); |
| 453 |
function onComplete(items, request){ |
| 454 |
t.assertEqual(items.length, 1); |
| 455 |
var labelList = opmlStore.getLabelAttributes(items[0]); |
| 456 |
t.assertTrue(dojo.isArray(labelList)); |
| 457 |
t.assertEqual("text", labelList[0]); |
| 458 |
d.callback(true); |
| 459 |
} |
| 460 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 461 |
onComplete: onComplete, |
| 462 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 463 |
}); |
| 464 |
return d; |
| 465 |
}, |
| 466 |
|
| 467 |
function testReadAPI_getLabel_nondefault(t){ |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml"); |
| 474 |
args.label="label"; |
| 475 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 476 |
|
| 477 |
var d = new doh.Deferred(); |
| 478 |
function onComplete(items, request){ |
| 479 |
t.assertEqual(items.length, 1); |
| 480 |
var label = opmlStore.getLabel(items[0]); |
| 481 |
t.assertTrue(label !== null); |
| 482 |
t.assertEqual("Continent/Asia", label); |
| 483 |
d.callback(true); |
| 484 |
} |
| 485 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 486 |
onComplete: onComplete, |
| 487 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 488 |
}); |
| 489 |
return d; |
| 490 |
}, |
| 491 |
function testReadAPI_getLabelAttributes_nondefault(t){ |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml"); |
| 498 |
args.label="label"; |
| 499 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 500 |
|
| 501 |
var d = new doh.Deferred(); |
| 502 |
function onComplete(items, request){ |
| 503 |
t.assertEqual(items.length, 1); |
| 504 |
var labelList = opmlStore.getLabelAttributes(items[0]); |
| 505 |
t.assertTrue(dojo.isArray(labelList)); |
| 506 |
t.assertEqual("label", labelList[0]); |
| 507 |
d.callback(true); |
| 508 |
} |
| 509 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 510 |
onComplete: onComplete, |
| 511 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 512 |
}); |
| 513 |
return d; |
| 514 |
}, |
| 515 |
|
| 516 |
function testReadAPI_getValue(t){ |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 523 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 524 |
|
| 525 |
var d = new doh.Deferred(); |
| 526 |
function completedAll(items){ |
| 527 |
t.is(6, items.length); |
| 528 |
|
| 529 |
t.is("Africa", opmlStore.getValue(items[0],"text")); |
| 530 |
t.is("Asia", opmlStore.getValue(items[1],"text")); |
| 531 |
t.is("Australia", opmlStore.getValue(items[2],"text")); |
| 532 |
t.is("Europe", opmlStore.getValue(items[3],"text")); |
| 533 |
t.is("North America", opmlStore.getValue(items[4],"text")); |
| 534 |
t.is("South America", opmlStore.getValue(items[5],"text")); |
| 535 |
|
| 536 |
t.is("continent", opmlStore.getValue(items[1],"type")); |
| 537 |
t.is("21 million", opmlStore.getValue(items[2],"population")); |
| 538 |
|
| 539 |
var firstChild = opmlStore.getValue(items[4],"children"); |
| 540 |
t.assertTrue(opmlStore.isItem(firstChild)); |
| 541 |
t.is("Mexico", opmlStore.getValue(firstChild,"text")); |
| 542 |
t.is("country", opmlStore.getValue(firstChild,"type")); |
| 543 |
t.is("108 million", opmlStore.getValue(firstChild,"population")); |
| 544 |
t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area")); |
| 545 |
|
| 546 |
firstChild = opmlStore.getValue(firstChild,"children"); |
| 547 |
t.assertTrue(opmlStore.isItem(firstChild)); |
| 548 |
t.is("Mexico City", opmlStore.getValue(firstChild,"text")); |
| 549 |
t.is("city", opmlStore.getValue(firstChild,"type")); |
| 550 |
t.is("19 million", opmlStore.getValue(firstChild,"population")); |
| 551 |
t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone")); |
| 552 |
|
| 553 |
d.callback(true); |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 558 |
return d; |
| 559 |
}, |
| 560 |
function testReadAPI_getValues(t){ |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 567 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 568 |
|
| 569 |
var d = new doh.Deferred(); |
| 570 |
function completed(items){ |
| 571 |
t.is(1, items.length); |
| 572 |
|
| 573 |
var children = opmlStore.getValues(items[0],"children"); |
| 574 |
t.is(3, children.length); |
| 575 |
for(var i=0; i<children.length; i++){ |
| 576 |
t.assertTrue(opmlStore.isItem(children[i])); |
| 577 |
} |
| 578 |
|
| 579 |
t.is("Mexico", opmlStore.getValues(children[0],"text")[0]); |
| 580 |
t.is("country", opmlStore.getValues(children[0],"type")[0]); |
| 581 |
t.is("108 million", opmlStore.getValues(children[0],"population")[0]); |
| 582 |
t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]); |
| 583 |
|
| 584 |
t.is("Canada", opmlStore.getValues(children[1],"text")[0]); |
| 585 |
t.is("country", opmlStore.getValues(children[1],"type")[0]); |
| 586 |
|
| 587 |
children = opmlStore.getValues(children[1],"children"); |
| 588 |
t.is(2, children.length); |
| 589 |
for(var i=0; i<children.length; i++){ |
| 590 |
t.assertTrue(opmlStore.isItem(children[i])); |
| 591 |
} |
| 592 |
t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]); |
| 593 |
t.is("Toronto", opmlStore.getValues(children[1],"text")[0]); |
| 594 |
|
| 595 |
d.callback(true); |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
opmlStore.fetch({ query: {text: "North America"}, |
| 600 |
onComplete: completed, |
| 601 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 602 |
return d; |
| 603 |
}, |
| 604 |
function testReadAPI_isItem(t){ |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 611 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 612 |
|
| 613 |
var d = new doh.Deferred(); |
| 614 |
function completedAll(items){ |
| 615 |
t.is(6, items.length); |
| 616 |
for(var i=0; i<6; i++){ |
| 617 |
t.assertTrue(opmlStore.isItem(items[i])); |
| 618 |
} |
| 619 |
t.assertTrue(!opmlStore.isItem({})); |
| 620 |
t.assertTrue(!opmlStore.isItem({ item: "not an item" })); |
| 621 |
t.assertTrue(!opmlStore.isItem("not an item")); |
| 622 |
t.assertTrue(!opmlStore.isItem(["not an item"])); |
| 623 |
|
| 624 |
d.callback(true); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 629 |
return d; |
| 630 |
}, |
| 631 |
function testReadAPI_hasAttribute(t){ |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 638 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 639 |
|
| 640 |
var d = new doh.Deferred(); |
| 641 |
function onComplete(items){ |
| 642 |
t.is(1, items.length); |
| 643 |
t.assertTrue(items[0] !== null); |
| 644 |
t.assertTrue(opmlStore.hasAttribute(items[0], "text")); |
| 645 |
t.assertTrue(opmlStore.hasAttribute(items[0], "type")); |
| 646 |
t.assertTrue(!opmlStore.hasAttribute(items[0], "population")); |
| 647 |
t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing")); |
| 648 |
t.assertTrue(!opmlStore.hasAttribute(items[0], "Text")); |
| 649 |
|
| 650 |
|
| 651 |
var passed = false; |
| 652 |
try{ |
| 653 |
opmlStore.hasAttribute(items[0], null); |
| 654 |
}catch (e){ |
| 655 |
passed = true; |
| 656 |
} |
| 657 |
t.assertTrue(passed); |
| 658 |
|
| 659 |
d.callback(true); |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
opmlStore.fetch({ query: {text: "Asia"}, |
| 664 |
onComplete: onComplete, |
| 665 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 666 |
}); |
| 667 |
return d; |
| 668 |
}, |
| 669 |
function testReadAPI_containsValue(t){ |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 676 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 677 |
|
| 678 |
var d = new doh.Deferred(); |
| 679 |
function onComplete(items){ |
| 680 |
t.is(1, items.length); |
| 681 |
t.assertTrue(items[0] !== null); |
| 682 |
t.assertTrue(opmlStore.containsValue(items[0], "text", "North America")); |
| 683 |
t.assertTrue(opmlStore.containsValue(items[0], "type", "continent")); |
| 684 |
t.assertTrue(!opmlStore.containsValue(items[0], "text", "America")); |
| 685 |
t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent")); |
| 686 |
t.assertTrue(!opmlStore.containsValue(items[0], "text", null)); |
| 687 |
|
| 688 |
var children = opmlStore.getValues(items[0], "children"); |
| 689 |
t.assertTrue(opmlStore.containsValue(items[0], "children", children[0])); |
| 690 |
t.assertTrue(opmlStore.containsValue(items[0], "children", children[1])); |
| 691 |
t.assertTrue(opmlStore.containsValue(items[0], "children", children[2])); |
| 692 |
|
| 693 |
|
| 694 |
var passed = false; |
| 695 |
try{ |
| 696 |
opmlStore.containsValue(items[0], null, "foo"); |
| 697 |
}catch (e){ |
| 698 |
passed = true; |
| 699 |
} |
| 700 |
t.assertTrue(passed); |
| 701 |
|
| 702 |
d.callback(true); |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
opmlStore.fetch({ query: {text: "North America"}, |
| 707 |
onComplete: onComplete, |
| 708 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) |
| 709 |
}); |
| 710 |
return d; |
| 711 |
}, |
| 712 |
function testReadAPI_getAttributes(t){ |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 719 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 720 |
|
| 721 |
var d = new doh.Deferred(); |
| 722 |
function onComplete(items){ |
| 723 |
t.is(6, items.length); |
| 724 |
t.assertTrue(opmlStore.isItem(items[0])); |
| 725 |
|
| 726 |
var attributes = opmlStore.getAttributes(items[0]); |
| 727 |
t.is(3, attributes.length); |
| 728 |
for(var i = 0; i < attributes.length; i++){ |
| 729 |
t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children")); |
| 730 |
} |
| 731 |
|
| 732 |
d.callback(true); |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 737 |
return d; |
| 738 |
}, |
| 739 |
function testReadAPI_getFeatures(t){ |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 746 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 747 |
|
| 748 |
var features = opmlStore.getFeatures(); |
| 749 |
var count = 0; |
| 750 |
for(i in features){ |
| 751 |
t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity")); |
| 752 |
count++; |
| 753 |
} |
| 754 |
t.assertTrue(count === 2); |
| 755 |
}, |
| 756 |
function testReadAPI_fetch_patternMatch0(t){ |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 763 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 764 |
|
| 765 |
var d = new doh.Deferred(); |
| 766 |
function completed(items, request){ |
| 767 |
t.is(3, items.length); |
| 768 |
var valueArray = [ "Africa", "Asia", "Australia"]; |
| 769 |
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray)); |
| 770 |
d.callback(true); |
| 771 |
} |
| 772 |
|
| 773 |
opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 774 |
return d; |
| 775 |
}, |
| 776 |
function testReadAPI_fetch_patternMatch1(t){ |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 783 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 784 |
|
| 785 |
var d = new doh.Deferred(); |
| 786 |
function completed(items, request){ |
| 787 |
t.assertTrue(items.length === 2); |
| 788 |
var valueArray = [ "North America", "South America"]; |
| 789 |
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray)); |
| 790 |
d.callback(true); |
| 791 |
} |
| 792 |
|
| 793 |
opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 794 |
return d; |
| 795 |
}, |
| 796 |
function testReadAPI_fetch_patternMatch2(t){ |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 803 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 804 |
|
| 805 |
var d = new doh.Deferred(); |
| 806 |
function completed(items, request){ |
| 807 |
t.is(1, items.length); |
| 808 |
t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe"); |
| 809 |
d.callback(true); |
| 810 |
} |
| 811 |
|
| 812 |
opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 813 |
return d; |
| 814 |
}, |
| 815 |
function testReadAPI_fetch_patternMatch_caseInsensitive(t){ |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 822 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 823 |
|
| 824 |
var d = new doh.Deferred(); |
| 825 |
function completed(items, request){ |
| 826 |
t.is(1, items.length); |
| 827 |
t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia"); |
| 828 |
d.callback(true); |
| 829 |
} |
| 830 |
|
| 831 |
opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 832 |
return d; |
| 833 |
}, |
| 834 |
function testReadAPI_fetch_patternMatch_caseSensitive(t){ |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 841 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 842 |
|
| 843 |
var d = new doh.Deferred(); |
| 844 |
function completed(items, request){ |
| 845 |
t.is(0, items.length); |
| 846 |
d.callback(true); |
| 847 |
} |
| 848 |
|
| 849 |
opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 850 |
return d; |
| 851 |
}, |
| 852 |
function testReadAPI_fetch_sortAlphabetic(t){ |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 859 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 860 |
|
| 861 |
var d = new doh.Deferred(); |
| 862 |
function completed(items, request){ |
| 863 |
|
| 864 |
var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"]; |
| 865 |
t.is(6, items.length); |
| 866 |
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray)); |
| 867 |
d.callback(true); |
| 868 |
} |
| 869 |
|
| 870 |
var sortAttributes = [{attribute: "text"}]; |
| 871 |
opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 872 |
return d; |
| 873 |
}, |
| 874 |
function testReadAPI_fetch_sortAlphabeticDescending(t){ |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 881 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 882 |
|
| 883 |
var d = new doh.Deferred(); |
| 884 |
function completed(items, request){ |
| 885 |
|
| 886 |
var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa" |
| 887 |
]; |
| 888 |
t.is(6, items.length); |
| 889 |
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray)); |
| 890 |
d.callback(true); |
| 891 |
} |
| 892 |
|
| 893 |
var sortAttributes = [{attribute: "text", descending: true}]; |
| 894 |
opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 895 |
return d; |
| 896 |
}, |
| 897 |
function testReadAPI_fetch_sortAlphabeticWithCount(t){ |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 904 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 905 |
|
| 906 |
var d = new doh.Deferred(); |
| 907 |
function completed(items, request){ |
| 908 |
|
| 909 |
var orderedArray = [ "South America", "North America", "Europe", "Australia" |
| 910 |
]; |
| 911 |
t.is(4, items.length); |
| 912 |
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray)); |
| 913 |
d.callback(true); |
| 914 |
} |
| 915 |
|
| 916 |
var sortAttributes = [{attribute: "text", descending: true}]; |
| 917 |
opmlStore.fetch({sort: sortAttributes, |
| 918 |
count: 4, |
| 919 |
onComplete: completed, |
| 920 |
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 921 |
return d; |
| 922 |
}, |
| 923 |
function testReadAPI_functionConformance(t){ |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml")); |
| 930 |
var readApi = new dojo.data.api.Read(); |
| 931 |
var passed = true; |
| 932 |
|
| 933 |
for(i in readApi){ |
| 934 |
if(i.toString().charAt(0) !== '_') |
| 935 |
{ |
| 936 |
var member = readApi[i]; |
| 937 |
|
| 938 |
if(typeof member === "function"){ |
| 939 |
var testStoreMember = testStore[i]; |
| 940 |
if(!(typeof testStoreMember === "function")){ |
| 941 |
passed = false; |
| 942 |
break; |
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
t.assertTrue(passed); |
| 948 |
}, |
| 949 |
function testIdentityAPI_fetchItemByIdentity(t){ |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 956 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 957 |
|
| 958 |
var d = new doh.Deferred(); |
| 959 |
function onItem(item){ |
| 960 |
t.assertTrue(item !== null); |
| 961 |
d.callback(true); |
| 962 |
} |
| 963 |
opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 964 |
return d; |
| 965 |
}, |
| 966 |
|
| 967 |
function testIdentityAPI_fetchItemByIdentity_bad1(t){ |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 974 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 975 |
|
| 976 |
var d = new doh.Deferred(); |
| 977 |
function onItem(item){ |
| 978 |
t.assertTrue(item === null); |
| 979 |
d.callback(true); |
| 980 |
} |
| 981 |
opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 982 |
return d; |
| 983 |
}, |
| 984 |
function testIdentityAPI_fetchItemByIdentity_bad2(t){ |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 991 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 992 |
var d = new doh.Deferred(); |
| 993 |
function onItem(item){ |
| 994 |
t.assertTrue(item === null); |
| 995 |
d.callback(true); |
| 996 |
} |
| 997 |
opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 998 |
return d; |
| 999 |
}, |
| 1000 |
function testIdentityAPI_fetchItemByIdentity_bad3(t){ |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 1007 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 1008 |
var d = new doh.Deferred(); |
| 1009 |
function onItem(item){ |
| 1010 |
t.assertTrue(item === null); |
| 1011 |
d.callback(true); |
| 1012 |
} |
| 1013 |
opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); |
| 1014 |
return d; |
| 1015 |
}, |
| 1016 |
function testIdentityAPI_getIdentity(t){ |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); |
| 1023 |
var opmlStore = new dojox.data.OpmlStore(args); |
| 1024 |
|
| 1025 |
var d = new doh.Deferred(); |
| 1026 |
function completed(items, request){ |
| 1027 |
var passed = true; |
| 1028 |
for(var i = 0; i < items.length; i++){ |
| 1029 |
console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i); |
| 1030 |
if(!(opmlStore.getIdentity(items[i]) == i)){ |
| 1031 |
passed=false; |
| 1032 |
break; |
| 1033 |
} |
| 1034 |
} |
| 1035 |
t.assertTrue(passed); |
| 1036 |
d.callback(true); |
| 1037 |
} |
| 1038 |
|
| 1039 |
|
| 1040 |
opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}}); |
| 1041 |
return d; |
| 1042 |
}, |
| 1043 |
function testIdentityAPI_functionConformance(t){ |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml")); |
| 1050 |
var identityApi = new dojo.data.api.Identity(); |
| 1051 |
var passed = true; |
| 1052 |
|
| 1053 |
for(i in identityApi){ |
| 1054 |
if(i.toString().charAt(0) !== '_') |
| 1055 |
{ |
| 1056 |
var member = identityApi[i]; |
| 1057 |
|
| 1058 |
if(typeof member === "function"){ |
| 1059 |
console.log("Looking at function: [" + i + "]"); |
| 1060 |
var testStoreMember = testStore[i]; |
| 1061 |
if(!(typeof testStoreMember === "function")){ |
| 1062 |
passed = false; |
| 1063 |
break; |
| 1064 |
} |
| 1065 |
} |
| 1066 |
} |
| 1067 |
} |
| 1068 |
t.assertTrue(passed); |
| 1069 |
} |
| 1070 |
] |
| 1071 |
); |
| 1072 |
|