Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2149 → Rev 2150

/trunk/api/js/dojo1.0/dojox/data/tests/ml/test_HtmlTableStore_declaratively.html
New file
0,0 → 1,120
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dojox HtmlDataStore Widget</title>
<style>
@import "../../../../dijit/themes/tundra/tundra.css";
@import "../../../../dojo/resources/dojo.css";
@import "../../../../dijit/tests/css/dijitTests.css";
</style>
<script type="text/javascript">
djConfig = {
isDebug: true,
parseOnLoad: true
};
</script>
<script type="text/javascript" src="../../../../dojo/dojo.js"></script>
<!--
<script language="JavaScript" type="text/javascript">
dojo.require("doh.runner");
function registerTests() {
doh.register("t",
[
function testTableLoaded(t){
t.assertTrue(tableStore !== null);
t.assertTrue(tableStore !== undefined);
}
]
);
doh.run();
};
dojo.addOnLoad(registerTests);
</script>
-->
 
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojox.data.HtmlTableStore");
dojo.require("dijit.Tree");
function init() {
var table = tableStore;
function testComplete(items, request){
console.debug("Completed!");
 
var attributes = null;
for(var i = 0; i < items.length; i++){
attributes = table.getAttributes(items[i]);
for(var j=0; j < attributes.length; j++){
console.debug("attribute: [" + attributes[j] + "] have value: " + table.getValue(items[i], attributes[j]));
}
}
}
table.fetch({query:{X:1}, onComplete: testComplete});
table.fetch({query:{X:2}, onComplete: testComplete});
table.fetch({query:{X:3}, onComplete: testComplete});
table.fetch({query:{X:4}, onComplete: testComplete});
table.fetch({query:{X:5}, onComplete: testComplete}); // Should be empty
}
dojo.addOnLoad(init);
</script>
 
</head>
<body class="tundra">
<h1>Dojox HtmlDataStore Widget</h1>
<hr/>
<br/>
<br/>
 
<!-- Instantiate the HtmlTableStore and bind it to global name tableStore -->
<div dojoType="dojox.data.HtmlTableStore" tableId="tableExample" jsId="tableStore"></div>
 
<!-- The table to link into with the HtmlTableStore-->
<table id="tableExample">
<thead>
<tr>
<th>X</th>
<th>Y</th>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr id="test">
<td>2</td>
<td>3</td>
<td></td>
<td>8</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td>5</td>
<td>7</td>
</tr>
<tr>
<td>4</td>
<td>9</td>
<td>22</td>
<td>777</td>
</tr>
<tr>
<td>3231</td>
<td>3</td>
<td>535</td>
<td>747</td>
</tr>
 
</tbody>
</table>
 
