📄 atomreadstore.js
字号:
if(!dojo._hasResource["dojox.data.tests.stores.AtomReadStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.data.tests.stores.AtomReadStore"] = true;dojo.provide("dojox.data.tests.stores.AtomReadStore");dojo.require("dojox.data.AtomReadStore");dojo.require("dojo.data.api.Read");dojox.data.tests.stores.AtomReadStore.getBlog1Store = function(){ return new dojox.data.AtomReadStore({url: dojo.moduleUrl("dojox.data.tests", "stores/atom1.xml").toString()}); //return new dojox.data.AtomReadStore({url: "/sos/feeds/blog.php"});};/*dojox.data.tests.stores.AtomReadStore.getBlog2Store = function(){ return new dojox.data.AtomReadStore({url: dojo.moduleUrl("dojox.data.tests", "stores/atom2.xml").toString()});};*/dojox.data.tests.stores.AtomReadStore.error = function(t, d, errData){ // summary: // The error callback function to be used for all of the tests. //console.log("In here."); //console.trace(); d.errback(errData);}doh.register("dojox.data.tests.stores.AtomReadStore", [ { name: "ReadAPI: Fetch_One", timeout: 5000, //1 second runTest: function(t) { // summary: // Simple test of a basic fetch on AtomReadStore of a single item. // description: // Simple test of a basic fetch on AtomReadStore of a single item. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); function onComplete(items, request){ t.is(1, items.length); d.callback(true); } atomStore.fetch({ query: { }, count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, doh, d) }); return d; //Object } }, { name: "ReadAPI: Fetch_5_Streaming", timeout: 5000, //1 second. runTest: function(t) { // summary: // Simple test of a basic fetch on AtomReadStore. // description: // Simple test of a basic fetch on AtomReadStore. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); var count = 0; function onItem(item, requestObj){ t.assertTrue(atomStore.isItem(item)); count++; } function onComplete(items, request){ t.is(5, count); t.is(null, items); d.callback(true); } //Get everything... atomStore.fetch({ query: { }, onBegin: null, count: 5, onItem: onItem, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d) }); return d; //Object } }, { name: "ReadAPI: Fetch_Paging", timeout: 5000, //1 second. runTest: function(t) { // summary: // Test of multiple fetches on a single result. Paging, if you will. // description: // Test of multiple fetches on a single result. Paging, if you will. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); function dumpFirstFetch(items, request){ t.is(5, items.length); request.start = 3; request.count = 1; request.onComplete = dumpSecondFetch; atomStore.fetch(request); } function dumpSecondFetch(items, request){ console.log("dumpSecondFetch: got "+items.length); t.is(1, items.length); request.start = 0; request.count = 5; request.onComplete = dumpThirdFetch; atomStore.fetch(request); } function dumpThirdFetch(items, request){ console.log("dumpThirdFetch: got "+items.length); t.is(5, items.length); request.start = 2; request.count = 18; request.onComplete = dumpFourthFetch; atomStore.fetch(request); } function dumpFourthFetch(items, request){ console.log("dumpFourthFetch: got "+items.length); t.is(18, items.length); request.start = 5; request.count = 11; request.onComplete = dumpFifthFetch; atomStore.fetch(request); } function dumpFifthFetch(items, request){ console.log("dumpFifthFetch: got "+items.length); t.is(11, items.length); request.start = 4; request.count = 16; request.onComplete = dumpSixthFetch; atomStore.fetch(request); } function dumpSixthFetch(items, request){ console.log("dumpSixthFetch: got "+items.length); t.is(16, items.length); d.callback(true); } function completed(items, request){ t.is(7, items.length); request.start = 1; request.count = 5; request.onComplete = dumpFirstFetch; atomStore.fetch(request); } atomStore.fetch({ query: { }, count: 7, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d) }); return d; //Object } }, { name: "ReadAPI: getLabel", timeout: 5000, //1 second. runTest: function(t) { // summary: // Simple test of the getLabel function against a store set that has a label defined. // description: // Simple test of the getLabel function against a store set that has a label defined. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); function onComplete(items, request){ t.assertEqual(items.length, 1); var label = atomStore.getLabel(items[0]); t.assertTrue(label !== null); d.callback(true); } atomStore.fetch({ query: { }, count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d) }); return d; } }, { name: "ReadAPI: getLabelAttributes", timeout: 5000, //1 second runTest: function(t) { // summary: // Simple test of the getLabelAttributes function against a store set that has a label defined. // description: // Simple test of the getLabelAttributes function against a store set that has a label defined. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); function onComplete(items, request){ t.assertEqual(items.length, 1); var labelList = atomStore.getLabelAttributes(items[0]); t.assertTrue(dojo.isArray(labelList)); t.assertEqual("title", labelList[0]); d.callback(true); } atomStore.fetch({ query: { }, count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d) }); return d; } }, { name: "ReadAPI: getValue", timeout: 5000, //1 second runTest: function(t) { // summary: // Simple test of the getValue function of the store. // description: // Simple test of the getValue function of the store. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); function completedAll(items){ t.is(1, items.length); t.assertTrue(atomStore.getValue(items[0], "summary") !== null); t.assertTrue(atomStore.getValue(items[0], "content") !== null); t.assertTrue(atomStore.getValue(items[0], "published") !== null); t.assertTrue(atomStore.getValue(items[0], "updated") !== null); console.log("typeof updated = "+typeof(atomStore.getValue(items[0], "updated"))); t.assertTrue(atomStore.getValue(items[0], "updated").getFullYear); d.callback(true); } //Get one item and look at it. atomStore.fetch({ query: { }, count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)}); return d; //Object } }, { name: "ReadAPI: getValue_Failure", timeout: 5000, //1 second runTest: function(t) { // summary: // Simple test of the getValue function of the store. // description: // Simple test of the getValue function of the store. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var passed = false; try{ var value = store.getValue("NotAnItem", foo); }catch(e){ passed = true; } t.assertTrue(passed); } }, { name: "ReadAPI: getValues", timeout: 5000, //1 second runTest: function(t) { // summary: // Simple test of the getValue function of the store. // description: // Simple test of the getValue function of the store. var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store(); var d = new doh.Deferred(); function completedAll(items){ t.is(1, items.length); var summary = atomStore.getValues(items[0], "summary"); t.assertTrue(dojo.isArray(summary)); var content = atomStore.getValues(items[0], "content"); t.assertTrue(dojo.isArray(content)); var published = atomStore.getValues(items[0], "published"); t.assertTrue(dojo.isArray(published)); var updated = atomStore.getValues(items[0], "updated"); t.assertTrue(dojo.isArray(updated)); d.callback(true); } //Get one item and look at it. atomStore.fetch({ query: { }, count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d) }); return d; //Object } }, { name: "ReadAPI: getValues_Failure", timeout: 5000, //1 second runTest: function(t) { // summary: // Simple test of the getValue function of the store. // description: // Simple test of the getValue function of the store.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -