| 1 |
dojo.provide("dojox.atom.tests.io.module"); |
| 2 |
dojo.require("dojox.atom.io.model"); |
| 3 |
dojo.require("dojox.atom.io.Connection"); |
| 4 |
dojo.require("dojox.data.dom"); |
| 5 |
dojo.require("dojo.date.stamp"); |
| 6 |
dojo.require("dojo.date"); |
| 7 |
|
| 8 |
doh.register("dojox.atom.tests.io.module", [ |
| 9 |
|
| 10 |
|
| 11 |
function checkCreateDate(t){ |
| 12 |
var node = document.createElement("div"); |
| 13 |
var knownDate = "2007-08-06T20:00:00-04:00"; |
| 14 |
var date = dojo.date.stamp.fromISOString(knownDate); |
| 15 |
|
| 16 |
|
| 17 |
node.innerHTML = " " + knownDate + " "; |
| 18 |
var dateWithSpaces = dojox.atom.io.model.util.createDate(node); |
| 19 |
|
| 20 |
var res = dojo.date.compare(dateWithSpaces, date); |
| 21 |
t.t(res === 0); |
| 22 |
}, |
| 23 |
|
| 24 |
|
| 25 |
function checkEscapeHTML(t){ |
| 26 |
var original = "<html><head><title>This is a \"Test Title\"</title></head><body class=\"tundra\">Woo hoo, this is an awesome & exciting test case!</body></html>"; |
| 27 |
var escaped = dojox.atom.io.model.util.escapeHtml(original); |
| 28 |
var expected = "<html><head><title>This is a "Test Title"</title></head><body class="tundra">Woo hoo, this is an awesome & exciting test case!</body></html>"; |
| 29 |
t.is(expected, escaped); |
| 30 |
}, |
| 31 |
|
| 32 |
|
| 33 |
function checkUnEscapeHtml(t){ |
| 34 |
var original = "<html><head><title>This is a "Test Title"</title></head><body class="tundra">Woo hoo, this is an awesome & exciting test case!</body></html>"; |
| 35 |
var unescaped = dojox.atom.io.model.util.unEscapeHtml(original); |
| 36 |
var expected = "<html><head><title>This is a \"Test Title\"</title></head><body class=\"tundra\">Woo hoo, this is an awesome & exciting test case!</body></html>"; |
| 37 |
t.is(expected, unescaped); |
| 38 |
t.is("<", dojox.atom.io.model.util.unEscapeHtml("&lt;")); |
| 39 |
}, |
| 40 |
|
| 41 |
|
| 42 |
function checkGetNodename(t){ |
| 43 |
var node = document.createElement("div"); |
| 44 |
t.is("div", dojox.atom.io.model.util.getNodename(node).toLowerCase()); |
| 45 |
|
| 46 |
node = dojox.data.dom.createDocument("<root><first/><second/><third/></root>").firstChild; |
| 47 |
t.is("root", dojox.atom.io.model.util.getNodename(node)); |
| 48 |
var n = node.firstChild; |
| 49 |
dojo.forEach(["first", "second", "third"], function(name){ |
| 50 |
t.is(name, dojox.atom.io.model.util.getNodename(n)); |
| 51 |
node.removeChild(n); |
| 52 |
n = node.firstChild; |
| 53 |
}); |
| 54 |
}, |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
{ |
| 60 |
name: "checkFeed", |
| 61 |
runTest: function(t){ |
| 62 |
var d = new doh.Deferred(); |
| 63 |
var atomio = new dojox.atom.io.Connection(); |
| 64 |
atomio.getFeed(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(feed){ |
| 65 |
var i; |
| 66 |
|
| 67 |
|
| 68 |
t.is('Example.com', feed.title.value); |
| 69 |
feed.setTitle('Example.com Atom Feed', 'text'); |
| 70 |
t.is('Example.com Atom Feed', feed.title.value); |
| 71 |
t.is('Example.com\'s Sample Feed', feed.subtitle.value); |
| 72 |
t.is('Copyright Example.com', feed.rights); |
| 73 |
t.is('http://example.com/samplefeed.xml', feed.id); |
| 74 |
t.is(dojo.date.stamp.fromISOString('2007-08-07T20:00:00-05:00'), feed.updated); |
| 75 |
|
| 76 |
|
| 77 |
feed.addNamespace('http://www.test.com'); |
| 78 |
t.is({}, feed.name_spaces); |
| 79 |
feed.addNamespace('', 'test'); |
| 80 |
t.is({}, feed.name_spaces); |
| 81 |
feed.addNamespace('http://www.test.com', 'test'); |
| 82 |
t.is({'test': 'http://www.test.com'}, feed.name_spaces); |
| 83 |
|
| 84 |
t.is(null, feed.authors); |
| 85 |
feed.addAuthor('John'); |
| 86 |
feed.addAuthor('Matt', '[email protected]'); |
| 87 |
feed.addAuthor('Joe', '[email protected]', 'http://joe.example.com'); |
| 88 |
t.t(dojo.isArray(feed.authors)); |
| 89 |
t.t(feed.authors.length === 3); |
| 90 |
|
| 91 |
t.is(null, feed.contributors); |
| 92 |
feed.addContributor('Sam'); |
| 93 |
feed.addContributor('Dave', '[email protected]'); |
| 94 |
feed.addContributor('Harry', '[email protected]', 'http://harry.example.com'); |
| 95 |
t.t(dojo.isArray(feed.contributors)); |
| 96 |
t.t(feed.contributors.length === 3); |
| 97 |
|
| 98 |
t.t(dojo.isArray(feed.links)); |
| 99 |
t.t(feed.links.length === 2); |
| 100 |
feed.removeLink('http://example.com/', 'alternate'); |
| 101 |
t.t(feed.links.length === 1); |
| 102 |
feed.addLink('http://www.example.com/', 'alternate', 'en', 'Example.com', 'text/html'); |
| 103 |
t.t(feed.links.length === 2); |
| 104 |
feed.addLink('http://test.example.com/', '', 'en', 'Example.com', 'text/html'); |
| 105 |
t.t(feed.links.length === 3); |
| 106 |
feed.removeBasicLinks(); |
| 107 |
t.t(feed.links.length === 2); |
| 108 |
|
| 109 |
t.is(null, feed.categories); |
| 110 |
feed.addCategory("scheme", "term", "label"); |
| 111 |
feed.addCategory("scheme", "term2", "label2"); |
| 112 |
feed.addCategory("scheme2", "term", "label"); |
| 113 |
t.t(dojo.isArray(feed.categories)); |
| 114 |
t.t(feed.categories.length === 3); |
| 115 |
var c = feed.getCategories("scheme"); |
| 116 |
t.t(c.length === 2); |
| 117 |
c = feed.getCategories("scheme2"); |
| 118 |
t.t(c.length === 1); |
| 119 |
feed.removeCategories("scheme", "term2"); |
| 120 |
t.t(feed.categories.length === 2); |
| 121 |
feed.removeCategories("scheme", "term"); |
| 122 |
t.t(feed.categories.length === 1); |
| 123 |
feed.removeCategories("scheme2", "term"); |
| 124 |
t.t(feed.categories.length === 0); |
| 125 |
|
| 126 |
t.is(null, feed.extensions); |
| 127 |
t.is([], feed.getExtensions()); |
| 128 |
feed.addExtension('nameSpace', 'element', [], 'A Test Element', 'sns'); |
| 129 |
feed.addExtension('nameSpace', 'element2', [], 'Another Test Element', 'sns'); |
| 130 |
feed.addExtension('anotherNameSpace', 'element', [], 'A Test Element', 'asns'); |
| 131 |
t.t(feed.extensions.length === 3); |
| 132 |
t.t(feed.getExtensions('nameSpace').length === 2); |
| 133 |
t.t(feed.getExtensions('nameSpace', 'element').length === 1); |
| 134 |
t.t(feed.getExtensions('anotherNameSpace', 'element').length === 1); |
| 135 |
t.t(feed.getExtensions('sns').length === 2); |
| 136 |
feed.removeExtensions('anotherNameSpace', 'element'); |
| 137 |
feed.removeExtensions('sns', 'element2'); |
| 138 |
t.t(feed.getExtensions('anotherNameSpace').length === 0); |
| 139 |
t.t(feed.getExtensions('sns').length === 1); |
| 140 |
|
| 141 |
|
| 142 |
t.t(feed.accept('title')); |
| 143 |
t.t(feed.accept('entry')); |
| 144 |
t.f(feed.accept('workspace')); |
| 145 |
|
| 146 |
var e = feed.getFirstEntry(); |
| 147 |
t.f(e === null); |
| 148 |
t.t(e.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 149 |
t.t(feed.entries.length === 6); |
| 150 |
feed.removeEntry(e); |
| 151 |
t.t(feed.entries.length === 5); |
| 152 |
t.t(feed.getEntry('http://example.com/samplefeed.xml/entry/1') === null); |
| 153 |
e = feed.getFirstEntry(); |
| 154 |
t.t(e.id === 'http://example.com/samplefeed.xml/entry/2'); |
| 155 |
e = feed.getEntry('http://example.com/samplefeed.xml/entry/4'); |
| 156 |
t.f(e === null); |
| 157 |
t.t(e.title.value === 'Test Entry #4'); |
| 158 |
e = new dojox.atom.io.model.Entry(); |
| 159 |
t.e(Error, feed, 'addEntry', [e]); |
| 160 |
t.t(feed.entries.length === 5); |
| 161 |
e.id = 'http://example.com/samplefeed.xml/newentry/1'; |
| 162 |
feed.addEntry(e); |
| 163 |
t.t(feed.entries.length === 6); |
| 164 |
var entries = []; |
| 165 |
for(i=2; i<5; i++){ |
| 166 |
e = new dojox.atom.io.model.Entry(); |
| 167 |
e.id = 'http://example.com/samplefeed.xml/newentry/'+i; |
| 168 |
entries.push(e); |
| 169 |
} |
| 170 |
feed.setEntries(entries); |
| 171 |
t.t(feed.entries.length === 9); |
| 172 |
|
| 173 |
e = feed.getSelfHref(); |
| 174 |
t.t(e === 'http://www.example.com/samplefeed.xml'); |
| 175 |
e = feed.createEntry(); |
| 176 |
t.t(e.feedUrl === 'http://www.example.com/samplefeed.xml'); |
| 177 |
|
| 178 |
|
| 179 |
for(i=2; i<7; i++){ |
| 180 |
e = feed.getEntry('http://example.com/samplefeed.xml/entry/'+i); |
| 181 |
feed.removeEntry(e); |
| 182 |
} |
| 183 |
t.t(feed.entries.length === 4); |
| 184 |
|
| 185 |
|
| 186 |
var isoString = dojo.date.stamp.toISOString(dojo.date.stamp.fromISOString('2007-08-07T20:00:00-05:00')); |
| 187 |
var str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:test=\"http://www.test.com\">\n<id>http://example.com/samplefeed.xml</id>\n<title type=\"text\" >Example.com Atom Feed</title>\n<rights>Copyright Example.com</rights>\n" |
| 188 |
str +="<updated>" + isoString + "</updated>\n<subtitle type=\"text\" >Example.com's Sample Feed</subtitle>\n<author>\n\t<name>John</name>\n</author>\n<author>\n\t<name>Matt</name>\n\t<email>[email protected]</email>\n</author>\n<author>\n\t<name>Joe</name>\n\t<email>[email protected]</email>\n\t<uri>http://joe.example.com</uri>\n</author>\n<contributor>\n\t<name>Sam</name>\n</contributor>\n<contributor>\n\t<name>Dave</name>\n\t<email>[email protected]</email>\n</contributor>\n<contributor>\n\t<name>Harry</name>\n\t<email>[email protected]</email>\n\t<uri>http://harry.example.com</uri>\n</contributor>\n<sns:element xmlns='nameSpace'>A Test Element</sns:element>\n<entry>\n<id>http://example.com/samplefeed.xml/newentry/1</id>\n</entry>\n<entry>\n<id>http://example.com/samplefeed.xml/newentry/2</id>\n</entry>\n<entry>\n<id>http://example.com/samplefeed.xml/newentry/3</id>\n</entry>\n<entry>\n<id>http://example.com/samplefeed.xml/newentry/4</id>\n</entry>\n</feed>"; |
| 189 |
t.t(feed.toString() == str); |
| 190 |
|
| 191 |
d.callback(true); |
| 192 |
}, function(e){ |
| 193 |
|
| 194 |
console.debug(e); |
| 195 |
d.errback("Feed fetching failed"); |
| 196 |
}); |
| 197 |
return d; |
| 198 |
} |
| 199 |
}, |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
{ |
| 204 |
name: "checkEntry", |
| 205 |
runTest: function(t){ |
| 206 |
var d = new doh.Deferred(); |
| 207 |
var atomio = new dojox.atom.io.Connection(); |
| 208 |
atomio.getFeed(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeedEdit.xml').toString(), function(feed){ |
| 209 |
t.is('Example.com', feed.title.value); |
| 210 |
var e = feed.createEntry(); |
| 211 |
var str = e.getEditHref(); |
| 212 |
t.t(str === null); |
| 213 |
|
| 214 |
e = feed.getFirstEntry(); |
| 215 |
str = e.getEditHref(); |
| 216 |
t.t(str === null); |
| 217 |
|
| 218 |
e = feed.getEntry('http://example.com/samplefeedEdit.xml/entry/10'); |
| 219 |
str = e.getEditHref(); |
| 220 |
t.t(str === 'http://example.com/samplefeedEdit.xml/entry/edit/10'); |
| 221 |
|
| 222 |
d.callback(true); |
| 223 |
}, function(){ |
| 224 |
|
| 225 |
d.errback("Feed fetching failed"); |
| 226 |
}); |
| 227 |
return d; |
| 228 |
} |
| 229 |
}, |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
{ |
| 234 |
name: "checkXmlEntry", |
| 235 |
runTest: function(t){ |
| 236 |
var d = new doh.Deferred(); |
| 237 |
var atomio = new dojox.atom.io.Connection(); |
| 238 |
atomio.getFeed(dojo.moduleUrl('dojox.atom.tests.io', 'sampleFeedXMLContent.xml'), function(feed){ |
| 239 |
try{ |
| 240 |
t.is('Example.com', feed.title.value); |
| 241 |
var e = feed.getFirstEntry(); |
| 242 |
t.t(e.title.value == "Test Entry #1"); |
| 243 |
var c = e.content.value; |
| 244 |
c = dojo.trim(c); |
| 245 |
t.t(c.indexOf("<rootNode ") === 0); |
| 246 |
d.callback(true); |
| 247 |
}catch(err){ |
| 248 |
d.errback(err); |
| 249 |
} |
| 250 |
}, function(){ |
| 251 |
|
| 252 |
d.errback("Feed fetching failed"); |
| 253 |
}); |
| 254 |
return d; |
| 255 |
} |
| 256 |
}, |
| 257 |
|
| 258 |
{ |
| 259 |
name: "checkEntry_preventCache", |
| 260 |
runTest: function(t){ |
| 261 |
var d = new doh.Deferred(); |
| 262 |
var atomio = new dojox.atom.io.Connection(false, true); |
| 263 |
atomio.getFeed(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeedEdit.xml').toString(), function(feed){ |
| 264 |
t.is('Example.com', feed.title.value); |
| 265 |
var e = feed.createEntry(); |
| 266 |
var str = e.getEditHref(); |
| 267 |
t.t(str === null); |
| 268 |
|
| 269 |
e = feed.getFirstEntry(); |
| 270 |
str = e.getEditHref(); |
| 271 |
t.t(str === null); |
| 272 |
|
| 273 |
e = feed.getEntry('http://example.com/samplefeedEdit.xml/entry/10'); |
| 274 |
str = e.getEditHref(); |
| 275 |
t.t(str === 'http://example.com/samplefeedEdit.xml/entry/edit/10'); |
| 276 |
|
| 277 |
d.callback(true); |
| 278 |
}, function(){ |
| 279 |
|
| 280 |
d.errback("Feed fetching failed"); |
| 281 |
}); |
| 282 |
return d; |
| 283 |
} |
| 284 |
}, |
| 285 |
|
| 286 |
|
| 287 |
{ |
| 288 |
name: "checkAtomIOGetFeedFail", |
| 289 |
runTest: function(t){ |
| 290 |
var d = new doh.Deferred(); |
| 291 |
var atomio = new dojox.atom.io.Connection(); |
| 292 |
atomio.getFeed(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefee.xml').toString(), function(feed){ |
| 293 |
d.errback("Feed fetching succeeded when it should've failed"); |
| 294 |
}, function(error, args){ |
| 295 |
|
| 296 |
t.t(error.name === 'Error'); |
| 297 |
t.t(error.status === 404); |
| 298 |
d.callback(true); |
| 299 |
}); |
| 300 |
return d; |
| 301 |
} |
| 302 |
},{ |
| 303 |
name: "checkAtomIOGetFeedSuccess", |
| 304 |
runTest: function(t){ |
| 305 |
var d = new doh.Deferred(); |
| 306 |
var atomio = new dojox.atom.io.Connection(); |
| 307 |
atomio.getFeed(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(feed){ |
| 308 |
|
| 309 |
t.t(feed.title.value === 'Example.com'); |
| 310 |
d.callback(true); |
| 311 |
}, function(error, args){ |
| 312 |
|
| 313 |
d.errback("Feed fetching failed"); |
| 314 |
}); |
| 315 |
return d; |
| 316 |
} |
| 317 |
},{ |
| 318 |
name: "checkAtomIOGetEntryFail", |
| 319 |
runTest: function(t){ |
| 320 |
var d = new doh.Deferred(); |
| 321 |
var atomio = new dojox.atom.io.Connection(); |
| 322 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.io', 'sampleEntr.xml').toString(), function(entry){ |
| 323 |
d.errback("Feed fetching succeeded when it should've failed"); |
| 324 |
}, function(error, args){ |
| 325 |
|
| 326 |
t.t(error.name === 'Error'); |
| 327 |
t.t(error.status === 404); |
| 328 |
d.callback(true); |
| 329 |
}); |
| 330 |
return d; |
| 331 |
} |
| 332 |
},{ |
| 333 |
name: "checkAtomIOGetEntrySuccess", |
| 334 |
runTest: function(t){ |
| 335 |
var d = new doh.Deferred(); |
| 336 |
var atomio = new dojox.atom.io.Connection(); |
| 337 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.io', 'sampleEntry.xml').toString(), function(entry){ |
| 338 |
t.t(entry.title.value === 'Test Entry #1'); |
| 339 |
t.t(entry.id === 'http://example.com/sampleEntry.xml/entry/1'); |
| 340 |
d.callback(true); |
| 341 |
}, function(error, args){ |
| 342 |
|
| 343 |
d.errback("Feed fetching failed"); |
| 344 |
}); |
| 345 |
return d; |
| 346 |
} |
| 347 |
},{ |
| 348 |
name: "checkAtomIOGetEntryFeedSuccess", |
| 349 |
runTest: function(t){ |
| 350 |
var d = new doh.Deferred(); |
| 351 |
var atomio = new dojox.atom.io.Connection(); |
| 352 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(entry){ |
| 353 |
|
| 354 |
t.t(entry.title.value === 'Test Entry #1'); |
| 355 |
t.t(entry.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 356 |
d.callback(true); |
| 357 |
}, function(error, args){ |
| 358 |
|
| 359 |
d.errback("Feed fetching failed"); |
| 360 |
}); |
| 361 |
return d; |
| 362 |
} |
| 363 |
},{ |
| 364 |
name: "checkGetService", |
| 365 |
runTest: function(t){ |
| 366 |
var d = new doh.Deferred(); |
| 367 |
var atomio = new dojox.atom.io.Connection(); |
| 368 |
atomio.getService(dojo.moduleUrl('dojox.atom.tests.io', 'service.xml').toString(), function(service, domNode){ |
| 369 |
var collection = service.getCollection("http://example.com/feed"); |
| 370 |
t.t(collection[0].href === 'http://example.com/feed'); |
| 371 |
t.t(collection[0].title === 'Test Collection'); |
| 372 |
d.callback(true); |
| 373 |
}, function(error, args){ |
| 374 |
|
| 375 |
d.errback("Service fetching failed"); |
| 376 |
}); |
| 377 |
return d; |
| 378 |
} |
| 379 |
},{ |
| 380 |
name: "checkAtomIOUpdateEntrySuccess", |
| 381 |
timeout: 5000, |
| 382 |
runTest: function(t){ |
| 383 |
var d = new doh.Deferred(); |
| 384 |
var atomio = new dojox.atom.io.Connection(); |
| 385 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(entry){ |
| 386 |
|
| 387 |
t.t(entry.title.value === 'Test Entry #1'); |
| 388 |
t.t(entry.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 389 |
entry.setEditHref(dojo.moduleUrl('dojox.atom.tests.io', 'app.php')); |
| 390 |
entry.setTitle('<h1>New Editable Title!</h1>', 'xhtml'); |
| 391 |
atomio.updateEntry(entry, function(e, dom, args){ |
| 392 |
t.t(e.title.value === '<h1>New Editable Title!</h1>'); |
| 393 |
t.t(e.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 394 |
d.callback(true); |
| 395 |
}, function(error, args){ |
| 396 |
d.errback("Updating entry failed"); |
| 397 |
}); |
| 398 |
}, function(error, args){ |
| 399 |
|
| 400 |
d.errback("Feed fetching failed"); |
| 401 |
}); |
| 402 |
return d; |
| 403 |
} |
| 404 |
},{ |
| 405 |
name: "checkAtomIOUpdateEntryFail", |
| 406 |
timeout: 5000, |
| 407 |
runTest: function(t){ |
| 408 |
var d = new doh.Deferred(); |
| 409 |
var atomio = new dojox.atom.io.Connection(); |
| 410 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(entry){ |
| 411 |
|
| 412 |
t.t(entry.title.value === 'Test Entry #1'); |
| 413 |
t.t(entry.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 414 |
entry.setEditHref(dojo.moduleUrl('dojox.atom.tests.io', 'appFail.php')); |
| 415 |
entry.setTitle('<h1>New Editable Title!</h1>', 'xhtml'); |
| 416 |
atomio.updateEntry(entry, function(e, dom, args){ |
| 417 |
d.errback("Updating entry succeeded"); |
| 418 |
}, function(error, args){ |
| 419 |
d.callback(true); |
| 420 |
}); |
| 421 |
}, function(error, args){ |
| 422 |
|
| 423 |
d.errback("Updating entry failed."); |
| 424 |
}); |
| 425 |
return d; |
| 426 |
} |
| 427 |
},{ |
| 428 |
name: "checkAtomIOAddEntrySuccess", |
| 429 |
timeout: 5000, |
| 430 |
runTest: function(t){ |
| 431 |
var d = new doh.Deferred(); |
| 432 |
var entry = new dojox.atom.io.model.Entry(); |
| 433 |
entry.setTitle('Test Editable Entry #1', 'text'); |
| 434 |
entry.addAuthor('Test Person', '[email protected]'); |
| 435 |
entry.content = new dojox.atom.io.model.Content('content', 'This is the content of my test new entry!', null, 'text'); |
| 436 |
var atomio = new dojox.atom.io.Connection(); |
| 437 |
atomio.addEntry(entry, dojo.moduleUrl('dojox.atom.tests.io', 'app.php').toString(), function(entry, url){ |
| 438 |
t.t(entry.title.value === 'Test Editable Entry #1'); |
| 439 |
t.t(url === 'http://example.com/samplefeed.xml/entry/10'); |
| 440 |
d.callback(true); |
| 441 |
}, function(error, args){ |
| 442 |
|
| 443 |
d.errback("Adding entry failed."); |
| 444 |
}); |
| 445 |
return d; |
| 446 |
} |
| 447 |
},{ |
| 448 |
name: "checkAtomIOAddEntryFail", |
| 449 |
timeout: 5000, |
| 450 |
runTest: function(t){ |
| 451 |
var d = new doh.Deferred(); |
| 452 |
var entry = new dojox.atom.io.model.Entry(); |
| 453 |
|
| 454 |
entry.content = new dojox.atom.io.model.Content('content', 'This is the content of my test new entry!', null, 'text'); |
| 455 |
var atomio = new dojox.atom.io.Connection(); |
| 456 |
atomio.addEntry(entry, dojo.moduleUrl('dojox.atom.tests.io', 'appFail.php').toString(), function(entry, url){ |
| 457 |
|
| 458 |
d.errback("Adding entry succeeded when it shouldn't!"); |
| 459 |
}, function(error, args){ |
| 460 |
d.callback(true); |
| 461 |
}); |
| 462 |
return d; |
| 463 |
} |
| 464 |
},{ |
| 465 |
name: "checkAtomIODeleteEntrySuccess", |
| 466 |
timeout: 5000, |
| 467 |
runTest: function(t){ |
| 468 |
var d = new doh.Deferred(); |
| 469 |
var atomio = new dojox.atom.io.Connection(); |
| 470 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(entry){ |
| 471 |
|
| 472 |
t.t(entry.title.value === 'Test Entry #1'); |
| 473 |
t.t(entry.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 474 |
entry.setEditHref(dojo.moduleUrl('dojox.atom.tests.io', 'app.php')); |
| 475 |
atomio.deleteEntry(entry, function(result){ |
| 476 |
if (result) { |
| 477 |
d.callback(true); |
| 478 |
}else{ |
| 479 |
d.errback("Deleting entry failed"); |
| 480 |
} |
| 481 |
}, function(error, args){ |
| 482 |
d.errback("Deleting entry failed"); |
| 483 |
}); |
| 484 |
}, function(error, args){ |
| 485 |
|
| 486 |
d.errback("Retrieving the entry failed."); |
| 487 |
}); |
| 488 |
return d; |
| 489 |
} |
| 490 |
},{ |
| 491 |
name: "checkAtomIODeleteEntryFail", |
| 492 |
timeout: 5000, |
| 493 |
runTest: function(t){ |
| 494 |
var d = new doh.Deferred(); |
| 495 |
var atomio = new dojox.atom.io.Connection(); |
| 496 |
atomio.getEntry(dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeed.xml').toString(), function(entry){ |
| 497 |
|
| 498 |
t.t(entry.title.value === 'Test Entry #1'); |
| 499 |
t.t(entry.id === 'http://example.com/samplefeed.xml/entry/1'); |
| 500 |
entry.setEditHref(dojo.moduleUrl('dojox.atom.tests.io', 'appFail.php')); |
| 501 |
atomio.deleteEntry(entry, function(result){ |
| 502 |
if (result) { |
| 503 |
d.errback("Deleting entry succeeded but it shouldn't have"); |
| 504 |
}else{ |
| 505 |
d.errback("The callback was called but it shouldn't have"); |
| 506 |
} |
| 507 |
}, function(error, args){ |
| 508 |
d.callback(true); |
| 509 |
}); |
| 510 |
}, function(error, args){ |
| 511 |
|
| 512 |
d.errback("Retrieving the entry failed."); |
| 513 |
}); |
| 514 |
return d; |
| 515 |
} |
| 516 |
} |
| 517 |
]); |