<br/>
<br/>
<blockquote>
<b>Table Rows: <br/><i>(Just to show that the tree can determine that the tableStore works like a store).<br/>Should have three branches, where the row had attr Y value of 3.</i></b>
<div dojoType="dijit.Tree" id="tree" store="tableStore" query="{Y:3}" label="Test tree"></div>
</blockquote>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/tests/dom.js
New file
0,0 → 1,133
if(!dojo._hasResource["dojox.data.tests.dom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.dom"] = true;
dojo.provide("dojox.data.tests.dom");
dojo.require("dojox.data.dom");
 
tests.register("dojox.data.tests.dom",
[
function testCreateDocument(t){
var document = dojox.data.dom.createDocument();
t.assertTrue(document !== null);
},
function testCreateDocumentFromText(t){
var simpleXml = "<parentNode><childNode><grandchildNode/></childNode><childNode/></parentNode>";
var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
var parent = document.firstChild;
t.assertTrue(parent !== null);
t.assertTrue(parent.tagName === "parentNode");
t.assertTrue(parent.childNodes.length == 2);
var firstChild = parent.firstChild;
t.assertTrue(firstChild !== null);
t.assertTrue(firstChild.tagName === "childNode");
t.assertTrue(firstChild.childNodes.length == 1);
var secondChild = firstChild.nextSibling;
t.assertTrue(secondChild !== null);
t.assertTrue(secondChild.tagName === "childNode");
 
var grandChild = firstChild.firstChild;
t.assertTrue(grandChild !== null);
t.assertTrue(grandChild.tagName === "grandchildNode");
 
},
function testReadTextContent(t){
var text = "This is a bunch of child text on the node";
var simpleXml = "<parentNode>" + text + "</parentNode>";
var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
var topNode = document.firstChild;
t.assertTrue(topNode !== null);
t.assertTrue(topNode.tagName === "parentNode");
t.assertTrue(text === dojox.data.dom.textContent(topNode));
dojo._destroyElement(topNode);
t.assertTrue(document.firstChild === null);
},
function testSetTextContent(t){
var text = "This is a bunch of child text on the node";
var text2 = "This is the new text";
var simpleXml = "<parentNode>" + text + "</parentNode>";
var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
var topNode = document.firstChild;
t.assertTrue(topNode !== null);
t.assertTrue(topNode.tagName === "parentNode");
t.assertTrue(text === dojox.data.dom.textContent(topNode));
dojox.data.dom.textContent(topNode, text2);
t.assertTrue(text2 === dojox.data.dom.textContent(topNode));
dojo._destroyElement(topNode);
t.assertTrue(document.firstChild === null);
 
},
function testReplaceChildrenArray(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var simpleXml2 = "<parentNode><child4/><child5/><child6/><child7/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
var topNode1 = doc1.firstChild;
var topNode2 = doc2.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
t.assertTrue(topNode2 !== null);
t.assertTrue(topNode2.tagName === "parentNode");
dojox.data.dom.removeChildren(topNode1);
var newChildren=[];
for(var i=0;i<topNode2.childNodes.length;i++){
newChildren.push(topNode2.childNodes[i]);
}
dojox.data.dom.removeChildren(topNode2);
dojox.data.dom.replaceChildren(topNode1,newChildren);
t.assertTrue(topNode1.childNodes.length === 4);
t.assertTrue(topNode1.firstChild.tagName === "child4");
t.assertTrue(topNode1.lastChild.tagName === "child7");
 
},
function testReplaceChildrenSingle(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var simpleXml2 = "<parentNode><child4/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
var topNode1 = doc1.firstChild;
var topNode2 = doc2.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
t.assertTrue(topNode2 !== null);
t.assertTrue(topNode2.tagName === "parentNode");
dojox.data.dom.removeChildren(topNode1);
var newChildren = topNode2.firstChild;
dojox.data.dom.removeChildren(topNode2);
dojox.data.dom.replaceChildren(topNode1,newChildren);
t.assertTrue(topNode1.childNodes.length === 1);
t.assertTrue(topNode1.firstChild.tagName === "child4");
t.assertTrue(topNode1.lastChild.tagName === "child4");
},
function testRemoveChildren(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var topNode1 = doc1.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
dojox.data.dom.removeChildren(topNode1);
t.assertTrue(topNode1.childNodes.length === 0);
t.assertTrue(topNode1.firstChild === null);
},
function testInnerXML(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var topNode1 = doc1.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
 
var innerXml = dojox.data.dom.innerXML(topNode1);
t.assertTrue(simpleXml1 === innerXml);
}
]
);
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/runTests.html
New file
0,0 → 1,9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Dojox Unit Test Runner</title>
<meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.data.tests.module"></HEAD>
<BODY>
Redirecting to D.O.H runner.
</BODY>
</HTML>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books.xml
New file
0,0 → 1,103
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<isbn>1</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>2</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>3</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>4</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>5</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
<book>
<isbn>6</isbn>
<title>Title of 6</title>
<author>Author of 6</author>
</book>
<book>
<isbn>7</isbn>
<title>Title of 7</title>
<author>Author of 7</author>
</book>
<book>
<isbn>8</isbn>
<title>Title of 8</title>
<author>Author of 8</author>
</book>
<book>
<isbn>9</isbn>
<title>Title of 9</title>
<author>Author of 9</author>
</book>
<book>
<isbn>10</isbn>
<title>Title of 10</title>
<author>Author of 10</author>
</book>
<book>
<isbn>11</isbn>
<title>Title of 11</title>
<author>Author of 11</author>
</book>
<book>
<isbn>12</isbn>
<title>Title of 12</title>
<author>Author of 12</author>
</book>
<book>
<isbn>13</isbn>
<title>Title of 13</title>
<author>Author of 13</author>
</book>
<book>
<isbn>14</isbn>
<title>Title of 14</title>
<author>Author of 14</author>
</book>
<book>
<isbn>15</isbn>
<title>Title of 15</title>
<author>Author of 15</author>
</book>
<book>
<isbn>16</isbn>
<title>Title of 16</title>
<author>Author of 16</author>
</book>
<book>
<isbn>17</isbn>
<title>Title of 17</title>
<author>Author of 17</author>
</book>
<book>
<isbn>18</isbn>
<title>Title of 18</title>
<author>Author of 18</author>
</book>
<book>
<isbn>19</isbn>
<title>Title of 19</title>
<author>Author of 19</author>
</book>
<book>
<isbn>20</isbn>
<title>Title of 20</title>
<author>Author of 20</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/movies2.csv
New file
0,0 → 1,9
Title, Year, Producer
City of God, 2002, Katia Lund
Rain,"", Christine Jeffs
2001: A Space Odyssey, , Stanley Kubrick
"This is a ""fake"" movie title", 1957, Sidney Lumet
Alien, 1979 , Ridley Scott
"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott
"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"
 
/trunk/api/js/dojo1.0/dojox/data/tests/stores/geography_withspeciallabel.xml
New file
0,0 → 1,51
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
<head>
<title>geography.opml</title>
<dateCreated>2006-11-10</dateCreated>
<dateModified>2006-11-13</dateModified>
<ownerName>Magellan, Ferdinand</ownerName>
</head>
<body>
<outline text="Africa" type="continent" label="Continent/Africa">
<outline text="Egypt" type="country" label="Country/Egypt"/>
<outline text="Kenya" type="country" label="Country/Kenya">
<outline text="Nairobi" type="city" label="City/Nairobi"/>
<outline text="Mombasa" type="city" label="City/Mombasa"/>
</outline>
<outline text="Sudan" type="country" label="Country/Sudan">
<outline text="Khartoum" type="city" label="City/Khartoum"/>
</outline>
</outline>
<outline text="Asia" type="continent" label="Continent/Asia">
<outline text="China" type="country" label="Country/China"/>
<outline text="India" type="country" label="Country/India"/>
<outline text="Russia" type="country" label="Country/Russia"/>
<outline text="Mongolia" type="country" label="Country/Mongolia"/>
</outline>
<outline text="Australia" type="continent" population="21 million" label="Continent/Australia">
<outline text="Australia" type="country" population="21 million" label="Country/Australia"/>
</outline>
<outline text="Europe" type="continent" label="Contintent/Europe">
<outline text="Germany" type="country" label="Country/Germany"/>
<outline text="France" type="country" label="Country/France"/>
<outline text="Spain" type="country" label="Country/Spain"/>
<outline text="Italy" type="country" label="Country/Italy"/>
</outline>
<outline text="North America" type="continent" label="Continent/North America">
<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">
<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>
<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>
</outline>
<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">
<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>
<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>
</outline>
<outline text="United States of America" type="country" label="Country/United States of America"/>
</outline>
<outline text="South America" type="continent" label="Continent/South America">
<outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>
<outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>
</outline>
</body>
</opml>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books.html
New file
0,0 → 1,118
<html>
<head>
<title>Books2.html</title>
</head>
<body>
<table id="books">
<thead>
<tr>
<th>isbn</th>
<th>title</th>
<th>author</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Title of 1</td>
<td>Author of 1</td>
</tr>
<tr>
<td>2</td>
<td>Title of 2</td>
<td>Author of 2</td>
</tr>
<tr>
<td>3</td>
<td>Title of 3</td>
<td>Author of 3</td>
</tr>
<tr>
<td>4</td>
<td>Title of 4</td>
<td>Author of 4</td>
</tr>
<tr>
<td>5</td>
<td>Title of 5</td>
<td>Author of 5</td>
</tr>
<tr>
<td>6</td>
<td>Title of 6</td>
<td>Author of 6</td>
</tr>
<tr>
<td>7</td>
<td>Title of 7</td>
<td>Author of 7</td>
</tr>
<tr>
<td>8</td>
<td>Title of 8</td>
<td>Author of 8</td>
</tr>
<tr>
<td>9</td>
<td>Title of 9</td>
<td>Author of 9</td>
</tr>
<tr>
<td>10</td>
<td>Title of 10</td>
<td>Author of 10</td>
</tr>
<tr>
<td>11</td>
<td>Title of 11</td>
<td>Author of 11</td>
</tr>
<tr>
<td>12</td>
<td>Title of 12</td>
<td>Author of 12</td>
</tr>
<tr>
<td>13</td>
<td>Title of 13</td>
<td>Author of 13</td>
</tr>
<tr>
<td>14</td>
<td>Title of 14</td>
<td>Author of 14</td>
</tr>
<tr>
<td>15</td>
<td>Title of 15</td>
<td>Author of 15</td>
</tr>
<tr>
<td>16</td>
<td>Title of 16</td>
<td>Author of 16</td>
</tr>
<tr>
<td>17</td>
<td>Title of 17</td>
<td>Author of 17</td>
</tr>
<tr>
<td>18</td>
<td>Title of 18</td>
<td>Author of 18</td>
</tr>
<tr>
<td>19</td>
<td>Title of 19</td>
<td>Author of 19</td>
</tr>
<tr>
<td>20</td>
<td>Title of 20</td>
<td>Author of 20</td>
</tr>
</tbody>
</table>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books_isbnAttr.xml
New file
0,0 → 1,23
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book isbn="1">
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book isbn="2">
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book isbn="3">
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book isbn="4">
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book isbn="5">
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/CsvStore.js
New file
0,0 → 1,1127
if(!dojo._hasResource["dojox.data.tests.stores.CsvStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.CsvStore"] = true;
dojo.provide("dojox.data.tests.stores.CsvStore");
dojo.require("dojox.data.CsvStore");
dojo.require("dojo.data.api.Read");
dojo.require("dojo.data.api.Identity");
 
dojox.data.tests.stores.CsvStore.getDatasource = function(filepath){
// summary:
// A simple helper function for getting the sample data used in each of the tests.
// description:
// A simple helper function for getting the sample data used in each of the tests.
 
var dataSource = {};
if(dojo.isBrowser){
dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
}else{
// When running tests in Rhino, xhrGet is not available,
// so we have the file data in the code below.
switch(filepath){
case "stores/movies.csv":
var csvData = "";
csvData += "Title, Year, Producer\n";
csvData += "City of God, 2002, Katia Lund\n";
csvData += "Rain,, Christine Jeffs\n";
csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
csvData += "Alien, 1979 , Ridley Scott\n";
csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
break;
case "stores/movies2.csv":
var csvData = "";
csvData += "Title, Year, Producer\n";
csvData += "City of God, 2002, Katia Lund\n";
csvData += "Rain,\"\", Christine Jeffs\n";
csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
csvData += "Alien, 1979 , Ridley Scott\n";
csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
break;
case "stores/books.csv":
var csvData = "";
csvData += "Title, Author\n";
csvData += "The Transparent Society, David Brin\n";
csvData += "The First Measured Century, Theodore Caplow\n";
csvData += "Maps in a Mirror, Orson Scott Card\n";
csvData += "Princess Smartypants, Babette Cole\n";
csvData += "Carfree Cities, Crawford J.H.\n";
csvData += "Down and Out in the Magic Kingdom, Cory Doctorow\n";
csvData += "Tax Shift, Alan Thein Durning\n";
csvData += "The Sneetches and other stories, Dr. Seuss\n";
csvData += "News from Tartary, Peter Fleming\n";
break;
case "stores/patterns.csv":
var csvData = "";
csvData += "uniqueId, value\n";
csvData += "9, jfq4@#!$!@Rf14r14i5u\n";
csvData += "6, BaBaMaSaRa***Foo\n";
csvData += "2, bar*foo\n";
csvData += "8, 123abc\n";
csvData += "4, bit$Bite\n";
csvData += "3, 123abc\n";
csvData += "10, 123abcdefg\n";
csvData += "1, foo*bar\n";
csvData += "7, \n";
csvData += "5, 123abc\n"
break;
}
dataSource.data = csvData;
}
return dataSource; //Object
}
 
dojox.data.tests.stores.CsvStore.verifyItems = function(csvStore, items, attribute, compareArray){
// summary:
// A helper function for validating that the items array is ordered
// the same as the compareArray
if(items.length != compareArray.length){ return false; }
for(var i = 0; i < items.length; i++){
if(!(csvStore.getValue(items[i], attribute) === compareArray[i])){
return false; //Boolean
}
}
return true; //Boolean
}
 
dojox.data.tests.stores.CsvStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
for (i in errData) {
console.log(errData[i]);
}
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.CsvStore",
[
function testReadAPI_fetch_all(t){
// summary:
// Simple test of a basic fetch on CsvStore.
// description:
// Simple test of a basic fetch on CsvStore.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.assertTrue((items.length === 7));
d.callback(true);
}
 
//Get everything...
csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_all_withEmptyStringField(t){
// summary:
// Simple test of a basic fetch on CsvStore.
// description:
// Simple test of a basic fetch on CsvStore.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies2.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.assertTrue((items.length === 7));
d.callback(true);
}
 
//Get everything...
csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of a basic fetch on CsvStore of a single item.
// description:
// Simple test of a basic fetch on CsvStore of a single item.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d; //Object
},
function testReadAPI_fetch_Multiple(t){
// summary:
// Simple test of a basic fetch on CsvStore of a single item.
// description:
// Simple test of a basic fetch on CsvStore of a single item.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
 
var done = [false, false];
 
function onCompleteOne(items, request){
done[0] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
function onCompleteTwo(items, request){
done[1] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
try
{
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onCompleteOne,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
csvStore.fetch({ query: {Title: "2001:*"},
onComplete: onCompleteTwo,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
}
catch(e)
{
for (i in e) {
console.log(e[i]);
}
}
 
return d; //Object
},
function testReadAPI_fetch_MultipleMixed(t){
// summary:
// Simple test of a basic fetch on CsvStore of a single item.
// description:
// Simple test of a basic fetch on CsvStore of a single item.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
 
var done = [false, false];
function onComplete(items, request){
done[0] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
function onItem(item){
done[1] = true;
t.assertTrue(item !== null);
t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
if(done[0] && done[1]){
d.callback(true);
}
}
 
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_all_streaming(t){
// summary:
// Simple test of a basic fetch on CsvStore.
// description:
// Simple test of a basic fetch on CsvStore.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
count = 0;
 
function onBegin(size, requestObj){
t.assertTrue(size === 7);
}
function onItem(item, requestObj){
t.assertTrue(csvStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(7, count);
t.is(null, items);
d.callback(true);
}
 
//Get everything...
csvStore.fetch({ onBegin: onBegin,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d; //Object
},
function testReadAPI_fetch_paging(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 args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
csvStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
csvStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
csvStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(5, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
csvStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(0, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
csvStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(5, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(7, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
csvStore.fetch(request);
}
 
csvStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
 
},
function testReadAPI_getLabel(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 args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
args.label = "Title";
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = csvStore.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("The Sequel to \"Dances With Wolves.\"", label);
d.callback(true);
}
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d;
},
function testReadAPI_getLabelAttributes(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 args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
args.label = "Title";
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = csvStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("Title", labelList[0]);
d.callback(true);
}
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d;
},
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getValue_2(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is("City of God", csvStore.getValue(item,"Title"));
t.is("2002", csvStore.getValue(item,"Year"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "0", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getValue_3(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is("1979", csvStore.getValue(item,"Year"));
t.is("Alien", csvStore.getValue(item,"Title"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getValue_4(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is("2001: A Space Odyssey", csvStore.getValue(item,"Title"));
t.is("Stanley Kubrick", csvStore.getValue(item,"Producer"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "2", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues function of the store.
// description:
// Simple test of the getValues function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
var names = csvStore.getValues(item,"Title");
t.assertTrue(dojo.isArray(names));
t.is(1, names.length);
t.is("Rain", names[0]);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testIdentityAPI_fetchItemByIdentity_bad1(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "7", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad2(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad3(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_getIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(7, items.length);
var passed = true;
for(var i = 0; i < items.length; i++){
if(!(csvStore.getIdentity(items[i]) === i)){
passed=false;
break;
}
}
t.assertTrue(passed);
d.callback(true);
}
//Get everything...
csvStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testIdentityAPI_getIdentityAttributes(t){
// summary:
// Simple test of the getIdentityAttributes
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(csvStore.isItem(item));
t.assertEqual(null, csvStore.getIdentityAttributes(item));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(csvStore.isItem(item));
t.assertTrue(!csvStore.isItem({}));
t.assertTrue(!csvStore.isItem({ item: "not an item" }));
t.assertTrue(!csvStore.isItem("not an item"));
t.assertTrue(!csvStore.isItem(["not an item"]));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.assertTrue(csvStore.hasAttribute(item, "Title"));
t.assertTrue(csvStore.hasAttribute(item, "Producer"));
t.assertTrue(!csvStore.hasAttribute(item, "Year"));
t.assertTrue(!csvStore.hasAttribute(item, "Nothing"));
t.assertTrue(!csvStore.hasAttribute(item, "title"));
 
//Test that null attributes throw an exception
var passed = false;
try{
csvStore.hasAttribute(item, null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.assertTrue(csvStore.containsValue(item, "Title", "Alien"));
t.assertTrue(csvStore.containsValue(item, "Year", "1979"));
t.assertTrue(csvStore.containsValue(item, "Producer", "Ridley Scott"));
t.assertTrue(!csvStore.containsValue(item, "Title", "Alien2"));
t.assertTrue(!csvStore.containsValue(item, "Year", "1979 "));
t.assertTrue(!csvStore.containsValue(item, "Title", null));
 
//Test that null attributes throw an exception
var passed = false;
try{
csvStore.containsValue(item, null, "foo");
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.assertTrue(csvStore.isItem(item));
 
var attributes = csvStore.getAttributes(item);
t.is(3, attributes.length);
for(var i = 0; i < attributes.length; i++){
t.assertTrue((attributes[i] === "Title" || attributes[i] === "Year" || attributes[i] === "Producer"));
}
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testReadAPI_getAttributes_onlyTwo(t){
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
// Test an item that does not have all of the attributes
t.assertTrue(item !== null);
t.assertTrue(csvStore.isItem(item));
 
var attributes = csvStore.getAttributes(item);
t.assertTrue(attributes.length === 2);
t.assertTrue(attributes[0] === "Title");
t.assertTrue(attributes[1] === "Producer");
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var features = csvStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
count++;
}
t.assertTrue(count === 2);
},
function testReadAPI_fetch_patternMatch0(t){
// summary:
// Function to test pattern matching of everything starting with lowercase e
// description:
// Function to test pattern matching of everything starting with lowercase e
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function completed(items, request){
t.is(2, items.length);
var valueArray = [ "Alien", "The Sequel to \"Dances With Wolves.\""];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "Title", valueArray));
d.callback(true);
}
csvStore.fetch({query: {Producer: "* Scott"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch1(t){
// summary:
// Function to test pattern matching of everything with $ in it.
// description:
// Function to test pattern matching of everything with $ in it.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.assertTrue(items.length === 2);
var valueArray = [ "jfq4@#!$!@Rf14r14i5u", "bit$Bite"];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", valueArray));
d.callback(true);
}
csvStore.fetch({query: {value: "*$*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch2(t){
// summary:
// Function to test exact pattern match
// description:
// Function to test exact pattern match
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
d.callback(true);
}
csvStore.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseInsensitive(t){
// summary:
// Function to test exact pattern match with case insensitivity set.
// description:
// Function to test exact pattern match with case insensitivity set.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
d.callback(true);
}
csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseSensitive(t){
// summary:
// Function to test exact pattern match with case insensitivity set.
// description:
// Function to test exact pattern match with case insensitivity set.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(0, items.length);
d.callback(true);
}
csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortNumeric(t){
// summary:
// Function to test sorting numerically.
// description:
// Function to test sorting numerically.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function completed(items, request){
t.assertTrue(items.length === 10);
// TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
var orderedArray = [ "1", "10", "2", "3", "4", "5", "6", "7", "8", "9" ];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
d.callback(true);
}
 
var sortAttributes = [{attribute: "uniqueId"}];
csvStore.fetch({onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d),
sort: sortAttributes});
return d; //Object
},
function testReadAPI_fetch_sortNumericDescending(t){
// summary:
// Function to test sorting numerically.
// description:
// Function to test sorting numerically.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(10, items.length);
// TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
var orderedArray = [ "9", "8", "7", "6", "5", "4", "3", "2", "10", "1" ];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "uniqueId", descending: true}];
csvStore.fetch({ sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortNumericWithCount(t){
// summary:
// Function to test sorting numerically in descending order, returning only a specified number of them.
// description:
// Function to test sorting numerically in descending order, returning only a specified number of them.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(5, items.length);
// TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
var orderedArray = [ "9", "8", "7", "6", "5" ];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "uniqueId", descending: true}];
csvStore.fetch({sort: sortAttributes,
count: 5,
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabetic(t){
// summary:
// Function to test sorting alphabetic ordering.
// description:
// Function to test sorting alphabetic ordering.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "123abc",
"123abc",
"123abc",
"123abcdefg",
"BaBaMaSaRa***Foo",
"bar*foo",
"bit$Bite",
"foo*bar",
"jfq4@#!$!@Rf14r14i5u",
undefined
];
t.is(10, items.length);
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "value"}];
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabeticDescending(t){
// summary:
// Function to test sorting alphabetic ordering in descending mode.
// description:
// Function to test sorting alphabetic ordering in descending mode.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ undefined,
"jfq4@#!$!@Rf14r14i5u",
"foo*bar",
"bit$Bite",
"bar*foo",
"BaBaMaSaRa***Foo",
"123abcdefg",
"123abc",
"123abc",
"123abc"
];
t.is(10, items.length);
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "value", descending: true}];
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortMultiple(t){
// summary:
// Function to test sorting on multiple attributes.
// description:
// Function to test sorting on multiple attributes.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
var orderedArray0 = [ "8", "5", "3", "10", "6", "2", "4", "1", "9", "7" ];
var orderedArray1 = [ "123abc",
"123abc",
"123abc",
"123abcdefg",
"BaBaMaSaRa***Foo",
"bar*foo",
"bit$Bite",
"foo*bar",
"jfq4@#!$!@Rf14r14i5u",
undefined
];
t.is(10, items.length);
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray0));
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray1));
d.callback(true);
}
var sortAttributes = [{ attribute: "value"}, { attribute: "uniqueId", descending: true}];
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortMultipleSpecialComparator(t){
// summary:
// Function to test sorting on multiple attributes with a custom comparator.
// description:
// Function to test sorting on multiple attributes with a custom comparator.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
csvStore.comparatorMap = {};
csvStore.comparatorMap["Producer"] = function(a,b){
var ret = 0;
// We want to sort authors alphabetical by their last name
function lastName(name){
if(typeof name === "undefined"){ return undefined; }
var matches = name.match(/\s*(\S+)$/); // Grab the last word in the string.
return matches ? matches[1] : name; // Strings with only whitespace will not match.
}
var lastNameA = lastName(a);
var lastNameB = lastName(b);
if(lastNameA > lastNameB || typeof lastNameA === "undefined"){
ret = 1;
}else if(lastNameA < lastNameB || typeof lastNameB === "undefined"){
ret = -1;
}
return ret;
};
var sortAttributes = [{attribute: "Producer", descending: true}, { attribute: "Title", descending: true}];
var d = new doh.Deferred();
function completed(items, findResult){
var orderedArray = [5,4,0,3,2,1,6];
t.assertTrue(items.length === 7);
var passed = true;
for(var i = 0; i < items.length; i++){
if(!(csvStore.getIdentity(items[i]) === orderedArray[i])){
passed=false;
break;
}
}
t.assertTrue(passed);
d.callback(true);
}
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
console.log("Looking at function: [" + i + "]");
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
},
function testIdentityAPI_functionConformance(t){
// summary:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
var identityApi = new dojo.data.api.Identity();
var passed = true;
 
for(i in identityApi){
if(i.toString().charAt(0) !== '_')
{
var member = identityApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
console.log("Looking at function: [" + i + "]");
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/geography.xml
New file
0,0 → 1,51
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
<head>
<title>geography.opml</title>
<dateCreated>2006-11-10</dateCreated>
<dateModified>2006-11-13</dateModified>
<ownerName>Magellan, Ferdinand</ownerName>
</head>
<body>
<outline text="Africa" type="continent">
<outline text="Egypt" type="country"/>
<outline text="Kenya" type="country">
<outline text="Nairobi" type="city"/>
<outline text="Mombasa" type="city"/>
</outline>
<outline text="Sudan" type="country">
<outline text="Khartoum" type="city"/>
</outline>
</outline>
<outline text="Asia" type="continent">
<outline text="China" type="country"/>
<outline text="India" type="country"/>
<outline text="Russia" type="country"/>
<outline text="Mongolia" type="country"/>
</outline>
<outline text="Australia" type="continent" population="21 million">
<outline text="Australia" type="country" population="21 million"/>
</outline>
<outline text="Europe" type="continent">
<outline text="Germany" type="country"/>
<outline text="France" type="country"/>
<outline text="Spain" type="country"/>
<outline text="Italy" type="country"/>
</outline>
<outline text="North America" type="continent">
<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">
<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>
<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>
</outline>
<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">
<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>
<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>
</outline>
<outline text="United States of America" type="country"/>
</outline>
<outline text="South America" type="continent">
<outline text="Brazil" type="country" population="186 million"/>
<outline text="Argentina" type="country" population="40 million"/>
</outline>
</body>
</opml>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/XmlStore.js
New file
0,0 → 1,881
if(!dojo._hasResource["dojox.data.tests.stores.XmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.XmlStore"] = true;
dojo.provide("dojox.data.tests.stores.XmlStore");
dojo.require("dojox.data.XmlStore");
dojo.require("dojo.data.api.Read");
dojo.require("dojo.data.api.Write");
 
 
dojox.data.tests.stores.XmlStore.getBooks2Store = function(){
return new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books2.xml").toString(), label: "title"});
};
 
dojox.data.tests.stores.XmlStore.getBooksStore = function(){
return new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books.xml").toString(), label: "title"});
};
 
doh.register("dojox.data.tests.stores.XmlStore",
[
function testReadAPI_fetch_all(t){
// summary:
// Simple test of fetching all xml items through an XML element called isbn
// description:
// Simple test of fetching all xml items through an XML element called isbn
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
{
name: "testReadAPI_fetch_paging",
timeout: 10000,
runTest: function(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.assertEqual(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
store.fetch(request);
}
function dumpSecondFetch(items, request){
t.assertEqual(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
store.fetch(request);
}
function dumpThirdFetch(items, request){
t.assertEqual(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
store.fetch(request);
}
function dumpFourthFetch(items, request){
t.assertEqual(18, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
store.fetch(request);
}
function dumpFifthFetch(items, request){
t.assertEqual(11, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
store.fetch(request);
}
function dumpSixthFetch(items, request){
t.assertEqual(18, items.length);
d.callback(true);
}
function completed(items, request){
t.assertEqual(20, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
store.fetch(request);
}
function error(errData, request){
d.errback(errData);
}
store.fetch({onComplete: completed, onError: error});
return d; //Object
}
},
function testReadAPI_fetch_pattern0(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern1(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(4, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern2(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseInsensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseSensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_all_rootItem(t){
// summary:
// Simple test of fetching all xml items through an XML element called isbn
// description:
// Simple test of fetching all xml items through an XML element called isbn
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books3.xml").toString(),
rootItem:"book"});
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_all(t){
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
console.debug(error);
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_one(t){
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
console.debug(error);
d.errback(error);
}
store.fetch({query:{isbn:"2"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_pattern0(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(3, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"ABC?"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_pattern1(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_pattern2(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(2, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?C*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
 
function testReadAPI_getLabel(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 store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = store.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Title of 4", label);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
function testReadAPI_getLabelAttributes(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 store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = store.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("title", labelList[0]);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
 
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue API
// description:
// Simple test of the getValue API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertEqual(store.getValue(item,"isbn"), "A9B574");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues API
// description:
// Simple test of the getValues API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
var values = store.getValues(item,"isbn");
t.assertEqual(1,values.length);
t.assertEqual("A9B574", values[0]);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem API
// description:
// Simple test of the isItem API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItem(item));
t.assertTrue(!store.isItem({}));
t.assertTrue(!store.isItem("Foo"));
t.assertTrue(!store.isItem(1));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem_multistore(t){
// summary:
// Simple test of the isItem API across multiple store instances.
// description:
// Simple test of the isItem API across multiple store instances.
var store1 = dojox.data.tests.stores.XmlStore.getBooks2Store();
var store2 = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete1(items, request) {
t.assertEqual(1, items.length);
var item1 = items[0];
t.assertTrue(store1.isItem(item1));
 
function onComplete2(items, request) {
t.assertEqual(1, items.length);
var item2 = items[0];
t.assertTrue(store2.isItem(item2));
t.assertTrue(!store1.isItem(item2));
t.assertTrue(!store2.isItem(item1));
d.callback(true);
}
store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store1.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError});
return d; //Object
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute API
// description:
// Simple test of the hasAttribute API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertTrue(!store.hasAttribute(item,"bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue API
// description:
// Simple test of the containsValue API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
t.assertTrue(!store.containsValue(item,"isbn", "bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescending(t){
// summary:
// Simple test of the sorting API in descending order.
// description:
// Simple test of the sorting API in descending order.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1];
var d = new doh.Deferred();
function onComplete(items, request) {
console.log("Number of items: " + items.length);
t.assertEqual(20, items.length);
 
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscending(t){
// summary:
// Simple test of the sorting API in ascending order.
// description:
// Simple test of the sorting API in ascending order.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescendingNumeric(t){
// summary:
// Simple test of the sorting API in descending order using a numeric comparator.
// description:
// Simple test of the sorting API in descending order using a numeric comparator.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 20;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId--;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscendingNumeric(t){
// summary:
// Simple test of the sorting API in ascending order using a numeric comparator.
// description:
// Simple test of the sorting API in ascending order using a numeric comparator.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId++;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItemLoaded(t){
// summary:
// Simple test of the isItemLoaded API
// description:
// Simple test of the isItemLoaded API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItemLoaded(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var features = store.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Write"));
count++;
}
t.assertEqual(2, count);
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
var attributes = store.getAttributes(item);
 
//Should be six, as all items should have tagName, childNodes, and text() special attributes
//in addition to any doc defined ones, which in this case are author, title, and isbn
//FIXME: Figure out why IE returns 5! Need to get firebug lite working in IE for that.
//Suspect it's childNodes, may not be defined if there are no child nodes.
for(var i = 0; i < attributes.length; i++){
console.log("attribute found: " + attributes[i]);
}
if(dojo.isIE){
t.assertEqual(5,attributes.length);
}else{
t.assertEqual(6,attributes.length);
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_setValue(t){
// summary:
// Simple test of the setValue API
// description:
// Simple test of the setValue API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.setValue(item, "isbn", "A9B574-new");
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_setValues(t){
// summary:
// Simple test of the setValues API
// description:
// Simple test of the setValues API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.setValues(item, "isbn", ["A9B574-new1", "A9B574-new2"]);
var values = store.getValues(item,"isbn");
t.assertEqual(values[0].toString(), "A9B574-new1");
t.assertEqual(values[1].toString(), "A9B574-new2");
store.setValues(values[0], "text()", ["A9B574", "-new3"]);
t.assertEqual(store.getValue(values[0],"text()").toString(), "A9B574-new3");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_unsetAttribute(t){
// summary:
// Simple test of the unsetAttribute API
// description:
// Simple test of the unsetAttribute API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.unsetAttribute(item,"isbn");
t.assertTrue(!store.hasAttribute(item,"isbn"));
t.assertTrue(store.isDirty(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_isDirty(t){
// summary:
// Simple test of the isDirty API
// description:
// Simple test of the isDirty API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.setValue(item, "isbn", "A9B574-new");
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
t.assertTrue(store.isDirty(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_revert(t){
// summary:
// Simple test of the isDirty API
// description:
// Simple test of the isDirty API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
t.assertTrue(!store.isDirty(item));
store.setValue(item, "isbn", "A9B574-new");
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
t.assertTrue(store.isDirty(item));
store.revert();
//Fetch again to see if it reset the state.
function onComplete1(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
d.callback(true);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.XmlStore.getBooksStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
},
function testWriteAPI_functionConformance(t){
// summary:
// Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.XmlStore.getBooksStore();
var writeApi = new dojo.data.api.Write();
var passed = true;
 
for(i in writeApi){
var member = writeApi[i];
//Check that all the 'Write' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
t.assertTrue(passed);
}
]
);
 
 
 
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/QueryReadStore.js
New file
0,0 → 1,338
if(!dojo._hasResource["dojox.data.tests.stores.QueryReadStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.QueryReadStore"] = true;
dojo.provide("dojox.data.tests.stores.QueryReadStore");
dojo.require("dojox.data.QueryReadStore");
dojo.require("dojo.data.api.Read");
 
//dojo.require("dojox.testing.DocTest");
 
dojox.data.tests.stores.QueryReadStore.getStore = function(){
return new dojox.data.QueryReadStore({
url: dojo.moduleUrl("dojox.data.tests", "stores/QueryReadStore.php").toString(),
doClientPaging:true // "true" is actually also the default, but make sure :-).
});
};
 
 
tests.register("dojox.data.tests.stores.QueryReadStore",
[
/*
function testDocTests(t) {
// summary:
// Run all the doc comments.
var doctest = new dojox.testing.DocTest();
doctest.run("dojox.data.QueryReadStore");
t.assertTrue(doctest.errors.length==0);
},
*/
function testReadApi_getValue(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good cases.
t.assertEqual("Alabama", store.getValue(item, "name"));
t.assertEqual("<img src='images/Alabama.jpg'/>Alabama", store.getValue(item, "label"));
t.assertEqual("AL", store.getValue(item, "abbreviation"));
// Test the defaultValue cases (the third paramter).
t.assertEqual("default value", store.getValue(item, "NAME", "default value"));
// TODO Test for null somehow ...
// Read api says: Returns null if and only if null was explicitly set as the attribute value.
// According to Read-API getValue() an exception is thrown when
// the item is not an item or when the attribute is not a string.
t.assertError(Error, store, "getValue", ["not an item", "NOT THERE"]);
t.assertError(Error, store, "getValue", [item, {}]);
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_getValues(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good cases.
t.assertEqual(["Alabama"], store.getValues(item, "name"));
t.assertEqual(["<img src='images/Alabama.jpg'/>Alabama"], store.getValues(item, "label"));
t.assertEqual(["AL"], store.getValues(item, "abbreviation"));
// TODO Test for null somehow ...
// Read api says: Returns null if and only if null was explicitly set as the attribute value.
 
// Test for not-existing attributes without defaultValues and invalid items.
// TODO
//dojox.data.tests.stores.QueryReadStore.assertError(dojox.data.QueryReadStore.InvalidAttributeError, store, "getValues", [item, "NOT THERE"]);
//dojox.data.tests.stores.QueryReadStore.assertError(dojox.data.QueryReadStore.InvalidItemError, store, "getValues", ["not an item", "NOT THERE"]);
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
function testReadApi_getAttributes(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good case(s).
t.assertEqual(['name', 'label', 'abbreviation'], store.getAttributes(item));
t.assertError(dojox.data.QueryReadStore.InvalidItemError, store, "getAttributes", [{}]);
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_hasAttribute(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The positive cases.
t.assertEqual(true, store.hasAttribute(item, "name"));
t.assertEqual(true, store.hasAttribute(item, "label"));
t.assertEqual(true, store.hasAttribute(item, "abbreviation"));
// Make sure attribute case doesnt matter.
t.assertEqual(false, store.hasAttribute(item, "NAME"));
t.assertEqual(false, store.hasAttribute(item, "Name"));
t.assertEqual(false, store.hasAttribute(item, "Label"));
// Pass in an invalid item.
t.assertEqual(false, store.hasAttribute({}, "abbreviation"));
// pass in something that looks like the item with the attribute.
t.assertEqual(false, store.hasAttribute({name:"yo"}, "name"));
d.callback(true);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_containsValue(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
t.assertTrue(store.containsValue(item, "name", "Alaska"));
d.callback(true);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_isItem(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
// The good case.
t.assertEqual(true, store.isItem(items[0]));
// Try a pure object.
t.assertEqual(false, store.isItem({}));
// Try to look like an item.
t.assertEqual(false, store.isItem({name:"Alaska", label:"Alaska", abbreviation:"AK"}));
d.callback(true);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_isItemLoaded(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good case(s).
t.assertTrue(store.isItemLoaded(item));
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
 
//function testReadApi_loadItem(t){
// // summary:
// // description:
// t.assertTrue(false);
//},
 
function testReadApi_fetch_all(t){
// summary:
// Simple test of fetching all items.
// description:
// Simple test of fetching all items.
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(8, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{q:"a"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadApi_fetch_one(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete, onError: onError});
return d; //Object
},
 
function testReadApi_fetch_client_paging(t){
// summary:
// Lets test that paging on the same request does not trigger
// server requests.
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var lastRequestHash = null;
var firstItems = [];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
lastRequestHash = store.lastRequestHash;
firstItems = items;
// Do the next request AFTER the previous one, so we are sure its sequential.
// We need to be sure so we can compare to the data from the first request.
function onComplete1(items, request) {
t.assertEqual(5, items.length);
t.assertEqual(lastRequestHash, store.lastRequestHash);
t.assertEqual(firstItems[1], items[0]);
d.callback(true);
}
req.start = 1;
req.onComplete = onComplete1;
store.fetch(req);
}
function onError(error, request) {
d.errback(error);
}
var req = {query:{q:"a"}, start:0, count:5,
onComplete: onComplete, onError: onError};
store.fetch(req);
return d; //Object
},
function testReadApi_fetch_server_paging(t) {
// Verify that the paging on the server side does work.
// This is the test for http://trac.dojotoolkit.org/ticket/4761
//
// How? We request 10 items from the server, start=0, count=10.
// The second request requests 5 items: start=5, count=5 and those
// 5 items should have the same values as the last 5 of the first
// request.
// This tests if the server side paging does work.
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var lastRequestHash = null;
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(10, items.length);
lastRequestHash = store.lastRequestHash;
firstItems = items;
// Do the next request AFTER the previous one, so we are sure its sequential.
// We need to be sure so we can compare to the data from the first request.
function onComplete1(items, request) {
t.assertEqual(5, items.length);
// Compare the hash of the last request, they must be different,
// since another server request was issued.
t.assertTrue(lastRequestHash!=store.lastRequestHash);
t.assertEqual(store.getValue(firstItems[5], "name"), store.getValue(items[0], "name"));
t.assertEqual(store.getValue(firstItems[6], "name"), store.getValue(items[1], "name"));
t.assertEqual(store.getValue(firstItems[7], "name"), store.getValue(items[2], "name"));
t.assertEqual(store.getValue(firstItems[8], "name"), store.getValue(items[3], "name"));
t.assertEqual(store.getValue(firstItems[9], "name"), store.getValue(items[4], "name"));
d.callback(true);
}
// Init a new store, or it will use the old data, since the query has not changed.
store.doClientPaging = false;
store.fetch({start:5, count:5, onComplete: onComplete1, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{}, start:0, count:10, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadApi_getFeatures(t) {
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var features = store.getFeatures();
t.assertTrue(features["dojo.data.api.Read"]);
t.assertTrue(features["dojo.data.api.Identity"]);
var count = 0;
for (i in features){
count++;
}
t.assertEqual(2, count);
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.QueryReadStore.getStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
}
]
);
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/patterns.csv
New file
0,0 → 1,11
uniqueId, value
9, jfq4@#!$!@Rf14r14i5u
6, BaBaMaSaRa***Foo
2, bar*foo
8, 123abc
4, bit$Bite
3, 123abc
10, 123abcdefg
1, foo*bar
7,
5, 123abc
/trunk/api/js/dojo1.0/dojox/data/tests/stores/movies.csv
New file
0,0 → 1,9
Title, Year, Producer
City of God, 2002, Katia Lund
Rain,, Christine Jeffs
2001: A Space Odyssey, , Stanley Kubrick
"This is a ""fake"" movie title", 1957, Sidney Lumet
Alien, 1979 , Ridley Scott
"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott
"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"
 
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books2.xml
New file
0,0 → 1,28
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<isbn>A9B57C</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>A9B57F</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>A9B577</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>A9B574</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>A9B5CC</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/OpmlStore.js
New file
0,0 → 1,1075
if(!dojo._hasResource["dojox.data.tests.stores.OpmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.OpmlStore"] = true;
dojo.provide("dojox.data.tests.stores.OpmlStore");
dojo.require("dojox.data.OpmlStore");
dojo.require("dojo.data.api.Read");
 
dojox.data.tests.stores.OpmlStore.getDatasource = function(filepath){
// summary:
// A simple helper function for getting the sample data used in each of the tests.
// description:
// A simple helper function for getting the sample data used in each of the tests.
var dataSource = {};
if(dojo.isBrowser){
dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
}else{
// When running tests in Rhino, xhrGet is not available,
// so we have the file data in the code below.
switch(filepath){
case "stores/geography.xml":
var opmlData = "";
opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
opmlData += ' <opml version="1.0">\n';
opmlData += ' <head>\n';
opmlData += ' <title>geography.opml</title>\n';
opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
opmlData += ' <dateModified>2006-11-13</dateModified>\n';
opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
opmlData += ' </head>\n';
opmlData += ' <body>\n';
opmlData += ' <outline text="Africa" type="continent">\n';
opmlData += ' <outline text="Egypt" type="country"/>\n';
opmlData += ' <outline text="Kenya" type="country">\n';
opmlData += ' <outline text="Nairobi" type="city"/>\n';
opmlData += ' <outline text="Mombasa" type="city"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Sudan" type="country">\n';
opmlData += ' <outline text="Khartoum" type="city"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Asia" type="continent">\n';
opmlData += ' <outline text="China" type="country"/>\n';
opmlData += ' <outline text="India" type="country"/>\n';
opmlData += ' <outline text="Russia" type="country"/>\n';
opmlData += ' <outline text="Mongolia" type="country"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Australia" type="continent" population="21 million">\n';
opmlData += ' <outline text="Australia" type="country" population="21 million"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Europe" type="continent">\n';
opmlData += ' <outline text="Germany" type="country"/>\n';
opmlData += ' <outline text="France" type="country"/>\n';
opmlData += ' <outline text="Spain" type="country"/>\n';
opmlData += ' <outline text="Italy" type="country"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="North America" type="continent">\n';
opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n';
opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n';
opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n';
opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n';
opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="United States of America" type="country"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="South America" type="continent">\n';
opmlData += ' <outline text="Brazil" type="country" population="186 million"/>\n';
opmlData += ' <outline text="Argentina" type="country" population="40 million"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </body>\n';
opmlData += ' </opml>\n';
break;
case "stores/geography_withspeciallabel.xml":
var opmlData = "";
opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
opmlData += '<opml version="1.0">\n';
opmlData += ' <head>\n';
opmlData += ' <title>geography.opml</title>\n';
opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
opmlData += ' <dateModified>2006-11-13</dateModified>\n';
opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
opmlData += ' </head>\n';
opmlData += ' <body>\n';
opmlData += ' <outline text="Africa" type="continent" label="Continent/Africa">\n';
opmlData += ' <outline text="Egypt" type="country" label="Country/Egypt"/>\n';
opmlData += ' <outline text="Kenya" type="country" label="Country/Kenya">\n';
opmlData += ' <outline text="Nairobi" type="city" label="City/Nairobi"/>\n';
opmlData += ' <outline text="Mombasa" type="city" label="City/Mombasa"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Sudan" type="country" label="Country/Sudan">\n';
opmlData += ' <outline text="Khartoum" type="city" label="City/Khartoum"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Asia" type="continent" label="Continent/Asia">\n';
opmlData += ' <outline text="China" type="country" label="Country/China"/>\n';
opmlData += ' <outline text="India" type="country" label="Country/India"/>\n';
opmlData += ' <outline text="Russia" type="country" label="Country/Russia"/>\n';
opmlData += ' <outline text="Mongolia" type="country" label="Country/Mongolia"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Australia" type="continent" population="21 million" label="Continent/Australia">\n';
opmlData += ' <outline text="Australia" type="country" population="21 million" label="Country/Australia"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Europe" type="continent" label="Contintent/Europe">\n';
opmlData += ' <outline text="Germany" type="country" label="Country/Germany"/>\n';
opmlData += ' <outline text="France" type="country" label="Country/France"/>\n';
opmlData += ' <outline text="Spain" type="country" label="Country/Spain"/>\n';
opmlData += ' <outline text="Italy" type="country" label="Country/Italy"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="North America" type="continent" label="Continent/North America">\n';
opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">\n';
opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>\n';
opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">\n';
opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>\n';
opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="United States of America" type="country" label="Country/United States of America"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="South America" type="continent" label="Continent/South America">\n';
opmlData += ' <outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>\n';
opmlData += ' <outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </body>\n';
opmlData += '</opml>\n';
break;
}
dataSource.data = opmlData;
}
return dataSource; //Object
}
 
dojox.data.tests.stores.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){
// summary:
// A helper function for validating that the items array is ordered
// the same as the compareArray
if(items.length != compareArray.length){ return false; }
for(var i = 0; i < items.length; i++){
if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){
return false; //Boolean
}
}
return true; //Boolean
}
 
dojox.data.tests.stores.OpmlStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.OpmlStore",
[
function testReadAPI_fetch_all(t){
// summary:
// Simple test of a basic fetch on OpmlStore.
// description:
// Simple test of a basic fetch on OpmlStore.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.is(6, items.length);
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
 
function testReadAPI_fetch_one_Multiple(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
var done = [false,false];
function onCompleteOne(items, request){
done[0] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
function onCompleteTwo(items, request){
done[1] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
 
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onCompleteOne,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
 
opmlStore.fetch({ query: {text: "North America"},
onComplete: onCompleteTwo,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
 
return d; //Object
},
 
function testReadAPI_fetch_one_MultipleMixed(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item mixing two fetch types.
// description:
// Simple test of a basic fetch on Cpmltore of a single item mixing two fetch types.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
 
var done = [false, false];
function onComplete(items, request){
done[0] = true;
t.is(1, items.length);
console.log("Found item: " + opmlStore.getValue(items[0],"text") + " with identity: " + opmlStore.getIdentity(items[0]));
t.is(0, opmlStore.getIdentity(items[0]));
if(done[0] && done[1]){
d.callback(true);
}
}
function onItem(item){
done[1] = true;
t.assertTrue(item !== null);
console.log("Found item: " + opmlStore.getValue(item,"text"));
t.is('Egypt', opmlStore.getValue(item,"text")); //Should be the second node parsed, ergo id 1, first node is id 0.
t.is(1, opmlStore.getIdentity(item));
if(done[0] && done[1]){
d.callback(true);
}
}
 
opmlStore.fetch({ query: {text: "Africa"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
 
return d; //Object
},
 
function testReadAPI_fetch_one_deep(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Mexico City"},
queryOptions: {deep:true},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
 
function testReadAPI_fetch_one_deep_off(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
//Nothing should be found.
t.is(0, items.length);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Mexico City"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
 
function testReadAPI_fetch_all_streaming(t){
// summary:
// Simple test of a basic fetch on OpmlStore.
// description:
// Simple test of a basic fetch on OpmlStore.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
count = 0;
 
function onBegin(size, requestObj){
t.is(6, size);
}
function onItem(item, requestObj){
t.assertTrue(opmlStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(6, count);
t.is(null, items);
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onBegin: onBegin,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
function testReadAPI_fetch_paging(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 args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
opmlStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
opmlStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
opmlStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(4, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
opmlStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(0, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
opmlStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(4, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(6, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
opmlStore.fetch(request);
}
 
opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
 
},
function testReadAPI_getLabel(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 args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = opmlStore.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Asia", label);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
function testReadAPI_getLabelAttributes(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 args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = opmlStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("text", labelList[0]);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
 
function testReadAPI_getLabel_nondefault(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 args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
args.label="label";
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = opmlStore.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Continent/Asia", label);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
function testReadAPI_getLabelAttributes_nondefault(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 args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
args.label="label";
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = opmlStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("label", labelList[0]);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
 
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.is(6, items.length);
t.is("Africa", opmlStore.getValue(items[0],"text"));
t.is("Asia", opmlStore.getValue(items[1],"text"));
t.is("Australia", opmlStore.getValue(items[2],"text"));
t.is("Europe", opmlStore.getValue(items[3],"text"));
t.is("North America", opmlStore.getValue(items[4],"text"));
t.is("South America", opmlStore.getValue(items[5],"text"));
t.is("continent", opmlStore.getValue(items[1],"type"));
t.is("21 million", opmlStore.getValue(items[2],"population"));
var firstChild = opmlStore.getValue(items[4],"children");
t.assertTrue(opmlStore.isItem(firstChild));
t.is("Mexico", opmlStore.getValue(firstChild,"text"));
t.is("country", opmlStore.getValue(firstChild,"type"));
t.is("108 million", opmlStore.getValue(firstChild,"population"));
t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area"));
firstChild = opmlStore.getValue(firstChild,"children");
t.assertTrue(opmlStore.isItem(firstChild));
t.is("Mexico City", opmlStore.getValue(firstChild,"text"));
t.is("city", opmlStore.getValue(firstChild,"type"));
t.is("19 million", opmlStore.getValue(firstChild,"population"));
t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone"));
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues function of the store.
// description:
// Simple test of the getValues function of the store.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function completed(items){
t.is(1, items.length);
var children = opmlStore.getValues(items[0],"children");
t.is(3, children.length);
for(var i=0; i<children.length; i++){
t.assertTrue(opmlStore.isItem(children[i]));
}
t.is("Mexico", opmlStore.getValues(children[0],"text")[0]);
t.is("country", opmlStore.getValues(children[0],"type")[0]);
t.is("108 million", opmlStore.getValues(children[0],"population")[0]);
t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]);
t.is("Canada", opmlStore.getValues(children[1],"text")[0]);
t.is("country", opmlStore.getValues(children[1],"type")[0]);
children = opmlStore.getValues(children[1],"children");
t.is(2, children.length);
for(var i=0; i<children.length; i++){
t.assertTrue(opmlStore.isItem(children[i]));
}
t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]);
t.is("Toronto", opmlStore.getValues(children[1],"text")[0]);
d.callback(true);
}
 
//Get one item...
opmlStore.fetch({ query: {text: "North America"},
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function completedAll(items){
t.is(6, items.length);
for(var i=0; i<6; i++){
t.assertTrue(opmlStore.isItem(items[i]));
}
t.assertTrue(!opmlStore.isItem({}));
t.assertTrue(!opmlStore.isItem({ item: "not an item" }));
t.assertTrue(!opmlStore.isItem("not an item"));
t.assertTrue(!opmlStore.isItem(["not an item"]));
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(opmlStore.hasAttribute(items[0], "text"));
t.assertTrue(opmlStore.hasAttribute(items[0], "type"));
t.assertTrue(!opmlStore.hasAttribute(items[0], "population"));
t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing"));
t.assertTrue(!opmlStore.hasAttribute(items[0], "Text"));
//Test that null attributes throw an exception
var passed = false;
try{
opmlStore.hasAttribute(items[0], null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(opmlStore.containsValue(items[0], "text", "North America"));
t.assertTrue(opmlStore.containsValue(items[0], "type", "continent"));
t.assertTrue(!opmlStore.containsValue(items[0], "text", "America"));
t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent"));
t.assertTrue(!opmlStore.containsValue(items[0], "text", null));
var children = opmlStore.getValues(items[0], "children");
t.assertTrue(opmlStore.containsValue(items[0], "children", children[0]));
t.assertTrue(opmlStore.containsValue(items[0], "children", children[1]));
t.assertTrue(opmlStore.containsValue(items[0], "children", children[2]));
//Test that null attributes throw an exception
var passed = false;
try{
opmlStore.containsValue(items[0], null, "foo");
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
opmlStore.fetch({ query: {text: "North America"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function onComplete(items){
t.is(6, items.length);
t.assertTrue(opmlStore.isItem(items[0]));
var attributes = opmlStore.getAttributes(items[0]);
t.is(3, attributes.length);
for(var i = 0; i < attributes.length; i++){
t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children"));
}
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var features = opmlStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity"));
count++;
}
t.assertTrue(count === 2);
},
function testReadAPI_fetch_patternMatch0(t){
// summary:
// Function to test pattern matching of everything starting with Capital A
// description:
// Function to test pattern matching of everything starting with Capital A
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function completed(items, request){
t.is(3, items.length);
var valueArray = [ "Africa", "Asia", "Australia"];
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
d.callback(true);
}
opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch1(t){
// summary:
// Function to test pattern matching of everything with America in it.
// description:
// Function to test pattern matching of everything with America in it.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.assertTrue(items.length === 2);
var valueArray = [ "North America", "South America"];
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
d.callback(true);
}
opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch2(t){
// summary:
// Function to test exact pattern match
// description:
// Function to test exact pattern match
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe");
d.callback(true);
}
opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseInsensitive(t){
// summary:
// Function to test exact pattern match with case insensitivity set.
// description:
// Function to test exact pattern match with case insensitivity set.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia");
d.callback(true);
}
opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseSensitive(t){
// summary:
// Function to test exact pattern match with case sensitivity set.
// description:
// Function to test exact pattern match with case sensitivity set.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(0, items.length);
d.callback(true);
}
opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabetic(t){
// summary:
// Function to test sorting alphabetic ordering.
// description:
// Function to test sorting alphabetic ordering.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"];
t.is(6, items.length);
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "text"}];
opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabeticDescending(t){
// summary:
// Function to test sorting alphabetic ordering in descending mode.
// description:
// Function to test sorting alphabetic ordering in descending mode.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa"
];
t.is(6, items.length);
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "text", descending: true}];
opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabeticWithCount(t){
// summary:
// Function to test sorting numerically in descending order, returning only a specified number of them.
// description:
// Function to test sorting numerically in descending order, returning only a specified number of them.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "South America", "North America", "Europe", "Australia"
];
t.is(4, items.length);
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "text", descending: true}];
opmlStore.fetch({sort: sortAttributes,
count: 4,
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
},
function testIdentityAPI_fetchItemByIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
 
function testIdentityAPI_fetchItemByIdentity_bad1(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad2(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad3(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
function testIdentityAPI_getIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
var passed = true;
for(var i = 0; i < items.length; i++){
console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i);
if(!(opmlStore.getIdentity(items[i]) == i)){
passed=false;
break;
}
}
t.assertTrue(passed);
d.callback(true);
}
//Get everything...
opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}});
return d; //Object
},
function testIdentityAPI_functionConformance(t){
// summary:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/geography.xml"));
var identityApi = new dojo.data.api.Identity();
var passed = true;
 
for(i in identityApi){
if(i.toString().charAt(0) !== '_')
{
var member = identityApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
console.log("Looking at function: [" + i + "]");
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books3.xml
New file
0,0 → 1,31
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<category>
<name>Category 1</name>
<book>
<isbn>1</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>2</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>3</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>4</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>5</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</category>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/FlickrRestStore.js
New file
0,0 → 1,476
if(!dojo._hasResource["dojox.data.tests.stores.FlickrRestStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.FlickrRestStore"] = true;
dojo.provide("dojox.data.tests.stores.FlickrRestStore");
dojo.require("dojox.data.FlickrRestStore");
dojo.require("dojo.data.api.Read");
 
 
dojox.data.tests.stores.FlickrRestStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.FlickrRestStore",
[
{
name: "ReadAPI: Fetch_One",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrRestStore of a single item.
// description:
// Simple test of a basic fetch on FlickrRestStore of a single item.
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, doh, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_20_Streaming",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrRestStore.
// description:
// Simple test of a basic fetch on FlickrRestStore.
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
var count = 0;
 
function onItem(item, requestObj){
t.assertTrue(flickrStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(5, count);
t.is(null, items);
d.callback(true);
}
//Get everything...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
onBegin: null,
count: 5,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_Paging",
timeout: 30000, //30 seconds. Flickr can sometimes be slow.
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 flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
flickrStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
flickrStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 18;
request.onComplete = dumpFourthFetch;
flickrStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(18, items.length);
request.start = 9;
request.count = 11;
request.onComplete = dumpFifthFetch;
flickrStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(11, items.length);
request.start = 4;
request.count = 16;
request.onComplete = dumpSixthFetch;
flickrStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
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;
flickrStore.fetch(request);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 7,
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: getLabel",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
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 flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = flickrStore.getLabel(items[0]);
t.assertTrue(label !== null);
d.callback(true);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getLabelAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
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 flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = flickrStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("title", labelList[0]);
d.callback(true);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
d.callback(true);
}
 
//Get one item and look at it.
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: completedAll,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: getValues",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
var title = flickrStore.getValues(items[0], "title");
t.assertTrue(title instanceof Array);
var imgUrl = flickrStore.getValues(items[0], "imageUrl");
t.assertTrue(imgUrl instanceof Array);
var imgUrlSmall = flickrStore.getValues(items[0], "imageUrlSmall");
t.assertTrue(imgUrlSmall instanceof Array);
var imgUrlMedium = flickrStore.getValues(items[0], "imageUrlMedium");
t.assertTrue(imgUrlMedium instanceof Array);
d.callback(true);
}
//Get one item and look at it.
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: completedAll,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error,
t,
d)});
return d; //Object
}
},
{
name: "ReadAPI: isItem",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(5, items.length);
for(var i=0; i < items.length; i++){
t.assertTrue(flickrStore.isItem(items[i]));
}
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 5,
onComplete: completedAll,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: hasAttribute",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
 
//Test that null attributes throw an exception
var passed = false;
try{
flickrStore.hasAttribute(items[0], null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: containsValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: getAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(flickrStore.isItem(items[0]));
 
var attributes = flickrStore.getAttributes(items[0]);
t.is(9, attributes.length);
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var features = flickrStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read"));
count++;
}
t.assertTrue(count === 1);
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.FlickrRestStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/FlickrStore.js
New file
0,0 → 1,410
if(!dojo._hasResource["dojox.data.tests.stores.FlickrStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.FlickrStore"] = true;
dojo.provide("dojox.data.tests.stores.FlickrStore");
dojo.require("dojox.data.FlickrStore");
dojo.require("dojo.data.api.Read");
 
 
dojox.data.tests.stores.FlickrStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.FlickrStore",
[
{
name: "ReadAPI: Fetch_One",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrStore of a single item.
// description:
// Simple test of a basic fetch on FlickrStore of a single item.
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, doh, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_20_Streaming",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrStore.
// description:
// Simple test of a basic fetch on FlickrStore.
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
count = 0;
 
function onBegin(size, requestObj){
t.is(20, size);
}
function onItem(item, requestObj){
t.assertTrue(flickrStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(20, count);
t.is(null, items);
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({ onBegin: onBegin,
count: 20,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_Paging",
timeout: 30000, //30 seconds. Flickr can sometimes be slow.
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 flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
flickrStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
flickrStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
flickrStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(18, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
flickrStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(11, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
flickrStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(18, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(7, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
flickrStore.fetch(request);
}
flickrStore.fetch({count: 7, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: getLabel",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
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 flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = flickrStore.getLabel(items[0]);
t.assertTrue(label !== null);
d.callback(true);
}
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getLabelAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
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 flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = flickrStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("title", labelList[0]);
d.callback(true);
}
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
d.callback(true);
}
 
//Get one item and look at it.
flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: getValues",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
t.assertTrue(flickrStore.getValues(items[0], "title") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "description") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "imageUrl") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "imageUrlSmall") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "imageUrlMedium") instanceof Array);
d.callback(true);
}
//Get one item and look at it.
flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: isItem",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(5, items.length);
for(var i=0; i < items.length; i++){
t.assertTrue(flickrStore.isItem(items[i]));
}
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({ count: 5, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: hasAttribute",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
t.assertTrue(flickrStore.hasAttribute(items[0], "description"));
t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
 
//Test that null attributes throw an exception
var passed = false;
try{
flickrStore.hasAttribute(items[0], null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: containsValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: getAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(flickrStore.isItem(items[0]));
 
var attributes = flickrStore.getAttributes(items[0]);
t.is(10, attributes.length);
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({ count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var features = flickrStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read"));
count++;
}
t.assertTrue(count === 1);
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.FlickrStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books2.html
New file
0,0 → 1,43
<html>
<head>
<title>Books2.html</title>
</head>
<body>
<table id="books2">
<thead>
<tr>
<th>isbn</th>
<th>title</th>
<th>author</th>
</tr>
</thead>
<tbody>
<tr>
<td>A9B57C</td>
<td>Title of 1</td>
<td>Author of 1</td>
</tr>
<tr>
<td>A9B57F</td>
<td>Title of 2</td>
<td>Author of 2</td>
</tr>
<tr>
<td>A9B577</td>
<td>Title of 3</td>
<td>Author of 3</td>
</tr>
<tr>
<td>A9B574</td>
<td>Title of 4</td>
<td>Author of 4</td>
</tr>
<tr>
<td>A9B5CC</td>
<td>Title of 5</td>
<td>Author of 5</td>
</tr>
</tbody>
</table>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/HtmlTableStore.js
New file
0,0 → 1,702
if(!dojo._hasResource["dojox.data.tests.stores.HtmlTableStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.HtmlTableStore"] = true;
dojo.provide("dojox.data.tests.stores.HtmlTableStore");
dojo.require("dojox.data.HtmlTableStore");
dojo.require("dojo.data.api.Read");
dojo.require("dojo.data.api.Identity");
 
 
dojox.data.tests.stores.HtmlTableStore.getBooks2Store = function(){
return new dojox.data.HtmlTableStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books2.html").toString(), tableId: "books2"});
};
 
dojox.data.tests.stores.HtmlTableStore.getBooksStore = function(){
return new dojox.data.HtmlTableStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books.html").toString(), tableId: "books"});
};
 
doh.register("dojox.data.tests.stores.HtmlTableStore",
[
/***************************************
dojo.data.api.Read API
***************************************/
function testReadAPI_fetch_all(t){
// summary:
// Simple test of fetching all xml items through an XML element called isbn
// description:
// Simple test of fetching all xml items through an XML element called isbn
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_paging(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.assertEqual(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
store.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.assertEqual(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
store.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.assertEqual(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
store.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.assertEqual(18, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
store.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.assertEqual(11, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
store.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.assertEqual(18, items.length);
d.callback(true);
}
 
function completed(items, request){
t.assertEqual(20, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
store.fetch(request);
}
 
function error(errData, request){
d.errback(errData);
}
 
store.fetch({onComplete: completed, onError: error});
return d; //Object
},
function testReadAPI_fetch_pattern0(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern1(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(4, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern2(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseInsensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseSensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getLabel(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 store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = store.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Table Row #3", label);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
function testReadAPI_getLabelAttributes(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 store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = store.getLabelAttributes(items[0]);
t.assertTrue(labelList === null);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
 
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue API
// description:
// Simple test of the getValue API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertEqual(store.getValue(item,"isbn"), "A9B574");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues API
// description:
// Simple test of the getValues API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
var values = store.getValues(item,"isbn");
t.assertEqual(1,values.length);
t.assertEqual("A9B574", values[0]);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem API
// description:
// Simple test of the isItem API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItem(item));
t.assertTrue(!store.isItem({}));
t.assertTrue(!store.isItem("Foo"));
t.assertTrue(!store.isItem(1));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem_multistore(t){
// summary:
// Simple test of the isItem API across multiple store instances.
// description:
// Simple test of the isItem API across multiple store instances.
var store1 = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var store2 = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete1(items, request) {
t.assertEqual(1, items.length);
var item1 = items[0];
t.assertTrue(store1.isItem(item1));
 
function onComplete2(items, request) {
t.assertEqual(1, items.length);
var item2 = items[0];
t.assertTrue(store2.isItem(item2));
t.assertTrue(!store1.isItem(item2));
t.assertTrue(!store2.isItem(item1));
d.callback(true);
}
store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store1.fetch({query:{isbn:"1"}, onComplete: onComplete1, onError: onError});
return d; //Object
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute API
// description:
// Simple test of the hasAttribute API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertTrue(!store.hasAttribute(item,"bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue API
// description:
// Simple test of the containsValue API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
t.assertTrue(!store.containsValue(item,"isbn", "bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescending(t){
// summary:
// Simple test of the sorting API in descending order.
// description:
// Simple test of the sorting API in descending order.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
 
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscending(t){
// summary:
// Simple test of the sorting API in ascending order.
// description:
// Simple test of the sorting API in ascending order.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescendingNumeric(t){
// summary:
// Simple test of the sorting API in descending order using a numeric comparator.
// description:
// Simple test of the sorting API in descending order using a numeric comparator.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 20;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId--;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscendingNumeric(t){
// summary:
// Simple test of the sorting API in ascending order using a numeric comparator.
// description:
// Simple test of the sorting API in ascending order using a numeric comparator.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId++;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItemLoaded(t){
// summary:
// Simple test of the isItemLoaded API
// description:
// Simple test of the isItemLoaded API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItemLoaded(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var features = store.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
count++;
}
t.assertEqual(2, count);
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
var attributes = store.getAttributes(item);
t.assertEqual(3,attributes.length);
for(var i=0; i<attributes.length; i++){
t.assertTrue((attributes[i] === "isbn" || attributes[i] === "title" || attributes[i] === "author"));
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
},
/***************************************
dojo.data.api.Identity API
***************************************/
function testIdentityAPI_getIdentity(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertEqual(3,store.getIdentity(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testIdentityAPI_getIdentityAttributes(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
//Should have none, as it's not a public attribute.
var attributes = store.getIdentityAttributes(item);
t.assertEqual(null, attributes);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testIdentityAPI_fetchItemByIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity API
// description:
// Simple test of the fetchItemByIdentity API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onItem(item, request) {
t.assertTrue(item !== null);
t.assertTrue(store.isItem(item));
t.assertEqual("A9B574", store.getValue(item, "isbn"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetchItemByIdentity({identity: 3, onItem: onItem, onError: onError});
return d; //Object
},
function testIdentityAPI_functionConformance(t){
// summary:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var identityApi = new dojo.data.api.Identity();
var passed = true;
 
for(i in identityApi){
var member = identityApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
}
]
);
 
//Register the remote tests ... when they work.
//doh.registerUrl("dojox.data.tests.stores.HtmlTableStore.remote", dojo.moduleUrl("dojox.data.tests", "ml/test_HtmlTableStore_declaratively.html"));
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/QueryReadStore.php
New file
0,0 → 1,92
<?php
 
header("Content-Type", "text/json");
 
$allItems = array(
array('name'=>"Alabama", 'label'=>"<img src='images/Alabama.jpg'/>Alabama", 'abbreviation'=>"AL"),
array('name'=>"Alaska", 'label'=>"Alaska", 'abbreviation'=>"AK"),
array('name'=>"American Samoa", 'label'=>"American Samoa", 'abbreviation'=>"AS"),
array('name'=>"Arizona", 'label'=>"Arizona", 'abbreviation'=>"AZ"),
array('name'=>"Arkansas", 'label'=>"Arkansas", 'abbreviation'=>"AR"),
array('name'=>"Armed Forces Europe", 'label'=>"Armed Forces Europe", 'abbreviation'=>"AE"),
array('name'=>"Armed Forces Pacific", 'label'=>"Armed Forces Pacific", 'abbreviation'=>"AP"),
array('name'=>"Armed Forces the Americas", 'label'=>"Armed Forces the Americas", 'abbreviation'=>"AA"),
array('name'=>"California", 'label'=>"California", 'abbreviation'=>"CA"),
array('name'=>"Colorado", 'label'=>"Colorado", 'abbreviation'=>"CO"),
array('name'=>"Connecticut", 'label'=>"Connecticut", 'abbreviation'=>"CT"),
array('name'=>"Delaware", 'label'=>"Delaware", 'abbreviation'=>"DE"),
array('name'=>"District of Columbia", 'label'=>"District of Columbia", 'abbreviation'=>"DC"),
array('name'=>"Federated States of Micronesia", 'label'=>"Federated States of Micronesia", 'abbreviation'=>"FM"),
array('name'=>"Florida", 'label'=>"Florida", 'abbreviation'=>"FL"),
array('name'=>"Georgia", 'label'=>"Georgia", 'abbreviation'=>"GA"),
array('name'=>"Guam", 'label'=>"Guam", 'abbreviation'=>"GU"),
array('name'=>"Hawaii", 'label'=>"Hawaii", 'abbreviation'=>"HI"),
array('name'=>"Idaho", 'label'=>"Idaho", 'abbreviation'=>"ID"),
array('name'=>"Illinois", 'label'=>"Illinois", 'abbreviation'=>"IL"),
array('name'=>"Indiana", 'label'=>"Indiana", 'abbreviation'=>"IN"),
array('name'=>"Iowa", 'label'=>"Iowa", 'abbreviation'=>"IA"),
array('name'=>"Kansas", 'label'=>"Kansas", 'abbreviation'=>"KS"),
array('name'=>"Kentucky", 'label'=>"Kentucky", 'abbreviation'=>"KY"),
array('name'=>"Louisiana", 'label'=>"Louisiana", 'abbreviation'=>"LA"),
array('name'=>"Maine", 'label'=>"Maine", 'abbreviation'=>"ME"),
array('name'=>"Marshall Islands", 'label'=>"Marshall Islands", 'abbreviation'=>"MH"),
array('name'=>"Maryland", 'label'=>"Maryland", 'abbreviation'=>"MD"),
array('name'=>"Massachusetts", 'label'=>"Massachusetts", 'abbreviation'=>"MA"),
array('name'=>"Michigan", 'label'=>"Michigan", 'abbreviation'=>"MI"),
array('name'=>"Minnesota", 'label'=>"Minnesota", 'abbreviation'=>"MN"),
array('name'=>"Mississippi", 'label'=>"Mississippi", 'abbreviation'=>"MS"),
array('name'=>"Missouri", 'label'=>"Missouri", 'abbreviation'=>"MO"),
array('name'=>"Montana", 'label'=>"Montana", 'abbreviation'=>"MT"),
array('name'=>"Nebraska", 'label'=>"Nebraska", 'abbreviation'=>"NE"),
array('name'=>"Nevada", 'label'=>"Nevada", 'abbreviation'=>"NV"),
array('name'=>"New Hampshire", 'label'=>"New Hampshire", 'abbreviation'=>"NH"),
array('name'=>"New Jersey", 'label'=>"New Jersey", 'abbreviation'=>"NJ"),
array('name'=>"New Mexico", 'label'=>"New Mexico", 'abbreviation'=>"NM"),
array('name'=>"New York", 'label'=>"New York", 'abbreviation'=>"NY"),
array('name'=>"North Carolina", 'label'=>"North Carolina", 'abbreviation'=>"NC"),
array('name'=>"North Dakota", 'label'=>"North Dakota", 'abbreviation'=>"ND"),
array('name'=>"Northern Mariana Islands", 'label'=>"Northern Mariana Islands", 'abbreviation'=>"MP"),
array('name'=>"Ohio", 'label'=>"Ohio", 'abbreviation'=>"OH"),
array('name'=>"Oklahoma", 'label'=>"Oklahoma", 'abbreviation'=>"OK"),
array('name'=>"Oregon", 'label'=>"Oregon", 'abbreviation'=>"OR"),
array('name'=>"Pennsylvania", 'label'=>"Pennsylvania", 'abbreviation'=>"PA"),
array('name'=>"Puerto Rico", 'label'=>"Puerto Rico", 'abbreviation'=>"PR"),
array('name'=>"Rhode Island", 'label'=>"Rhode Island", 'abbreviation'=>"RI"),
array('name'=>"South Carolina", 'label'=>"South Carolina", 'abbreviation'=>"SC"),
array('name'=>"South Dakota", 'label'=>"South Dakota", 'abbreviation'=>"SD"),
array('name'=>"Tennessee", 'label'=>"Tennessee", 'abbreviation'=>"TN"),
array('name'=>"Texas", 'label'=>"Texas", 'abbreviation'=>"TX"),
array('name'=>"Utah", 'label'=>"Utah", 'abbreviation'=>"UT"),
array('name'=>"Vermont", 'label'=>"Vermont", 'abbreviation'=>"VT"),
array('name'=> "Virgin Islands, U.S.", 'label'=>"Virgin Islands, U.S.", 'abbreviation'=>"VI"),
array('name'=>"Virginia", 'label'=>"Virginia", 'abbreviation'=>"VA"),
array('name'=>"Washington", 'label'=>"Washington", 'abbreviation'=>"WA"),
array('name'=>"West Virginia", 'label'=>"West Virginia", 'abbreviation'=>"WV"),
array('name'=>"Wisconsin", 'label'=>"Wisconsin", 'abbreviation'=>"WI"),
array('name'=>"Wyoming", 'label'=>"Wyoming", 'abbreviation'=>"WY"),
// array('id'=>, 'name'=>''),
);
 
$q = "";
if (array_key_exists("q", $_REQUEST)) {
$q = $_REQUEST['q'];
}
if (strlen($q) && $q[strlen($q)-1]=="*") {
$q = substr($q, 0, strlen($q)-1);
}
$ret = array();
foreach ($allItems as $item) {
if (!$q || strpos(strtolower($item['name']), strtolower($q))===0) {
$ret[] = $item;
}
}
 
// Handle paging, if given.
if (array_key_exists("start", $_REQUEST)) {
$ret = array_slice($ret, $_REQUEST['start']);
}
if (array_key_exists("count", $_REQUEST)) {
$ret = array_slice($ret, 0, $_REQUEST['count']);
}
 
print '/*'.json_encode(array('items'=>$ret)).'*/';
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books_isbnAttr2.xml
New file
0,0 → 1,23
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book isbn="ABC1">
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book isbn="ABC2">
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book isbn="ABC3">
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book isbn="ACB4">
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book isbn="ACF5">
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/module.js
New file
0,0 → 1,24
if(!dojo._hasResource["dojox.data.tests.module"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.module"] = true;
dojo.provide("dojox.data.tests.module");
 
try{
dojo.require("dojox.data.tests.stores.CsvStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.HtmlTableStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.OpmlStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.XmlStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.FlickrStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.FlickrRestStore");
//Load only if in a browser AND if the location is remote (not file. As it needs a PHP server to work).
if(dojo.isBrowser){
if(window.location.protocol !== "file:"){
dojo.require("dojox.data.tests.stores.QueryReadStore");
}
}
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.dom");
}catch(e){
doh.debug(e);
}
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/QueryReadStore.html
New file
0,0 → 1,221
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dijit/themes/tundra/tundra_rtl.css";
</style>
 
<title>Query read store</title>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript" src="../../../dojo/data/util/simpleFetch.js"></script>
<script type="text/javascript" src="../../../dojox/data/QueryReadStore.js"></script>
<script type="text/javascript">
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
 
dojo.provide("ComboBoxReadStore");
dojo.declare("ComboBoxReadStore", dojox.data.QueryReadStore, {
fetch:function(request) {
// Copy the GET/POST parameters (request.query) we need into
// request.serverQuery. We actually want to have
// the query added to the URL like so: /url.php?q=<searchString>
// The data in "queryOptions" are useless for our backend,
// we ignore them, they are not sent to the server.
// The combobox puts this into the request-parameter:
// {
// query: {name:<searchString>},
// queryOptions: {ignoreCase:true, deep:true},
// ...
// }
// We generate request.serverQuery to be this, since those values will
// be sent to the server.
// {
// q:<searchString>}
// }
// This results in a xhr request to the following URL (in case of GET):
// /url.php?q=<searchString>
//
 
request.serverQuery = {q:request.query.name};
// If we wanted to send the queryOptions too, we could simply do:
// request.serverQuery = {
// q:request.query.name,
// ignoreCase:request.queryOptions.ignoreCase,
// deep:request.queryOptions.deep
// };
// This would then result in this URL, for ignoreCase and deep
// assumed to be true:
// /url.php?q=<searchString>&ignoreCase=true&deep=true
return this.inherited("fetch", arguments);
}
});
 
dojo.provide("ServerPagingReadStore");
dojo.declare("ServerPagingReadStore", dojox.data.QueryReadStore, {
fetch:function(request) {
request.serverQuery = {q:request.query.name, start:request.start, count:request.count};
return this.inherited("fetch", arguments);
}
});
 
var testStore = new dojox.data.QueryReadStore({url:'stores/QueryReadStore.php'});;
function doSearch() {
var queryOptions = {};
if (dojo.byId("ignoreCaseEnabled").checked) {
queryOptions.ignoreCase = dojo.query("#fetchForm")[0].ignoreCase[0].checked;
}
if (dojo.byId("deepEnabled").checked) {
queryOptions.deep = dojo.query("#fetchForm")[0].deep[0].checked;
}
var query = {};
query.q = dojo.byId("searchText").value;
var request = {query:query, queryOptions:queryOptions};
request.start = parseInt(dojo.query("#fetchForm")[0].pagingStart.value);
request.count = parseInt(dojo.query("#fetchForm")[0].pagingCount.value);
 
var requestMethod = "get";
var radioButtons = dojo.query("#fetchForm")[0].requestMethod;
for (var i=0; i<radioButtons.length; i++){
if (radioButtons[i].checked) {
requestMethod = radioButtons[i].value;
}
}
testStore.requestMethod = requestMethod;
testStore.doClientPaging = dojo.query("#fetchForm")[0].doClientPaging.checked;
if (!testStore.doClientPaging) {
// We have to fill the serverQuery, since we also want to send the
// paging data "start" and "count" along with what is in query.
request.serverQuery = {q:request.query.q, start:request.start, count:request.count};
}
request.onComplete = function (items) {
var s = "number of items: "+items.length+"<br /><br />";
for (var i=0; i<items.length; i++) {
s += i+": name: '"+testStore.getValue(items[i], "name")+"'<br />";
}
//s += "<pre>"+dojo.toJson(items)+"</pre>";
dojo.byId("fetchOutput").innerHTML = s;
};
 
console.log(dojo.toJson(request));
testStore.fetch(request);
}
</script>
</head>
<body class="tundra" style="margin:20px;">
<div dojoType="ComboBoxReadStore" jsId="store" url="stores/QueryReadStore.php" requestMethod="get"></div>
This is a ComboBox: <input id="cb" dojoType="dijit.form.ComboBox" store="store" pageSize="5" />
<br /><br /><hr />
 
This is a FilteringSelect: <input id="fs" dojoType="dijit.form.FilteringSelect" store="store" pageSize="5" />
<br />
<form id="filteringSelectForm">
<input id="selectById" value="0" size="3" />
<input type="button" value="set by id" onclick="dijit.byId('fs').setValue(dojo.byId('selectById').value)" />
</form>
<br /><br /><hr />
 
This ComboBox uses a customized QueryReadStore, it prepares the query-string for the URL that
way that the paging parameters "start" and "count" are also send.<br />
<div dojoType="ServerPagingReadStore" jsId="serverPagingStore" url="stores/QueryReadStore.php" requestMethod="get" doClientPaging="false"></div>
<input dojoType="dijit.form.ComboBox" store="serverPagingStore" pageSize="5" />
<br />
<a href="javascript://" onclick="var d = dojo.byId('pagingCode'); d.style.display= d.style.display=='none'?'block':'none';">Click here to see the code!</a>
<div id="pagingCode" style="display:none;">
The HTML might look like this, the important attribute: <em>doClientPaging="false"</em> this takes care that the same query is fired to the server
and its not assumed that the client (the store) does the paging on the old data.
<pre>
&lt;div dojoType="ServerPagingReadStore" jsId="serverPagingStore" url="stores/QueryReadStore.php" requestMethod="get" doClientPaging="false"&gt;&lt;/div&gt;
&lt;input dojoType="dijit.form.ComboBox" store="serverPagingStore" pageSize="10" /&gt;
</pre>
<pre>
dojo.require("dojox.data.QueryReadStore");
dojo.provide("ServerPagingReadStore");
dojo.declare("ServerPagingReadStore", dojox.data.QueryReadStore, {
fetch:function(request) {
request.serverQuery = {q:request.query.name, start:request.start, count:request.count};
return this.inherited("fetch", arguments);
}
});
</pre>
</div>
<br /><br />
<hr />
<style>
fieldset {
border:1px solid black;
display:inline;
padding:10px;
}
div.disabled {
opacity:0.1;
}
</style>
<form id="fetchForm">
<fieldset title="requestMethod">
<legend>requestMethod</legend>
get <input type="radio" value="get" checked="checked" name="requestMethod" />
post <input type="radio" value="post" name="requestMethod" />
</fieldset>
<fieldset title="queryOptions">
<legend>queryOptions</legend>
 
<fieldset id="ignoreCaseFieldset">
<legend><input type="checkbox" id="ignoreCaseEnabled" /> ignoreCase</legend>
<div class="disabled">
true <input type="radio" value="0" checked="checked" name="ignoreCase" />
false <input type="radio" value="1" name="ignoreCase" />
</div>
</fieldset>
<fieldset id="deepFieldset">
<legend><input type="checkbox" id="deepEnabled" /> deep</legend>
<div class="disabled">
true <input type="radio" value="0" name="deep" />
false <input type="radio" value="1" name="deep" checked="checked" />
</div>
</fieldset>
</fieldset>
<fieldset title="paging">
<legend>paging</legend>
start: <input id="pagingStart" value="0" size="3" />
count: <input id="pagingCount" value="10" size="3" />
<br /><br />
do client paging: <input id="doClientPaging" type="checkbox" checked="checked" />
</fieldset>
<script>
var fieldsets = ["ignoreCaseFieldset", "deepFieldset"];
for (var i=0; i<fieldsets.length; i++) {
dojo.connect(dojo.byId(fieldsets[i]), "onchange", toggleFieldset);
}
function toggleFieldset(el) {
var divs = dojo.query("div", el.target.parentNode.parentNode);
if (divs.length) {
var div = divs[0];
if (el.target.checked) {
dojo.removeClass(div, "disabled");
} else {
dojo.addClass(div, "disabled");
}
}
}
</script>
<br /><br />
<input id="searchText" type="text" value="a">
<input id="searchButton" type="button" value="store.fetch()" onclick="doSearch()" />
</form>
<div id="fetchOutput" style="background-color:#FFDDDD; margin-top:1em; float:left;"></div>
</body>
</html>