| | 1 | dojo.provide("dojox.tests.data.OpmlStore"); |
| | 2 | dojo.require("dojox.data.OpmlStore"); |
| | 3 | |
| | 4 | dojox.tests.data.OpmlStore.getDatasource = function(filepath){ |
| | 5 | // summary: |
| | 6 | // A simple helper function for getting the sample data used in each of the tests. |
| | 7 | // description: |
| | 8 | // A simple helper function for getting the sample data used in each of the tests. |
| | 9 | |
| | 10 | var dataSource = {}; |
| | 11 | if(dojo.isBrowser){ |
| | 12 | dataSource.url = dojo.moduleUrl("dojox.tests", filepath).toString(); |
| | 13 | }else{ |
| | 14 | // When running tests in Rhino, xhrGet is not available, |
| | 15 | // so we have the file data in the code below. |
| | 16 | switch(filepath){ |
| | 17 | case "data/geography.xml": |
| | 18 | var opmlData = ""; |
| | 19 | opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n'; |
| | 20 | opmlData += ' <opml version="1.0">\n'; |
| | 21 | opmlData += ' <head>\n'; |
| | 22 | opmlData += ' <title>geography.opml</title>\n'; |
| | 23 | opmlData += ' <dateCreated>2006-11-10</dateCreated>\n'; |
| | 24 | opmlData += ' <dateModified>2006-11-13</dateModified>\n'; |
| | 25 | opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n'; |
| | 26 | opmlData += ' </head>\n'; |
| | 27 | opmlData += ' <body>\n'; |
| | 28 | opmlData += ' <outline text="Africa" type="continent">\n'; |
| | 29 | opmlData += ' <outline text="Egypt" type="country"/>\n'; |
| | 30 | opmlData += ' <outline text="Kenya" type="country">\n'; |
| | 31 | opmlData += ' <outline text="Nairobi" type="city"/>\n'; |
| | 32 | opmlData += ' <outline text="Mombasa" type="city"/>\n'; |
| | 33 | opmlData += ' </outline>\n'; |
| | 34 | opmlData += ' <outline text="Sudan" type="country">\n'; |
| | 35 | opmlData += ' <outline text="Khartoum" type="city"/>\n'; |
| | 36 | opmlData += ' </outline>\n'; |
| | 37 | opmlData += ' </outline>\n'; |
| | 38 | opmlData += ' <outline text="Asia" type="continent">\n'; |
| | 39 | opmlData += ' <outline text="China" type="country"/>\n'; |
| | 40 | opmlData += ' <outline text="India" type="country"/>\n'; |
| | 41 | opmlData += ' <outline text="Russia" type="country"/>\n'; |
| | 42 | opmlData += ' <outline text="Mongolia" type="country"/>\n'; |
| | 43 | opmlData += ' </outline>\n'; |
| | 44 | opmlData += ' <outline text="Australia" type="continent" population="21 million">\n'; |
| | 45 | opmlData += ' <outline text="Australia" type="country" population="21 million"/>\n'; |
| | 46 | opmlData += ' </outline>\n'; |
| | 47 | opmlData += ' <outline text="Europe" type="continent">\n'; |
| | 48 | opmlData += ' <outline text="Germany" type="country"/>\n'; |
| | 49 | opmlData += ' <outline text="France" type="country"/>\n'; |
| | 50 | opmlData += ' <outline text="Spain" type="country"/>\n'; |
| | 51 | opmlData += ' <outline text="Italy" type="country"/>\n'; |
| | 52 | opmlData += ' </outline>\n'; |
| | 53 | opmlData += ' <outline text="North America" type="continent">\n'; |
| | 54 | opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n'; |
| | 55 | opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n'; |
| | 56 | opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n'; |
| | 57 | opmlData += ' </outline>\n'; |
| | 58 | opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n'; |
| | 59 | opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n'; |
| | 60 | opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n'; |
| | 61 | opmlData += ' </outline>\n'; |
| | 62 | opmlData += ' <outline text="United States of America" type="country"/>\n'; |
| | 63 | opmlData += ' </outline>\n'; |
| | 64 | opmlData += ' <outline text="South America" type="continent">\n'; |
| | 65 | opmlData += ' <outline text="Brazil" type="country" population="186 million"/>\n'; |
| | 66 | opmlData += ' <outline text="Argentina" type="country" population="40 million"/>\n'; |
| | 67 | opmlData += ' </outline>\n'; |
| | 68 | opmlData += ' </body>\n'; |
| | 69 | opmlData += ' </opml>\n'; |
| | 70 | break; |
| | 71 | } |
| | 72 | dataSource.data = opmlData; |
| | 73 | } |
| | 74 | return dataSource; //Object |
| | 75 | } |
| | 76 | |
| | 77 | dojox.tests.data.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){ |
| | 78 | // summary: |
| | 79 | // A helper function for validating that the items array is ordered |
| | 80 | // the same as the compareArray |
| | 81 | if(items.length != compareArray.length){ return false; } |
| | 82 | for(var i = 0; i < items.length; i++){ |
| | 83 | if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){ |
| | 84 | return false; //Boolean |
| | 85 | } |
| | 86 | } |
| | 87 | return true; //Boolean |
| | 88 | } |
| | 89 | |
| | 90 | dojox.tests.data.OpmlStore.error = function(t, d, errData){ |
| | 91 | // summary: |
| | 92 | // The error callback function to be used for all of the tests. |
| | 93 | d.errback(errData); |
| | 94 | } |
| | 95 | |
| | 96 | tests.register("dojox.tests.data.OpmlStore", |
| | 97 | [ |
| | 98 | function testReadAPI_fetch_all(t){ |
| | 99 | // summary: |
| | 100 | // Simple test of a basic fetch on OpmlStore. |
| | 101 | // description: |
| | 102 | // Simple test of a basic fetch on OpmlStore. |
| | 103 | |
| | 104 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 105 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 106 | |
| | 107 | var d = new tests.Deferred(); |
| | 108 | function completedAll(items){ |
| | 109 | t.is(6, items.length); |
| | 110 | d.callback(true); |
| | 111 | } |
| | 112 | |
| | 113 | //Get everything... |
| | 114 | opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 115 | return d; //Object |
| | 116 | }, |
| | 117 | function testReadAPI_fetch_one(t){ |
| | 118 | // summary: |
| | 119 | // Simple test of a basic fetch on OpmlStore of a single item. |
| | 120 | // description: |
| | 121 | // Simple test of a basic fetch on OpmlStore of a single item. |
| | 122 | |
| | 123 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 124 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 125 | |
| | 126 | var d = new tests.Deferred(); |
| | 127 | function onComplete(items, request){ |
| | 128 | t.is(1, items.length); |
| | 129 | d.callback(true); |
| | 130 | } |
| | 131 | opmlStore.fetch({ query: {text: "Asia"}, |
| | 132 | onComplete: onComplete, |
| | 133 | onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d) |
| | 134 | }); |
| | 135 | return d; //Object |
| | 136 | }, |
| | 137 | function testReadAPI_fetch_all_streaming(t){ |
| | 138 | // summary: |
| | 139 | // Simple test of a basic fetch on OpmlStore. |
| | 140 | // description: |
| | 141 | // Simple test of a basic fetch on OpmlStore. |
| | 142 | |
| | 143 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 144 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 145 | |
| | 146 | var d = new tests.Deferred(); |
| | 147 | count = 0; |
| | 148 | |
| | 149 | function onBegin(size, requestObj){ |
| | 150 | t.is(6, size); |
| | 151 | } |
| | 152 | function onItem(item, requestObj){ |
| | 153 | t.assertTrue(opmlStore.isItem(item)); |
| | 154 | count++; |
| | 155 | } |
| | 156 | function onComplete(items, request){ |
| | 157 | t.is(6, count); |
| | 158 | t.is(null, items); |
| | 159 | d.callback(true); |
| | 160 | } |
| | 161 | |
| | 162 | //Get everything... |
| | 163 | opmlStore.fetch({ onBegin: onBegin, |
| | 164 | onItem: onItem, |
| | 165 | onComplete: onComplete, |
| | 166 | onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d) |
| | 167 | }); |
| | 168 | return d; //Object |
| | 169 | }, |
| | 170 | function testReadAPI_fetch_paging(t){ |
| | 171 | // summary: |
| | 172 | // Test of multiple fetches on a single result. Paging, if you will. |
| | 173 | // description: |
| | 174 | // Test of multiple fetches on a single result. Paging, if you will. |
| | 175 | |
| | 176 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 177 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 178 | |
| | 179 | var d = new tests.Deferred(); |
| | 180 | function dumpFirstFetch(items, request){ |
| | 181 | t.is(5, items.length); |
| | 182 | request.start = 3; |
| | 183 | request.count = 1; |
| | 184 | request.onComplete = dumpSecondFetch; |
| | 185 | opmlStore.fetch(request); |
| | 186 | } |
| | 187 | |
| | 188 | function dumpSecondFetch(items, request){ |
| | 189 | t.is(1, items.length); |
| | 190 | request.start = 0; |
| | 191 | request.count = 5; |
| | 192 | request.onComplete = dumpThirdFetch; |
| | 193 | opmlStore.fetch(request); |
| | 194 | } |
| | 195 | |
| | 196 | function dumpThirdFetch(items, request){ |
| | 197 | t.is(5, items.length); |
| | 198 | request.start = 2; |
| | 199 | request.count = 20; |
| | 200 | request.onComplete = dumpFourthFetch; |
| | 201 | opmlStore.fetch(request); |
| | 202 | } |
| | 203 | |
| | 204 | function dumpFourthFetch(items, request){ |
| | 205 | t.is(4, items.length); |
| | 206 | request.start = 9; |
| | 207 | request.count = 100; |
| | 208 | request.onComplete = dumpFifthFetch; |
| | 209 | opmlStore.fetch(request); |
| | 210 | } |
| | 211 | |
| | 212 | function dumpFifthFetch(items, request){ |
| | 213 | t.is(0, items.length); |
| | 214 | request.start = 2; |
| | 215 | request.count = 20; |
| | 216 | request.onComplete = dumpSixthFetch; |
| | 217 | opmlStore.fetch(request); |
| | 218 | } |
| | 219 | |
| | 220 | function dumpSixthFetch(items, request){ |
| | 221 | t.is(4, items.length); |
| | 222 | d.callback(true); |
| | 223 | } |
| | 224 | |
| | 225 | function completed(items, request){ |
| | 226 | t.is(6, items.length); |
| | 227 | request.start = 1; |
| | 228 | request.count = 5; |
| | 229 | request.onComplete = dumpFirstFetch; |
| | 230 | opmlStore.fetch(request); |
| | 231 | } |
| | 232 | |
| | 233 | opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 234 | return d; //Object |
| | 235 | |
| | 236 | }, |
| | 237 | function testReadAPI_getValue(t){ |
| | 238 | // summary: |
| | 239 | // Simple test of the getValue function of the store. |
| | 240 | // description: |
| | 241 | // Simple test of the getValue function of the store. |
| | 242 | |
| | 243 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 244 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 245 | |
| | 246 | var d = new tests.Deferred(); |
| | 247 | function completedAll(items){ |
| | 248 | t.is(6, items.length); |
| | 249 | |
| | 250 | t.is("Africa", opmlStore.getValue(items[0],"text")); |
| | 251 | t.is("Asia", opmlStore.getValue(items[1],"text")); |
| | 252 | t.is("Australia", opmlStore.getValue(items[2],"text")); |
| | 253 | t.is("Europe", opmlStore.getValue(items[3],"text")); |
| | 254 | t.is("North America", opmlStore.getValue(items[4],"text")); |
| | 255 | t.is("South America", opmlStore.getValue(items[5],"text")); |
| | 256 | |
| | 257 | t.is("continent", opmlStore.getValue(items[1],"type")); |
| | 258 | t.is("21 million", opmlStore.getValue(items[2],"population")); |
| | 259 | |
| | 260 | var firstChild = opmlStore.getValue(items[4],"children"); |
| | 261 | t.assertTrue(opmlStore.isItem(firstChild)); |
| | 262 | t.is("Mexico", opmlStore.getValue(firstChild,"text")); |
| | 263 | t.is("country", opmlStore.getValue(firstChild,"type")); |
| | 264 | t.is("108 million", opmlStore.getValue(firstChild,"population")); |
| | 265 | t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area")); |
| | 266 | |
| | 267 | firstChild = opmlStore.getValue(firstChild,"children"); |
| | 268 | t.assertTrue(opmlStore.isItem(firstChild)); |
| | 269 | t.is("Mexico City", opmlStore.getValue(firstChild,"text")); |
| | 270 | t.is("city", opmlStore.getValue(firstChild,"type")); |
| | 271 | t.is("19 million", opmlStore.getValue(firstChild,"population")); |
| | 272 | t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone")); |
| | 273 | |
| | 274 | d.callback(true); |
| | 275 | } |
| | 276 | |
| | 277 | //Get everything... |
| | 278 | opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 279 | return d; //Object |
| | 280 | }, |
| | 281 | function testReadAPI_getValues(t){ |
| | 282 | // summary: |
| | 283 | // Simple test of the getValues function of the store. |
| | 284 | // description: |
| | 285 | // Simple test of the getValues function of the store. |
| | 286 | |
| | 287 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 288 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 289 | |
| | 290 | var d = new tests.Deferred(); |
| | 291 | function completed(items){ |
| | 292 | t.is(1, items.length); |
| | 293 | |
| | 294 | var children = opmlStore.getValues(items[0],"children"); |
| | 295 | t.is(3, children.length); |
| | 296 | for(var i=0; i<children.length; i++){ |
| | 297 | t.assertTrue(opmlStore.isItem(children[i])); |
| | 298 | } |
| | 299 | |
| | 300 | t.is("Mexico", opmlStore.getValues(children[0],"text")[0]); |
| | 301 | t.is("country", opmlStore.getValues(children[0],"type")[0]); |
| | 302 | t.is("108 million", opmlStore.getValues(children[0],"population")[0]); |
| | 303 | t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]); |
| | 304 | |
| | 305 | t.is("Canada", opmlStore.getValues(children[1],"text")[0]); |
| | 306 | t.is("country", opmlStore.getValues(children[1],"type")[0]); |
| | 307 | |
| | 308 | children = opmlStore.getValues(children[1],"children"); |
| | 309 | t.is(2, children.length); |
| | 310 | for(var i=0; i<children.length; i++){ |
| | 311 | t.assertTrue(opmlStore.isItem(children[i])); |
| | 312 | } |
| | 313 | t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]); |
| | 314 | t.is("Toronto", opmlStore.getValues(children[1],"text")[0]); |
| | 315 | |
| | 316 | d.callback(true); |
| | 317 | } |
| | 318 | |
| | 319 | //Get one item... |
| | 320 | opmlStore.fetch({ query: {text: "North America"}, |
| | 321 | onComplete: completed, |
| | 322 | onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 323 | return d; //Object |
| | 324 | }, |
| | 325 | function testReadAPI_isItem(t){ |
| | 326 | // summary: |
| | 327 | // Simple test of the isItem function of the store |
| | 328 | // description: |
| | 329 | // Simple test of the isItem function of the store |
| | 330 | |
| | 331 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 332 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 333 | |
| | 334 | var d = new tests.Deferred(); |
| | 335 | function completedAll(items){ |
| | 336 | t.is(6, items.length); |
| | 337 | for(var i=0; i<6; i++){ |
| | 338 | t.assertTrue(opmlStore.isItem(items[i])); |
| | 339 | } |
| | 340 | t.assertTrue(!opmlStore.isItem({})); |
| | 341 | t.assertTrue(!opmlStore.isItem({ item: "not an item" })); |
| | 342 | t.assertTrue(!opmlStore.isItem("not an item")); |
| | 343 | t.assertTrue(!opmlStore.isItem(["not an item"])); |
| | 344 | |
| | 345 | d.callback(true); |
| | 346 | } |
| | 347 | |
| | 348 | //Get everything... |
| | 349 | opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 350 | return d; //Object |
| | 351 | }, |
| | 352 | function testReadAPI_hasAttribute(t){ |
| | 353 | // summary: |
| | 354 | // Simple test of the hasAttribute function of the store |
| | 355 | // description: |
| | 356 | // Simple test of the hasAttribute function of the store |
| | 357 | |
| | 358 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 359 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 360 | |
| | 361 | var d = new tests.Deferred(); |
| | 362 | function onComplete(items){ |
| | 363 | t.is(1, items.length); |
| | 364 | t.assertTrue(items[0] !== null); |
| | 365 | t.assertTrue(opmlStore.hasAttribute(items[0], "text")); |
| | 366 | t.assertTrue(opmlStore.hasAttribute(items[0], "type")); |
| | 367 | t.assertTrue(!opmlStore.hasAttribute(items[0], "population")); |
| | 368 | t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing")); |
| | 369 | t.assertTrue(!opmlStore.hasAttribute(items[0], "Text")); |
| | 370 | |
| | 371 | //Test that null attributes throw an exception |
| | 372 | var passed = false; |
| | 373 | try{ |
| | 374 | opmlStore.hasAttribute(items[0], null); |
| | 375 | }catch (e){ |
| | 376 | passed = true; |
| | 377 | } |
| | 378 | t.assertTrue(passed); |
| | 379 | |
| | 380 | d.callback(true); |
| | 381 | } |
| | 382 | |
| | 383 | //Get one item... |
| | 384 | opmlStore.fetch({ query: {text: "Asia"}, |
| | 385 | onComplete: onComplete, |
| | 386 | onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d) |
| | 387 | }); |
| | 388 | return d; //Object |
| | 389 | }, |
| | 390 | function testReadAPI_containsValue(t){ |
| | 391 | // summary: |
| | 392 | // Simple test of the containsValue function of the store |
| | 393 | // description: |
| | 394 | // Simple test of the containsValue function of the store |
| | 395 | |
| | 396 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 397 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 398 | |
| | 399 | var d = new tests.Deferred(); |
| | 400 | function onComplete(items){ |
| | 401 | t.is(1, items.length); |
| | 402 | t.assertTrue(items[0] !== null); |
| | 403 | t.assertTrue(opmlStore.containsValue(items[0], "text", "North America")); |
| | 404 | t.assertTrue(opmlStore.containsValue(items[0], "type", "continent")); |
| | 405 | t.assertTrue(!opmlStore.containsValue(items[0], "text", "America")); |
| | 406 | t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent")); |
| | 407 | t.assertTrue(!opmlStore.containsValue(items[0], "text", null)); |
| | 408 | |
| | 409 | var children = opmlStore.getValues(items[0], "children"); |
| | 410 | t.assertTrue(opmlStore.containsValue(items[0], "children", children[0])); |
| | 411 | t.assertTrue(opmlStore.containsValue(items[0], "children", children[1])); |
| | 412 | t.assertTrue(opmlStore.containsValue(items[0], "children", children[2])); |
| | 413 | |
| | 414 | //Test that null attributes throw an exception |
| | 415 | var passed = false; |
| | 416 | try{ |
| | 417 | opmlStore.containsValue(items[0], null, "foo"); |
| | 418 | }catch (e){ |
| | 419 | passed = true; |
| | 420 | } |
| | 421 | t.assertTrue(passed); |
| | 422 | |
| | 423 | d.callback(true); |
| | 424 | } |
| | 425 | |
| | 426 | //Get one item... |
| | 427 | opmlStore.fetch({ query: {text: "North America"}, |
| | 428 | onComplete: onComplete, |
| | 429 | onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d) |
| | 430 | }); |
| | 431 | return d; //Object |
| | 432 | }, |
| | 433 | function testReadAPI_getAttributes(t){ |
| | 434 | // summary: |
| | 435 | // Simple test of the getAttributes function of the store |
| | 436 | // description: |
| | 437 | // Simple test of the getAttributes function of the store |
| | 438 | |
| | 439 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 440 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 441 | |
| | 442 | var d = new tests.Deferred(); |
| | 443 | function onComplete(items){ |
| | 444 | t.is(6, items.length); |
| | 445 | t.assertTrue(opmlStore.isItem(items[0])); |
| | 446 | |
| | 447 | var attributes = opmlStore.getAttributes(items[0]); |
| | 448 | t.is(3, attributes.length); |
| | 449 | for(var i = 0; i < attributes.length; i++){ |
| | 450 | t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children")); |
| | 451 | } |
| | 452 | |
| | 453 | d.callback(true); |
| | 454 | } |
| | 455 | |
| | 456 | //Get everything... |
| | 457 | opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 458 | return d; //Object |
| | 459 | }, |
| | 460 | function testReadAPI_getFeatures(t){ |
| | 461 | // summary: |
| | 462 | // Simple test of the getFeatures function of the store |
| | 463 | // description: |
| | 464 | // Simple test of the getFeatures function of the store |
| | 465 | |
| | 466 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 467 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 468 | |
| | 469 | var features = opmlStore.getFeatures(); |
| | 470 | var count = 0; |
| | 471 | for(i in features){ |
| | 472 | t.assertTrue((i === "dojo.data.api.Read")); |
| | 473 | count++; |
| | 474 | } |
| | 475 | t.assertTrue(count === 1); |
| | 476 | }, |
| | 477 | function testReadAPI_fetch_patternMatch0(t){ |
| | 478 | // summary: |
| | 479 | // Function to test pattern matching of everything starting with Capital A |
| | 480 | // description: |
| | 481 | // Function to test pattern matching of everything starting with Capital A |
| | 482 | |
| | 483 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 484 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 485 | |
| | 486 | var d = new tests.Deferred(); |
| | 487 | function completed(items, request){ |
| | 488 | t.is(3, items.length); |
| | 489 | var valueArray = [ "Africa", "Asia", "Australia"]; |
| | 490 | t.assertTrue(dojox.tests.data.OpmlStore.verifyItems(opmlStore, items, "text", valueArray)); |
| | 491 | d.callback(true); |
| | 492 | } |
| | 493 | |
| | 494 | opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.tests.data.OpmlStore.error, t, d)}); |
| | 495 | return d; //Object |
| | 496 | }, |
| | 497 | function testReadAPI_fetch_patternMatch1(t){ |
| | 498 | // summary: |
| | 499 | // Function to test pattern matching of everything with America in it. |
| | 500 | // description: |
| | 501 | // Function to test pattern matching of everything with America in it. |
| | 502 | |
| | 503 | var args = dojox.tests.data.OpmlStore.getDatasource("data/geography.xml"); |
| | 504 | var opmlStore = new dojox.data.OpmlStore(args); |
| | 505 | |
| | 506 | var d = new tests.Deferred(); |
| | 507 | function completed(items, request){ |
| | 508 | t.assertTrue(items.length === 2); |
| | 509 | var valueArray = [ "North America", "South America"]; |
| | 510 | t.assertTrue(dojox.tests.data.OpmlStore.verifyItems(opmlStore, items, "text", valueArray)); |
| | 511 | d.callback(true); |