269f9ef41094f7e27706d26628fcf0308dddb73a.svn-base 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. if (!dojo._hasResource["dojox.data.tests.stores.CsvStore"]) { // _hasResource
  2. // checks added
  3. // by build. Do
  4. // not use
  5. // _hasResource
  6. // directly in
  7. // your code.
  8. dojo._hasResource["dojox.data.tests.stores.CsvStore"] = true;
  9. dojo.provide("dojox.data.tests.stores.CsvStore");
  10. dojo.require("dojox.data.CsvStore");
  11. dojo.require("dojo.data.api.Read");
  12. dojo.require("dojo.data.api.Identity");
  13. dojox.data.tests.stores.CsvStore.getDatasource = function(filepath) {
  14. // summary:
  15. // A simple helper function for getting the sample data used in each of
  16. // the tests.
  17. // description:
  18. // A simple helper function for getting the sample data used in each of
  19. // the tests.
  20. var dataSource = {};
  21. if (dojo.isBrowser) {
  22. dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath)
  23. .toString();
  24. } else {
  25. // When running tests in Rhino, xhrGet is not available,
  26. // so we have the file data in the code below.
  27. switch (filepath) {
  28. case "stores/movies.csv" :
  29. var csvData = "";
  30. csvData += "Title, Year, Producer\n";
  31. csvData += "City of God, 2002, Katia Lund\n";
  32. csvData += "Rain,, Christine Jeffs\n";
  33. csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
  34. csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
  35. csvData += "Alien, 1979 , Ridley Scott\n";
  36. csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
  37. csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
  38. break;
  39. case "stores/movies2.csv" :
  40. var csvData = "";
  41. csvData += "Title, Year, Producer\n";
  42. csvData += "City of God, 2002, Katia Lund\n";
  43. csvData += "Rain,\"\", Christine Jeffs\n";
  44. csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
  45. csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
  46. csvData += "Alien, 1979 , Ridley Scott\n";
  47. csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
  48. csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
  49. break;
  50. case "stores/books.csv" :
  51. var csvData = "";
  52. csvData += "Title, Author\n";
  53. csvData += "The Transparent Society, David Brin\n";
  54. csvData += "The First Measured Century, Theodore Caplow\n";
  55. csvData += "Maps in a Mirror, Orson Scott Card\n";
  56. csvData += "Princess Smartypants, Babette Cole\n";
  57. csvData += "Carfree Cities, Crawford J.H.\n";
  58. csvData += "Down and Out in the Magic Kingdom, Cory Doctorow\n";
  59. csvData += "Tax Shift, Alan Thein Durning\n";
  60. csvData += "The Sneetches and other stories, Dr. Seuss\n";
  61. csvData += "News from Tartary, Peter Fleming\n";
  62. break;
  63. case "stores/patterns.csv" :
  64. var csvData = "";
  65. csvData += "uniqueId, value\n";
  66. csvData += "9, jfq4@#!$!@Rf14r14i5u\n";
  67. csvData += "6, BaBaMaSaRa***Foo\n";
  68. csvData += "2, bar*foo\n";
  69. csvData += "8, 123abc\n";
  70. csvData += "4, bit$Bite\n";
  71. csvData += "3, 123abc\n";
  72. csvData += "10, 123abcdefg\n";
  73. csvData += "1, foo*bar\n";
  74. csvData += "7, \n";
  75. csvData += "5, 123abc\n"
  76. break;
  77. }
  78. dataSource.data = csvData;
  79. }
  80. return dataSource; // Object
  81. }
  82. dojox.data.tests.stores.CsvStore.verifyItems = function(csvStore, items,
  83. attribute, compareArray) {
  84. // summary:
  85. // A helper function for validating that the items array is ordered
  86. // the same as the compareArray
  87. if (items.length != compareArray.length) {
  88. return false;
  89. }
  90. for (var i = 0; i < items.length; i++) {
  91. if (!(csvStore.getValue(items[i], attribute) === compareArray[i])) {
  92. return false; // Boolean
  93. }
  94. }
  95. return true; // Boolean
  96. }
  97. dojox.data.tests.stores.CsvStore.error = function(t, d, errData) {
  98. // summary:
  99. // The error callback function to be used for all of the tests.
  100. for (i in errData) {
  101. console.log(errData[i]);
  102. }
  103. d.errback(errData);
  104. }
  105. doh.register("dojox.data.tests.stores.CsvStore", [
  106. function testReadAPI_fetch_all(t) {
  107. // summary:
  108. // Simple test of a basic fetch on CsvStore.
  109. // description:
  110. // Simple test of a basic fetch on CsvStore.
  111. var args = dojox.data.tests.stores.CsvStore
  112. .getDatasource("stores/movies.csv");
  113. var csvStore = new dojox.data.CsvStore(args);
  114. var d = new doh.Deferred();
  115. function completedAll(items) {
  116. t.assertTrue((items.length === 7));
  117. d.callback(true);
  118. }
  119. // Get everything...
  120. csvStore.fetch({
  121. onComplete : completedAll,
  122. onError : dojo.partial(
  123. dojox.data.tests.stores.CsvStore.error, t,
  124. d)
  125. });
  126. return d; // Object
  127. }, function testReadAPI_fetch_all_withEmptyStringField(t) {
  128. // summary:
  129. // Simple test of a basic fetch on CsvStore.
  130. // description:
  131. // Simple test of a basic fetch on CsvStore.
  132. var args = dojox.data.tests.stores.CsvStore
  133. .getDatasource("stores/movies2.csv");
  134. var csvStore = new dojox.data.CsvStore(args);
  135. var d = new doh.Deferred();
  136. function completedAll(items) {
  137. t.assertTrue((items.length === 7));
  138. d.callback(true);
  139. }
  140. // Get everything...
  141. csvStore.fetch({
  142. onComplete : completedAll,
  143. onError : dojo.partial(
  144. dojox.data.tests.stores.CsvStore.error, t,
  145. d)
  146. });
  147. return d; // Object
  148. }, function testReadAPI_fetch_one(t) {
  149. // summary:
  150. // Simple test of a basic fetch on CsvStore of a single item.
  151. // description:
  152. // Simple test of a basic fetch on CsvStore of a single item.
  153. var args = dojox.data.tests.stores.CsvStore
  154. .getDatasource("stores/movies.csv");
  155. var csvStore = new dojox.data.CsvStore(args);
  156. var d = new doh.Deferred();
  157. function onComplete(items, request) {
  158. t.is(1, items.length);
  159. d.callback(true);
  160. }
  161. csvStore.fetch({
  162. query : {
  163. Title : "*Sequel*"
  164. },
  165. onComplete : onComplete,
  166. onError : dojo.partial(
  167. dojox.data.tests.stores.CsvStore.error, t,
  168. d)
  169. });
  170. return d; // Object
  171. }, function testReadAPI_fetch_Multiple(t) {
  172. // summary:
  173. // Simple test of a basic fetch on CsvStore of a single item.
  174. // description:
  175. // Simple test of a basic fetch on CsvStore of a single item.
  176. var args = dojox.data.tests.stores.CsvStore
  177. .getDatasource("stores/movies.csv");
  178. var csvStore = new dojox.data.CsvStore(args);
  179. var d = new doh.Deferred();
  180. var done = [false, false];
  181. function onCompleteOne(items, request) {
  182. done[0] = true;
  183. t.is(1, items.length);
  184. if (done[0] && done[1]) {
  185. d.callback(true);
  186. }
  187. }
  188. function onCompleteTwo(items, request) {
  189. done[1] = true;
  190. t.is(1, items.length);
  191. if (done[0] && done[1]) {
  192. d.callback(true);
  193. }
  194. }
  195. try {
  196. csvStore.fetch({
  197. query : {
  198. Title : "*Sequel*"
  199. },
  200. onComplete : onCompleteOne,
  201. onError : dojo.partial(
  202. dojox.data.tests.stores.CsvStore.error,
  203. t, d)
  204. });
  205. csvStore.fetch({
  206. query : {
  207. Title : "2001:*"
  208. },
  209. onComplete : onCompleteTwo,
  210. onError : dojo.partial(
  211. dojox.data.tests.stores.CsvStore.error,
  212. t, d)
  213. });
  214. } catch (e) {
  215. for (i in e) {
  216. console.log(e[i]);
  217. }
  218. }
  219. return d; // Object
  220. }, function testReadAPI_fetch_MultipleMixed(t) {
  221. // summary:
  222. // Simple test of a basic fetch on CsvStore of a single item.
  223. // description:
  224. // Simple test of a basic fetch on CsvStore of a single item.
  225. var args = dojox.data.tests.stores.CsvStore
  226. .getDatasource("stores/movies.csv");
  227. var csvStore = new dojox.data.CsvStore(args);
  228. var d = new doh.Deferred();
  229. var done = [false, false];
  230. function onComplete(items, request) {
  231. done[0] = true;
  232. t.is(1, items.length);
  233. if (done[0] && done[1]) {
  234. d.callback(true);
  235. }
  236. }
  237. function onItem(item) {
  238. done[1] = true;
  239. t.assertTrue(item !== null);
  240. t.is('Dymtryk "the King", Edward', csvStore.getValue(item,
  241. "Producer"));
  242. t.is('Caine Mutiny, The', csvStore.getValue(item, "Title"));
  243. if (done[0] && done[1]) {
  244. d.callback(true);
  245. }
  246. }
  247. csvStore.fetch({
  248. query : {
  249. Title : "*Sequel*"
  250. },
  251. onComplete : onComplete,
  252. onError : dojo.partial(
  253. dojox.data.tests.stores.CsvStore.error, t,
  254. d)
  255. });
  256. csvStore.fetchItemByIdentity({
  257. identity : "6",
  258. onItem : onItem,
  259. onError : dojo.partial(
  260. dojox.data.tests.stores.CsvStore.error, t,
  261. d)
  262. });
  263. return d; // Object
  264. }, function testReadAPI_fetch_all_streaming(t) {
  265. // summary:
  266. // Simple test of a basic fetch on CsvStore.
  267. // description:
  268. // Simple test of a basic fetch on CsvStore.
  269. var args = dojox.data.tests.stores.CsvStore
  270. .getDatasource("stores/movies.csv");
  271. var csvStore = new dojox.data.CsvStore(args);
  272. var d = new doh.Deferred();
  273. count = 0;
  274. function onBegin(size, requestObj) {
  275. t.assertTrue(size === 7);
  276. }
  277. function onItem(item, requestObj) {
  278. t.assertTrue(csvStore.isItem(item));
  279. count++;
  280. }
  281. function onComplete(items, request) {
  282. t.is(7, count);
  283. t.is(null, items);
  284. d.callback(true);
  285. }
  286. // Get everything...
  287. csvStore.fetch({
  288. onBegin : onBegin,
  289. onItem : onItem,
  290. onComplete : onComplete,
  291. onError : dojo.partial(
  292. dojox.data.tests.stores.CsvStore.error, t,
  293. d)
  294. });
  295. return d; // Object
  296. }, function testReadAPI_fetch_paging(t) {
  297. // summary:
  298. // Test of multiple fetches on a single result. Paging, if you
  299. // will.
  300. // description:
  301. // Test of multiple fetches on a single result. Paging, if you
  302. // will.
  303. var args = dojox.data.tests.stores.CsvStore
  304. .getDatasource("stores/movies.csv");
  305. var csvStore = new dojox.data.CsvStore(args);
  306. var d = new doh.Deferred();
  307. function dumpFirstFetch(items, request) {
  308. t.is(5, items.length);
  309. request.start = 3;
  310. request.count = 1;
  311. request.onComplete = dumpSecondFetch;
  312. csvStore.fetch(request);
  313. }
  314. function dumpSecondFetch(items, request) {
  315. t.is(1, items.length);
  316. request.start = 0;
  317. request.count = 5;
  318. request.onComplete = dumpThirdFetch;
  319. csvStore.fetch(request);
  320. }
  321. function dumpThirdFetch(items, request) {
  322. t.is(5, items.length);
  323. request.start = 2;
  324. request.count = 20;
  325. request.onComplete = dumpFourthFetch;
  326. csvStore.fetch(request);
  327. }
  328. function dumpFourthFetch(items, request) {
  329. t.is(5, items.length);
  330. request.start = 9;
  331. request.count = 100;
  332. request.onComplete = dumpFifthFetch;
  333. csvStore.fetch(request);
  334. }
  335. function dumpFifthFetch(items, request) {
  336. t.is(0, items.length);
  337. request.start = 2;
  338. request.count = 20;
  339. request.onComplete = dumpSixthFetch;
  340. csvStore.fetch(request);
  341. }
  342. function dumpSixthFetch(items, request) {
  343. t.is(5, items.length);
  344. d.callback(true);
  345. }
  346. function completed(items, request) {
  347. t.is(7, items.length);
  348. request.start = 1;
  349. request.count = 5;
  350. request.onComplete = dumpFirstFetch;
  351. csvStore.fetch(request);
  352. }
  353. csvStore.fetch({
  354. onComplete : completed,
  355. onError : dojo.partial(
  356. dojox.data.tests.stores.CsvStore.error, t,
  357. d)
  358. });
  359. return d; // Object
  360. },
  361. function testReadAPI_getLabel(t) {
  362. // summary:
  363. // Simple test of the getLabel function against a store set that
  364. // has a label defined.
  365. // description:
  366. // Simple test of the getLabel function against a store set that
  367. // has a label defined.
  368. var args = dojox.data.tests.stores.CsvStore
  369. .getDatasource("stores/movies.csv");
  370. args.label = "Title";
  371. var csvStore = new dojox.data.CsvStore(args);
  372. var d = new doh.Deferred();
  373. function onComplete(items, request) {
  374. t.assertEqual(items.length, 1);
  375. var label = csvStore.getLabel(items[0]);
  376. t.assertTrue(label !== null);
  377. t.assertEqual("The Sequel to \"Dances With Wolves.\"",
  378. label);
  379. d.callback(true);
  380. }
  381. csvStore.fetch({
  382. query : {
  383. Title : "*Sequel*"
  384. },
  385. onComplete : onComplete,
  386. onError : dojo.partial(
  387. dojox.data.tests.stores.CsvStore.error, t,
  388. d)
  389. });
  390. return d;
  391. }, function testReadAPI_getLabelAttributes(t) {
  392. // summary:
  393. // Simple test of the getLabelAttributes function against a
  394. // store set that has a label defined.
  395. // description:
  396. // Simple test of the getLabelAttributes function against a
  397. // store set that has a label defined.
  398. var args = dojox.data.tests.stores.CsvStore
  399. .getDatasource("stores/movies.csv");
  400. args.label = "Title";
  401. var csvStore = new dojox.data.CsvStore(args);
  402. var d = new doh.Deferred();
  403. function onComplete(items, request) {
  404. t.assertEqual(items.length, 1);
  405. var labelList = csvStore.getLabelAttributes(items[0]);
  406. t.assertTrue(dojo.isArray(labelList));
  407. t.assertEqual("Title", labelList[0]);
  408. d.callback(true);
  409. }
  410. csvStore.fetch({
  411. query : {
  412. Title : "*Sequel*"
  413. },
  414. onComplete : onComplete,
  415. onError : dojo.partial(
  416. dojox.data.tests.stores.CsvStore.error, t,
  417. d)
  418. });
  419. return d;
  420. }, function testReadAPI_getValue(t) {
  421. // summary:
  422. // Simple test of the getValue function of the store.
  423. // description:
  424. // Simple test of the getValue function of the store.
  425. var args = dojox.data.tests.stores.CsvStore
  426. .getDatasource("stores/movies.csv");
  427. var csvStore = new dojox.data.CsvStore(args);
  428. var d = new doh.Deferred();
  429. function onItem(item) {
  430. t.assertTrue(item !== null);
  431. t.is('Dymtryk "the King", Edward', csvStore.getValue(item,
  432. "Producer"));
  433. t.is('Caine Mutiny, The', csvStore.getValue(item, "Title"));
  434. d.callback(true);
  435. }
  436. csvStore.fetchItemByIdentity({
  437. identity : "6",
  438. onItem : onItem,
  439. onError : dojo.partial(
  440. dojox.data.tests.stores.CsvStore.error, t,
  441. d)
  442. });
  443. return d;
  444. }, function testReadAPI_getValue_2(t) {
  445. // summary:
  446. // Simple test of the getValue function of the store.
  447. // description:
  448. // Simple test of the getValue function of the store.
  449. var args = dojox.data.tests.stores.CsvStore
  450. .getDatasource("stores/movies.csv");
  451. var csvStore = new dojox.data.CsvStore(args);
  452. var d = new doh.Deferred();
  453. function onItem(item) {
  454. t.assertTrue(item !== null);
  455. t.is("City of God", csvStore.getValue(item, "Title"));
  456. t.is("2002", csvStore.getValue(item, "Year"));
  457. d.callback(true);
  458. }
  459. csvStore.fetchItemByIdentity({
  460. identity : "0",
  461. onItem : onItem,
  462. onError : dojo.partial(
  463. dojox.data.tests.stores.CsvStore.error, t,
  464. d)
  465. });
  466. return d;
  467. }, function testReadAPI_getValue_3(t) {
  468. // summary:
  469. // Simple test of the getValue function of the store.
  470. // description:
  471. // Simple test of the getValue function of the store.
  472. var args = dojox.data.tests.stores.CsvStore
  473. .getDatasource("stores/movies.csv");
  474. var csvStore = new dojox.data.CsvStore(args);
  475. var d = new doh.Deferred();
  476. function onItem(item) {
  477. t.assertTrue(item !== null);
  478. t.is("1979", csvStore.getValue(item, "Year"));
  479. t.is("Alien", csvStore.getValue(item, "Title"));
  480. d.callback(true);
  481. }
  482. csvStore.fetchItemByIdentity({
  483. identity : "4",
  484. onItem : onItem,
  485. onError : dojo.partial(
  486. dojox.data.tests.stores.CsvStore.error, t,
  487. d)
  488. });
  489. return d;
  490. }, function testReadAPI_getValue_4(t) {
  491. // summary:
  492. // Simple test of the getValue function of the store.
  493. // description:
  494. // Simple test of the getValue function of the store.
  495. var args = dojox.data.tests.stores.CsvStore
  496. .getDatasource("stores/movies.csv");
  497. var csvStore = new dojox.data.CsvStore(args);
  498. var d = new doh.Deferred();
  499. function onItem(item) {
  500. t.assertTrue(item !== null);
  501. t.is("2001: A Space Odyssey", csvStore.getValue(item,
  502. "Title"));
  503. t
  504. .is("Stanley Kubrick", csvStore.getValue(item,
  505. "Producer"));
  506. d.callback(true);
  507. }
  508. csvStore.fetchItemByIdentity({
  509. identity : "2",
  510. onItem : onItem,
  511. onError : dojo.partial(
  512. dojox.data.tests.stores.CsvStore.error, t,
  513. d)
  514. });
  515. return d;
  516. },
  517. function testReadAPI_getValues(t) {
  518. // summary:
  519. // Simple test of the getValues function of the store.
  520. // description:
  521. // Simple test of the getValues function of the store.
  522. var args = dojox.data.tests.stores.CsvStore
  523. .getDatasource("stores/movies.csv");
  524. var csvStore = new dojox.data.CsvStore(args);
  525. var d = new doh.Deferred();
  526. function onItem(item) {
  527. t.assertTrue(item !== null);
  528. var names = csvStore.getValues(item, "Title");
  529. t.assertTrue(dojo.isArray(names));
  530. t.is(1, names.length);
  531. t.is("Rain", names[0]);
  532. d.callback(true);
  533. }
  534. csvStore.fetchItemByIdentity({
  535. identity : "1",
  536. onItem : onItem,
  537. onError : dojo.partial(
  538. dojox.data.tests.stores.CsvStore.error, t,
  539. d)
  540. });
  541. return d;
  542. }, function testIdentityAPI_fetchItemByIdentity(t) {
  543. // summary:
  544. // Simple test of the fetchItemByIdentity function of the store.
  545. // description:
  546. // Simple test of the fetchItemByIdentity function of the store.
  547. var args = dojox.data.tests.stores.CsvStore
  548. .getDatasource("stores/movies.csv");
  549. var csvStore = new dojox.data.CsvStore(args);
  550. var d = new doh.Deferred();
  551. function onItem(item) {
  552. t.assertTrue(item !== null);
  553. d.callback(true);
  554. }
  555. csvStore.fetchItemByIdentity({
  556. identity : "1",
  557. onItem : onItem,
  558. onError : dojo.partial(
  559. dojox.data.tests.stores.CsvStore.error, t,
  560. d)
  561. });
  562. return d;
  563. },
  564. function testIdentityAPI_fetchItemByIdentity_bad1(t) {
  565. // summary:
  566. // Simple test of the fetchItemByIdentity function of the store.
  567. // description:
  568. // Simple test of the fetchItemByIdentity function of the store.
  569. var args = dojox.data.tests.stores.CsvStore
  570. .getDatasource("stores/movies.csv");
  571. var csvStore = new dojox.data.CsvStore(args);
  572. var d = new doh.Deferred();
  573. function onItem(item) {
  574. t.assertTrue(item === null);
  575. d.callback(true);
  576. }
  577. csvStore.fetchItemByIdentity({
  578. identity : "7",
  579. onItem : onItem,
  580. onError : dojo.partial(
  581. dojox.data.tests.stores.CsvStore.error, t,
  582. d)
  583. });
  584. return d;
  585. }, function testIdentityAPI_fetchItemByIdentity_bad2(t) {
  586. // summary:
  587. // Simple test of the fetchItemByIdentity function of the store.
  588. // description:
  589. // Simple test of the fetchItemByIdentity function of the store.
  590. var args = dojox.data.tests.stores.CsvStore
  591. .getDatasource("stores/movies.csv");
  592. var csvStore = new dojox.data.CsvStore(args);
  593. var d = new doh.Deferred();
  594. function onItem(item) {
  595. t.assertTrue(item === null);
  596. d.callback(true);
  597. }
  598. csvStore.fetchItemByIdentity({
  599. identity : "-1",
  600. onItem : onItem,
  601. onError : dojo.partial(
  602. dojox.data.tests.stores.CsvStore.error, t,
  603. d)
  604. });
  605. return d;
  606. }, function testIdentityAPI_fetchItemByIdentity_bad3(t) {
  607. // summary:
  608. // Simple test of the fetchItemByIdentity function of the store.
  609. // description:
  610. // Simple test of the fetchItemByIdentity function of the store.
  611. var args = dojox.data.tests.stores.CsvStore
  612. .getDatasource("stores/movies.csv");
  613. var csvStore = new dojox.data.CsvStore(args);
  614. var d = new doh.Deferred();
  615. function onItem(item) {
  616. t.assertTrue(item === null);
  617. d.callback(true);
  618. }
  619. csvStore.fetchItemByIdentity({
  620. identity : "999999",
  621. onItem : onItem,
  622. onError : dojo.partial(
  623. dojox.data.tests.stores.CsvStore.error, t,
  624. d)
  625. });
  626. return d;
  627. }, function testIdentityAPI_getIdentity(t) {
  628. // summary:
  629. // Simple test of the fetchItemByIdentity function of the store.
  630. // description:
  631. // Simple test of the fetchItemByIdentity function of the store.
  632. var args = dojox.data.tests.stores.CsvStore
  633. .getDatasource("stores/movies.csv");
  634. var csvStore = new dojox.data.CsvStore(args);
  635. var d = new doh.Deferred();
  636. function completed(items, request) {
  637. t.is(7, items.length);
  638. var passed = true;
  639. for (var i = 0; i < items.length; i++) {
  640. if (!(csvStore.getIdentity(items[i]) === i)) {
  641. passed = false;
  642. break;
  643. }
  644. }
  645. t.assertTrue(passed);
  646. d.callback(true);
  647. }
  648. // Get everything...
  649. csvStore.fetch({
  650. onComplete : completed,
  651. onError : dojo.partial(
  652. dojox.data.tests.stores.CsvStore.error, t,
  653. d)
  654. });
  655. return d; // Object
  656. }, function testIdentityAPI_getIdentityAttributes(t) {
  657. // summary:
  658. // Simple test of the getIdentityAttributes
  659. // description:
  660. // Simple test of the fetchItemByIdentity function of the store.
  661. var args = dojox.data.tests.stores.CsvStore
  662. .getDatasource("stores/movies.csv");
  663. var csvStore = new dojox.data.CsvStore(args);
  664. var d = new doh.Deferred();
  665. function onItem(item) {
  666. t.assertTrue(csvStore.isItem(item));
  667. t.assertEqual(null, csvStore.getIdentityAttributes(item));
  668. d.callback(true);
  669. }
  670. csvStore.fetchItemByIdentity({
  671. identity : "1",
  672. onItem : onItem,
  673. onError : dojo.partial(
  674. dojox.data.tests.stores.CsvStore.error, t,
  675. d)
  676. });
  677. return d;
  678. }, function testReadAPI_isItem(t) {
  679. // summary:
  680. // Simple test of the isItem function of the store
  681. // description:
  682. // Simple test of the isItem function of the store
  683. var args = dojox.data.tests.stores.CsvStore
  684. .getDatasource("stores/movies.csv");
  685. var csvStore = new dojox.data.CsvStore(args);
  686. var d = new doh.Deferred();
  687. function onItem(item) {
  688. t.assertTrue(csvStore.isItem(item));
  689. t.assertTrue(!csvStore.isItem({}));
  690. t.assertTrue(!csvStore.isItem({
  691. item : "not an item"
  692. }));
  693. t.assertTrue(!csvStore.isItem("not an item"));
  694. t.assertTrue(!csvStore.isItem(["not an item"]));
  695. d.callback(true);
  696. }
  697. csvStore.fetchItemByIdentity({
  698. identity : "1",
  699. onItem : onItem,
  700. onError : dojo.partial(
  701. dojox.data.tests.stores.CsvStore.error, t,
  702. d)
  703. });
  704. return d;
  705. }, function testReadAPI_hasAttribute(t) {
  706. // summary:
  707. // Simple test of the hasAttribute function of the store
  708. // description:
  709. // Simple test of the hasAttribute function of the store
  710. var args = dojox.data.tests.stores.CsvStore
  711. .getDatasource("stores/movies.csv");
  712. var csvStore = new dojox.data.CsvStore(args);
  713. var d = new doh.Deferred();
  714. function onItem(item) {
  715. t.assertTrue(item !== null);
  716. t.assertTrue(csvStore.hasAttribute(item, "Title"));
  717. t.assertTrue(csvStore.hasAttribute(item, "Producer"));
  718. t.assertTrue(!csvStore.hasAttribute(item, "Year"));
  719. t.assertTrue(!csvStore.hasAttribute(item, "Nothing"));
  720. t.assertTrue(!csvStore.hasAttribute(item, "title"));
  721. // Test that null attributes throw an exception
  722. var passed = false;
  723. try {
  724. csvStore.hasAttribute(item, null);
  725. } catch (e) {
  726. passed = true;
  727. }
  728. t.assertTrue(passed);
  729. d.callback(true);
  730. }
  731. csvStore.fetchItemByIdentity({
  732. identity : "1",
  733. onItem : onItem,
  734. onError : dojo.partial(
  735. dojox.data.tests.stores.CsvStore.error, t,
  736. d)
  737. });
  738. return d;
  739. }, function testReadAPI_containsValue(t) {
  740. // summary:
  741. // Simple test of the containsValue function of the store
  742. // description:
  743. // Simple test of the containsValue function of the store
  744. var args = dojox.data.tests.stores.CsvStore
  745. .getDatasource("stores/movies.csv");
  746. var csvStore = new dojox.data.CsvStore(args);
  747. var d = new doh.Deferred();
  748. function onItem(item) {
  749. t.assertTrue(item !== null);
  750. t
  751. .assertTrue(csvStore.containsValue(item, "Title",
  752. "Alien"));
  753. t.assertTrue(csvStore.containsValue(item, "Year", "1979"));
  754. t.assertTrue(csvStore.containsValue(item, "Producer",
  755. "Ridley Scott"));
  756. t.assertTrue(!csvStore.containsValue(item, "Title",
  757. "Alien2"));
  758. t.assertTrue(!csvStore.containsValue(item, "Year",
  759. "1979 "));
  760. t.assertTrue(!csvStore.containsValue(item, "Title", null));
  761. // Test that null attributes throw an exception
  762. var passed = false;
  763. try {
  764. csvStore.containsValue(item, null, "foo");
  765. } catch (e) {
  766. passed = true;
  767. }
  768. t.assertTrue(passed);
  769. d.callback(true);
  770. }
  771. csvStore.fetchItemByIdentity({
  772. identity : "4",
  773. onItem : onItem,
  774. onError : dojo.partial(
  775. dojox.data.tests.stores.CsvStore.error, t,
  776. d)
  777. });
  778. return d;
  779. }, function testReadAPI_getAttributes(t) {
  780. // summary:
  781. // Simple test of the getAttributes function of the store
  782. // description:
  783. // Simple test of the getAttributes function of the store
  784. var args = dojox.data.tests.stores.CsvStore
  785. .getDatasource("stores/movies.csv");
  786. var csvStore = new dojox.data.CsvStore(args);
  787. var d = new doh.Deferred();
  788. function onItem(item) {
  789. t.assertTrue(item !== null);
  790. t.assertTrue(csvStore.isItem(item));
  791. var attributes = csvStore.getAttributes(item);
  792. t.is(3, attributes.length);
  793. for (var i = 0; i < attributes.length; i++) {
  794. t
  795. .assertTrue((attributes[i] === "Title"
  796. || attributes[i] === "Year" || attributes[i] === "Producer"));
  797. }
  798. d.callback(true);
  799. }
  800. csvStore.fetchItemByIdentity({
  801. identity : "4",
  802. onItem : onItem,
  803. onError : dojo.partial(
  804. dojox.data.tests.stores.CsvStore.error, t,
  805. d)
  806. });
  807. return d;
  808. },
  809. function testReadAPI_getAttributes_onlyTwo(t) {
  810. // summary:
  811. // Simple test of the getAttributes function of the store
  812. // description:
  813. // Simple test of the getAttributes function of the store
  814. var args = dojox.data.tests.stores.CsvStore
  815. .getDatasource("stores/movies.csv");
  816. var csvStore = new dojox.data.CsvStore(args);
  817. var d = new doh.Deferred();
  818. function onItem(item) {
  819. // Test an item that does not have all of the attributes
  820. t.assertTrue(item !== null);
  821. t.assertTrue(csvStore.isItem(item));
  822. var attributes = csvStore.getAttributes(item);
  823. t.assertTrue(attributes.length === 2);
  824. t.assertTrue(attributes[0] === "Title");
  825. t.assertTrue(attributes[1] === "Producer");
  826. d.callback(true);
  827. }
  828. csvStore.fetchItemByIdentity({
  829. identity : "1",
  830. onItem : onItem,
  831. onError : dojo.partial(
  832. dojox.data.tests.stores.CsvStore.error, t,
  833. d)
  834. });
  835. return d;
  836. },
  837. function testReadAPI_getFeatures(t) {
  838. // summary:
  839. // Simple test of the getFeatures function of the store
  840. // description:
  841. // Simple test of the getFeatures function of the store
  842. var args = dojox.data.tests.stores.CsvStore
  843. .getDatasource("stores/movies.csv");
  844. var csvStore = new dojox.data.CsvStore(args);
  845. var features = csvStore.getFeatures();
  846. var count = 0;
  847. for (i in features) {
  848. t
  849. .assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
  850. count++;
  851. }
  852. t.assertTrue(count === 2);
  853. }, function testReadAPI_fetch_patternMatch0(t) {
  854. // summary:
  855. // Function to test pattern matching of everything starting with
  856. // lowercase e
  857. // description:
  858. // Function to test pattern matching of everything starting with
  859. // lowercase e
  860. var args = dojox.data.tests.stores.CsvStore
  861. .getDatasource("stores/movies.csv");
  862. var csvStore = new dojox.data.CsvStore(args);
  863. var d = new doh.Deferred();
  864. function completed(items, request) {
  865. t.is(2, items.length);
  866. var valueArray = ["Alien",
  867. "The Sequel to \"Dances With Wolves.\""];
  868. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  869. csvStore, items, "Title", valueArray));
  870. d.callback(true);
  871. }
  872. csvStore.fetch({
  873. query : {
  874. Producer : "* Scott"
  875. },
  876. onComplete : completed,
  877. onError : dojo.partial(
  878. dojox.data.tests.stores.CsvStore.error, t,
  879. d)
  880. });
  881. return d; // Object
  882. }, function testReadAPI_fetch_patternMatch1(t) {
  883. // summary:
  884. // Function to test pattern matching of everything with $ in it.
  885. // description:
  886. // Function to test pattern matching of everything with $ in it.
  887. var args = dojox.data.tests.stores.CsvStore
  888. .getDatasource("stores/patterns.csv");
  889. var csvStore = new dojox.data.CsvStore(args);
  890. var d = new doh.Deferred();
  891. function completed(items, request) {
  892. t.assertTrue(items.length === 2);
  893. var valueArray = ["jfq4@#!$!@Rf14r14i5u", "bit$Bite"];
  894. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  895. csvStore, items, "value", valueArray));
  896. d.callback(true);
  897. }
  898. csvStore.fetch({
  899. query : {
  900. value : "*$*"
  901. },
  902. onComplete : completed,
  903. onError : dojo.partial(
  904. dojox.data.tests.stores.CsvStore.error, t,
  905. d)
  906. });
  907. return d; // Object
  908. }, function testReadAPI_fetch_patternMatch2(t) {
  909. // summary:
  910. // Function to test exact pattern match
  911. // description:
  912. // Function to test exact pattern match
  913. var args = dojox.data.tests.stores.CsvStore
  914. .getDatasource("stores/patterns.csv");
  915. var csvStore = new dojox.data.CsvStore(args);
  916. var d = new doh.Deferred();
  917. function completed(items, request) {
  918. t.is(1, items.length);
  919. t
  920. .assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
  921. d.callback(true);
  922. }
  923. csvStore.fetch({
  924. query : {
  925. value : "bar\*foo"
  926. },
  927. onComplete : completed,
  928. onError : dojo.partial(
  929. dojox.data.tests.stores.CsvStore.error, t,
  930. d)
  931. });
  932. return d; // Object
  933. }, function testReadAPI_fetch_patternMatch_caseInsensitive(t) {
  934. // summary:
  935. // Function to test exact pattern match with case insensitivity
  936. // set.
  937. // description:
  938. // Function to test exact pattern match with case insensitivity
  939. // set.
  940. var args = dojox.data.tests.stores.CsvStore
  941. .getDatasource("stores/patterns.csv");
  942. var csvStore = new dojox.data.CsvStore(args);
  943. var d = new doh.Deferred();
  944. function completed(items, request) {
  945. t.is(1, items.length);
  946. t
  947. .assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
  948. d.callback(true);
  949. }
  950. csvStore.fetch({
  951. query : {
  952. value : "BAR\\*foo"
  953. },
  954. queryOptions : {
  955. ignoreCase : true
  956. },
  957. onComplete : completed,
  958. onError : dojo.partial(
  959. dojox.data.tests.stores.CsvStore.error, t,
  960. d)
  961. });
  962. return d; // Object
  963. }, function testReadAPI_fetch_patternMatch_caseSensitive(t) {
  964. // summary:
  965. // Function to test exact pattern match with case insensitivity
  966. // set.
  967. // description:
  968. // Function to test exact pattern match with case insensitivity
  969. // set.
  970. var args = dojox.data.tests.stores.CsvStore
  971. .getDatasource("stores/patterns.csv");
  972. var csvStore = new dojox.data.CsvStore(args);
  973. var d = new doh.Deferred();
  974. function completed(items, request) {
  975. t.is(0, items.length);
  976. d.callback(true);
  977. }
  978. csvStore.fetch({
  979. query : {
  980. value : "BAR\\*foo"
  981. },
  982. queryOptions : {
  983. ignoreCase : false
  984. },
  985. onComplete : completed,
  986. onError : dojo.partial(
  987. dojox.data.tests.stores.CsvStore.error, t,
  988. d)
  989. });
  990. return d; // Object
  991. }, function testReadAPI_fetch_sortNumeric(t) {
  992. // summary:
  993. // Function to test sorting numerically.
  994. // description:
  995. // Function to test sorting numerically.
  996. var args = dojox.data.tests.stores.CsvStore
  997. .getDatasource("stores/patterns.csv");
  998. var csvStore = new dojox.data.CsvStore(args);
  999. var d = new doh.Deferred();
  1000. function completed(items, request) {
  1001. t.assertTrue(items.length === 10);
  1002. // TODO: CsvStore treats everything like a string, so these
  1003. // numbers will be sorted lexicographically.
  1004. var orderedArray = ["1", "10", "2", "3", "4", "5", "6",
  1005. "7", "8", "9"];
  1006. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1007. csvStore, items, "uniqueId", orderedArray));
  1008. d.callback(true);
  1009. }
  1010. var sortAttributes = [{
  1011. attribute : "uniqueId"
  1012. }];
  1013. csvStore.fetch({
  1014. onComplete : completed,
  1015. onError : dojo.partial(
  1016. dojox.data.tests.stores.CsvStore.error, t,
  1017. d),
  1018. sort : sortAttributes
  1019. });
  1020. return d; // Object
  1021. }, function testReadAPI_fetch_sortNumericDescending(t) {
  1022. // summary:
  1023. // Function to test sorting numerically.
  1024. // description:
  1025. // Function to test sorting numerically.
  1026. var args = dojox.data.tests.stores.CsvStore
  1027. .getDatasource("stores/patterns.csv");
  1028. var csvStore = new dojox.data.CsvStore(args);
  1029. var d = new doh.Deferred();
  1030. function completed(items, request) {
  1031. t.is(10, items.length);
  1032. // TODO: CsvStore treats everything like a string, so these
  1033. // numbers will be sorted lexicographically.
  1034. var orderedArray = ["9", "8", "7", "6", "5", "4", "3", "2",
  1035. "10", "1"];
  1036. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1037. csvStore, items, "uniqueId", orderedArray));
  1038. d.callback(true);
  1039. }
  1040. var sortAttributes = [{
  1041. attribute : "uniqueId",
  1042. descending : true
  1043. }];
  1044. csvStore.fetch({
  1045. sort : sortAttributes,
  1046. onComplete : completed,
  1047. onError : dojo.partial(
  1048. dojox.data.tests.stores.CsvStore.error, t,
  1049. d)
  1050. });
  1051. return d; // Object
  1052. }, function testReadAPI_fetch_sortNumericWithCount(t) {
  1053. // summary:
  1054. // Function to test sorting numerically in descending order,
  1055. // returning only a specified number of them.
  1056. // description:
  1057. // Function to test sorting numerically in descending order,
  1058. // returning only a specified number of them.
  1059. var args = dojox.data.tests.stores.CsvStore
  1060. .getDatasource("stores/patterns.csv");
  1061. var csvStore = new dojox.data.CsvStore(args);
  1062. var d = new doh.Deferred();
  1063. function completed(items, request) {
  1064. t.is(5, items.length);
  1065. // TODO: CsvStore treats everything like a string, so these
  1066. // numbers will be sorted lexicographically.
  1067. var orderedArray = ["9", "8", "7", "6", "5"];
  1068. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1069. csvStore, items, "uniqueId", orderedArray));
  1070. d.callback(true);
  1071. }
  1072. var sortAttributes = [{
  1073. attribute : "uniqueId",
  1074. descending : true
  1075. }];
  1076. csvStore.fetch({
  1077. sort : sortAttributes,
  1078. count : 5,
  1079. onComplete : completed,
  1080. onError : dojo.partial(
  1081. dojox.data.tests.stores.CsvStore.error, t,
  1082. d)
  1083. });
  1084. return d; // Object
  1085. }, function testReadAPI_fetch_sortAlphabetic(t) {
  1086. // summary:
  1087. // Function to test sorting alphabetic ordering.
  1088. // description:
  1089. // Function to test sorting alphabetic ordering.
  1090. var args = dojox.data.tests.stores.CsvStore
  1091. .getDatasource("stores/patterns.csv");
  1092. var csvStore = new dojox.data.CsvStore(args);
  1093. var d = new doh.Deferred();
  1094. function completed(items, request) {
  1095. // Output should be in this order...
  1096. var orderedArray = ["123abc", "123abc", "123abc",
  1097. "123abcdefg", "BaBaMaSaRa***Foo", "bar*foo",
  1098. "bit$Bite", "foo*bar", "jfq4@#!$!@Rf14r14i5u",
  1099. undefined];
  1100. t.is(10, items.length);
  1101. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1102. csvStore, items, "value", orderedArray));
  1103. d.callback(true);
  1104. }
  1105. var sortAttributes = [{
  1106. attribute : "value"
  1107. }];
  1108. csvStore.fetch({
  1109. sort : sortAttributes,
  1110. onComplete : completed,
  1111. onError : dojo.partial(
  1112. dojox.data.tests.stores.CsvStore.error, t,
  1113. d)
  1114. });
  1115. return d; // Object
  1116. }, function testReadAPI_fetch_sortAlphabeticDescending(t) {
  1117. // summary:
  1118. // Function to test sorting alphabetic ordering in descending
  1119. // mode.
  1120. // description:
  1121. // Function to test sorting alphabetic ordering in descending
  1122. // mode.
  1123. var args = dojox.data.tests.stores.CsvStore
  1124. .getDatasource("stores/patterns.csv");
  1125. var csvStore = new dojox.data.CsvStore(args);
  1126. var d = new doh.Deferred();
  1127. function completed(items, request) {
  1128. // Output should be in this order...
  1129. var orderedArray = [undefined, "jfq4@#!$!@Rf14r14i5u",
  1130. "foo*bar", "bit$Bite", "bar*foo",
  1131. "BaBaMaSaRa***Foo", "123abcdefg", "123abc",
  1132. "123abc", "123abc"];
  1133. t.is(10, items.length);
  1134. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1135. csvStore, items, "value", orderedArray));
  1136. d.callback(true);
  1137. }
  1138. var sortAttributes = [{
  1139. attribute : "value",
  1140. descending : true
  1141. }];
  1142. csvStore.fetch({
  1143. sort : sortAttributes,
  1144. onComplete : completed,
  1145. onError : dojo.partial(
  1146. dojox.data.tests.stores.CsvStore.error, t,
  1147. d)
  1148. });
  1149. return d; // Object
  1150. }, function testReadAPI_fetch_sortMultiple(t) {
  1151. // summary:
  1152. // Function to test sorting on multiple attributes.
  1153. // description:
  1154. // Function to test sorting on multiple attributes.
  1155. var args = dojox.data.tests.stores.CsvStore
  1156. .getDatasource("stores/patterns.csv");
  1157. var csvStore = new dojox.data.CsvStore(args);
  1158. var d = new doh.Deferred();
  1159. function completed(items, request) {
  1160. var orderedArray0 = ["8", "5", "3", "10", "6", "2", "4",
  1161. "1", "9", "7"];
  1162. var orderedArray1 = ["123abc", "123abc", "123abc",
  1163. "123abcdefg", "BaBaMaSaRa***Foo", "bar*foo",
  1164. "bit$Bite", "foo*bar", "jfq4@#!$!@Rf14r14i5u",
  1165. undefined];
  1166. t.is(10, items.length);
  1167. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1168. csvStore, items, "uniqueId", orderedArray0));
  1169. t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(
  1170. csvStore, items, "value", orderedArray1));
  1171. d.callback(true);
  1172. }
  1173. var sortAttributes = [{
  1174. attribute : "value"
  1175. }, {
  1176. attribute : "uniqueId",
  1177. descending : true
  1178. }];
  1179. csvStore.fetch({
  1180. sort : sortAttributes,
  1181. onComplete : completed,
  1182. onError : dojo.partial(
  1183. dojox.data.tests.stores.CsvStore.error, t,
  1184. d)
  1185. });
  1186. return d; // Object
  1187. }, function testReadAPI_fetch_sortMultipleSpecialComparator(t) {
  1188. // summary:
  1189. // Function to test sorting on multiple attributes with a custom
  1190. // comparator.
  1191. // description:
  1192. // Function to test sorting on multiple attributes with a custom
  1193. // comparator.
  1194. var args = dojox.data.tests.stores.CsvStore
  1195. .getDatasource("stores/movies.csv");
  1196. var csvStore = new dojox.data.CsvStore(args);
  1197. csvStore.comparatorMap = {};
  1198. csvStore.comparatorMap["Producer"] = function(a, b) {
  1199. var ret = 0;
  1200. // We want to sort authors alphabetical by their last name
  1201. function lastName(name) {
  1202. if (typeof name === "undefined") {
  1203. return undefined;
  1204. }
  1205. var matches = name.match(/\s*(\S+)$/); // Grab the last
  1206. // word in the
  1207. // string.
  1208. return matches ? matches[1] : name; // Strings with only
  1209. // whitespace will
  1210. // not match.
  1211. }
  1212. var lastNameA = lastName(a);
  1213. var lastNameB = lastName(b);
  1214. if (lastNameA > lastNameB
  1215. || typeof lastNameA === "undefined") {
  1216. ret = 1;
  1217. } else if (lastNameA < lastNameB
  1218. || typeof lastNameB === "undefined") {
  1219. ret = -1;
  1220. }
  1221. return ret;
  1222. };
  1223. var sortAttributes = [{
  1224. attribute : "Producer",
  1225. descending : true
  1226. }, {
  1227. attribute : "Title",
  1228. descending : true
  1229. }];
  1230. var d = new doh.Deferred();
  1231. function completed(items, findResult) {
  1232. var orderedArray = [5, 4, 0, 3, 2, 1, 6];
  1233. t.assertTrue(items.length === 7);
  1234. var passed = true;
  1235. for (var i = 0; i < items.length; i++) {
  1236. if (!(csvStore.getIdentity(items[i]) === orderedArray[i])) {
  1237. passed = false;
  1238. break;
  1239. }
  1240. }
  1241. t.assertTrue(passed);
  1242. d.callback(true);
  1243. }
  1244. csvStore.fetch({
  1245. sort : sortAttributes,
  1246. onComplete : completed,
  1247. onError : dojo.partial(
  1248. dojox.data.tests.stores.CsvStore.error, t,
  1249. d)
  1250. });
  1251. return d; // Object
  1252. }, function testReadAPI_functionConformance(t) {
  1253. // summary:
  1254. // Simple test read API conformance. Checks to see all declared
  1255. // functions are actual functions on the instances.
  1256. // description:
  1257. // Simple test read API conformance. Checks to see all declared
  1258. // functions are actual functions on the instances.
  1259. var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore
  1260. .getDatasource("stores/movies.csv"));
  1261. var readApi = new dojo.data.api.Read();
  1262. var passed = true;
  1263. for (i in readApi) {
  1264. if (i.toString().charAt(0) !== '_') {
  1265. var member = readApi[i];
  1266. // Check that all the 'Read' defined functions exist on
  1267. // the test store.
  1268. if (typeof member === "function") {
  1269. console.log("Looking at function: [" + i + "]");
  1270. var testStoreMember = testStore[i];
  1271. if (!(typeof testStoreMember === "function")) {
  1272. console.log("Problem with function: [" + i
  1273. + "]. Got value: " + testStoreMember);
  1274. passed = false;
  1275. break;
  1276. }
  1277. }
  1278. }
  1279. }
  1280. t.assertTrue(passed);
  1281. }, function testIdentityAPI_functionConformance(t) {
  1282. // summary:
  1283. // Simple test identity API conformance. Checks to see all
  1284. // declared functions are actual functions on the instances.
  1285. // description:
  1286. // Simple test identity API conformance. Checks to see all
  1287. // declared functions are actual functions on the instances.
  1288. var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore
  1289. .getDatasource("stores/movies.csv"));
  1290. var identityApi = new dojo.data.api.Identity();
  1291. var passed = true;
  1292. for (i in identityApi) {
  1293. if (i.toString().charAt(0) !== '_') {
  1294. var member = identityApi[i];
  1295. // Check that all the 'Read' defined functions exist on
  1296. // the test store.
  1297. if (typeof member === "function") {
  1298. console.log("Looking at function: [" + i + "]");
  1299. var testStoreMember = testStore[i];
  1300. if (!(typeof testStoreMember === "function")) {
  1301. passed = false;
  1302. break;
  1303. }
  1304. }
  1305. }
  1306. }
  1307. t.assertTrue(passed);
  1308. }]);
  1309. }