1 | <html> |
---|
2 | <head> |
---|
3 | <script src="../OLLoader.js"></script> |
---|
4 | <script type="text/javascript"> |
---|
5 | |
---|
6 | function test_constructor(t) { |
---|
7 | t.plan(4); |
---|
8 | var options = {'foo': 'bar'}; |
---|
9 | var format = new OpenLayers.Format.Atom(options); |
---|
10 | t.ok(format instanceof OpenLayers.Format.Atom, |
---|
11 | "new OpenLayers.Format.GeoRSS returns object" ); |
---|
12 | t.eq(format.foo, "bar", "constructor sets options correctly"); |
---|
13 | t.eq(typeof format.read, "function", "format has a read function"); |
---|
14 | t.eq(typeof format.write, "function", "format has a write function"); |
---|
15 | } |
---|
16 | |
---|
17 | /* Reading tests */ |
---|
18 | |
---|
19 | function test_reproject_null(t) { |
---|
20 | t.plan(1); |
---|
21 | var parser = new OpenLayers.Format.Atom({'internalProjection':new OpenLayers.Projection("EPSG:4326"), 'externalProjection': new OpenLayers.Projection("EPSG:4326")}); |
---|
22 | var data = parser.read( |
---|
23 | // begin document |
---|
24 | '<feed xmlns="http://www.w3.org/2005/Atom">' + |
---|
25 | '<entry></entry>' + |
---|
26 | '</feed>' |
---|
27 | // end document |
---|
28 | ); |
---|
29 | t.eq( |
---|
30 | data.length, 1, |
---|
31 | "Parsing items with null geometry and reprojection doesn't fail" |
---|
32 | ); |
---|
33 | } |
---|
34 | |
---|
35 | // read entry 1: basic entry, no categories or persons |
---|
36 | function test_readentry1(t) { |
---|
37 | t.plan(10); |
---|
38 | var parser = new OpenLayers.Format.Atom(); |
---|
39 | var data = parser.read( |
---|
40 | // begin document |
---|
41 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
42 | ' <id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
43 | ' <link href="http://example.com/blog/1" rel="alternate"/>' + |
---|
44 | ' <summary>An Atom testing entry</summary>' + |
---|
45 | ' <title>Atom test</title>' + |
---|
46 | ' <updated>2009-06-02T10:00:00Z</updated>' + |
---|
47 | '</entry>' |
---|
48 | // end document |
---|
49 | ); |
---|
50 | t.ok(data instanceof Array, "Read features"); |
---|
51 | var fx = data[0]; |
---|
52 | t.ok(fx instanceof OpenLayers.Feature.Vector, "Read feature"); |
---|
53 | t.eq(fx.geometry, null, "Geometry is null"); |
---|
54 | t.eq( |
---|
55 | fx.fid, |
---|
56 | "urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed", |
---|
57 | "Read fid" |
---|
58 | ); |
---|
59 | var attrib = fx.attributes; |
---|
60 | t.eq(attrib.title, "Atom test", "Correct title attribute"); |
---|
61 | t.eq( |
---|
62 | attrib.description, |
---|
63 | "An Atom testing entry", |
---|
64 | "Correct description attribute" |
---|
65 | ); |
---|
66 | var atomAttrib = attrib.atom; |
---|
67 | t.eq( |
---|
68 | atomAttrib.links, |
---|
69 | [{href: "http://example.com/blog/1", rel: "alternate"}], |
---|
70 | "Correct links in atom namespace" |
---|
71 | ); |
---|
72 | t.eq( |
---|
73 | atomAttrib.summary, |
---|
74 | "An Atom testing entry", |
---|
75 | "Correct summary in atom namespace" |
---|
76 | ); |
---|
77 | t.eq( |
---|
78 | atomAttrib.title, |
---|
79 | "Atom test", |
---|
80 | "Correct title in atom namespace" |
---|
81 | ); |
---|
82 | t.eq( |
---|
83 | atomAttrib.updated, |
---|
84 | "2009-06-02T10:00:00Z", |
---|
85 | "Correct timestamp in atom namespace" |
---|
86 | ); |
---|
87 | } |
---|
88 | |
---|
89 | // read entry 2: with georss:where |
---|
90 | function test_readentry2(t) { |
---|
91 | t.plan(5); |
---|
92 | var parser = new OpenLayers.Format.Atom(); |
---|
93 | var data = parser.read( |
---|
94 | // begin document |
---|
95 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
96 | ' <id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
97 | ' <georss:where xmlns:georss="http://www.georss.org/georss">' + |
---|
98 | ' <gml:Point xmlns:gml="http://www.opengis.net/gml">' + |
---|
99 | ' <gml:pos>45.68 -111.04</gml:pos>' + |
---|
100 | ' </gml:Point>' + |
---|
101 | ' </georss:where>' + |
---|
102 | '</entry>' |
---|
103 | // end document |
---|
104 | ); |
---|
105 | t.ok(data instanceof Array, "Read features"); |
---|
106 | var fx = data[0]; |
---|
107 | t.ok(fx instanceof OpenLayers.Feature.Vector, "Read feature"); |
---|
108 | t.ok(fx.geometry instanceof OpenLayers.Geometry.Point, "Read geometry"); |
---|
109 | t.eq(fx.geometry.x, -111.04, "Read x"); |
---|
110 | t.eq(fx.geometry.y, 45.68, "Read y"); |
---|
111 | } |
---|
112 | |
---|
113 | // read entry 3: with georss:point |
---|
114 | function test_readentry3(t) { |
---|
115 | t.plan(5); |
---|
116 | var parser = new OpenLayers.Format.Atom(); |
---|
117 | var data = parser.read( |
---|
118 | // begin document |
---|
119 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
120 | ' <id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
121 | ' <georss:point xmlns:georss="http://www.georss.org/georss">45.68 -111.04</georss:point>' + |
---|
122 | '</entry>' |
---|
123 | // end document |
---|
124 | ); |
---|
125 | t.ok(data instanceof Array, "Read features"); |
---|
126 | var fx = data[0]; |
---|
127 | t.ok(fx instanceof OpenLayers.Feature.Vector, "Read feature"); |
---|
128 | t.ok(fx.geometry instanceof OpenLayers.Geometry.Point, "Read geometry"); |
---|
129 | t.eq(fx.geometry.x, -111.04, "Read x"); |
---|
130 | t.eq(fx.geometry.y, 45.68, "Read y"); |
---|
131 | } |
---|
132 | |
---|
133 | // read entry 4: basic entry, text content |
---|
134 | function test_readentry4(t) { |
---|
135 | t.plan(3); |
---|
136 | var parser = new OpenLayers.Format.Atom(); |
---|
137 | var data = parser.read( |
---|
138 | // begin document |
---|
139 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
140 | ' <id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
141 | ' <link href="http://example.com/blog/1" rel="alternate"/>' + |
---|
142 | ' <summary>An Atom testing entry</summary>' + |
---|
143 | ' <title>Atom test</title>' + |
---|
144 | ' <updated>2009-06-02T10:00:00Z</updated>' + |
---|
145 | ' <content type="text">Blah, blah, blah</content>' + |
---|
146 | '</entry>' |
---|
147 | // end document |
---|
148 | ); |
---|
149 | t.ok(data instanceof Array, "Read features"); |
---|
150 | var fx = data[0]; |
---|
151 | var attrib = fx.attributes; |
---|
152 | var atomAttrib = attrib.atom; |
---|
153 | t.eq( |
---|
154 | atomAttrib.content.type, |
---|
155 | "text", |
---|
156 | "Correct content.type in atom namespace" |
---|
157 | ); |
---|
158 | t.eq( |
---|
159 | atomAttrib.content.value, |
---|
160 | "Blah, blah, blah", |
---|
161 | "Correct content.value in atom namespace" |
---|
162 | ); |
---|
163 | } |
---|
164 | |
---|
165 | // read entry 5: basic entry, KML content |
---|
166 | function test_readentry5(t) { |
---|
167 | t.plan(3); |
---|
168 | var parser = new OpenLayers.Format.Atom(); |
---|
169 | var data = parser.read( |
---|
170 | // begin document |
---|
171 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
172 | ' <id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
173 | ' <link href="http://example.com/blog/1" rel="alternate"/>' + |
---|
174 | ' <summary>An Atom testing entry</summary>' + |
---|
175 | ' <title>Atom test</title>' + |
---|
176 | ' <updated>2009-06-02T10:00:00Z</updated>' + |
---|
177 | ' <content type="application/vnd.google-earth.kml+xml"><kml xmlns="http://earth.google.com/kml/2.0"><Folder><name>A folder</name><description>It\'s a folder</description></Folder></kml></content>' + |
---|
178 | '</entry>' |
---|
179 | // end document |
---|
180 | ); |
---|
181 | t.ok(data instanceof Array, "Read features"); |
---|
182 | var fx = data[0]; |
---|
183 | var attrib = fx.attributes; |
---|
184 | var atomAttrib = attrib.atom; |
---|
185 | t.eq( |
---|
186 | atomAttrib.content.type, |
---|
187 | "application/vnd.google-earth.kml+xml", |
---|
188 | "Correct content.type in atom namespace" |
---|
189 | ); |
---|
190 | var node = atomAttrib.content.value; |
---|
191 | var name = node.localName || node.nodeName.split(":").pop(); |
---|
192 | t.eq( |
---|
193 | name, |
---|
194 | "kml", |
---|
195 | "Correct content.value in atom namespace" |
---|
196 | ); |
---|
197 | } |
---|
198 | |
---|
199 | // read feed 1 |
---|
200 | function test_readfeed1(t) { |
---|
201 | t.plan(2); |
---|
202 | var parser = new OpenLayers.Format.Atom(); |
---|
203 | var data = parser.read( |
---|
204 | // begin document |
---|
205 | '<feed xmlns="http://www.w3.org/2005/Atom">' + |
---|
206 | ' <entry>' + |
---|
207 | ' <id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
208 | ' </entry>' + |
---|
209 | '</feed>' |
---|
210 | // end document |
---|
211 | ); |
---|
212 | t.ok(data instanceof Array, "Read features"); |
---|
213 | var fx = data[0]; |
---|
214 | t.ok(fx instanceof OpenLayers.Feature.Vector, "Read feature"); |
---|
215 | } |
---|
216 | |
---|
217 | /* Writing tests */ |
---|
218 | |
---|
219 | // write entry 1: null geometry, no attributes |
---|
220 | function test_writeentry1(t) { |
---|
221 | t.plan(1); |
---|
222 | var writer = new OpenLayers.Format.Atom(); |
---|
223 | var feature = new OpenLayers.Feature.Vector(null, {}); |
---|
224 | feature.fid = '1'; |
---|
225 | var data = writer.write(feature); |
---|
226 | t.xml_eq( |
---|
227 | data, |
---|
228 | // begin document |
---|
229 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
230 | '<id>1</id>' + |
---|
231 | '<title>untitled</title>' + |
---|
232 | '</entry>', |
---|
233 | // end document |
---|
234 | 'Writes an entry doc with id, no attributes' |
---|
235 | ); |
---|
236 | } |
---|
237 | |
---|
238 | // write entry 2: null geometry, well-known attributes |
---|
239 | function test_writeentry2(t) { |
---|
240 | t.plan(1); |
---|
241 | var writer = new OpenLayers.Format.Atom(); |
---|
242 | var feature = new OpenLayers.Feature.Vector(null, {title: "Test", description: "A testing feature"}); |
---|
243 | feature.fid = '1'; |
---|
244 | var data = writer.write(feature); |
---|
245 | t.xml_eq( |
---|
246 | data, |
---|
247 | // begin document |
---|
248 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
249 | '<id>1</id>' + |
---|
250 | '<summary>A testing feature</summary>' + |
---|
251 | '<title>Test</title>' + |
---|
252 | '</entry>', |
---|
253 | // end document |
---|
254 | 'Writes an entry doc with id, well-known attributes' |
---|
255 | ); |
---|
256 | } |
---|
257 | |
---|
258 | // write entry 3: null geometry, Atom constructs to override |
---|
259 | // well-known attributes |
---|
260 | function test_writeentry3(t) { |
---|
261 | t.plan(1); |
---|
262 | var writer = new OpenLayers.Format.Atom(); |
---|
263 | var feature = new OpenLayers.Feature.Vector(null, {title: "Test", description: "A testing feature", atom: {title: "Atom test", summary: "An Atom testing feature", updated: "2009-06-02T10:00:00Z"}}); |
---|
264 | feature.fid = '1'; |
---|
265 | var data = writer.write(feature); |
---|
266 | t.xml_eq( |
---|
267 | data, |
---|
268 | // begin document |
---|
269 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
270 | '<id>1</id>' + |
---|
271 | '<summary>An Atom testing feature</summary>' + |
---|
272 | '<title>Atom test</title>' + |
---|
273 | '<updated>2009-06-02T10:00:00Z</updated>' + |
---|
274 | '</entry>', |
---|
275 | // end document |
---|
276 | 'Writes an entry doc with Atom constructs overriding well-known atts' |
---|
277 | ); |
---|
278 | } |
---|
279 | |
---|
280 | // write entry 4: Atom categories |
---|
281 | function test_writeentry4(t) { |
---|
282 | t.plan(1); |
---|
283 | var writer = new OpenLayers.Format.Atom(); |
---|
284 | var feature = new OpenLayers.Feature.Vector(null, {title: "Test", description: "A testing feature", atom: {title: "Atom test", summary: "An Atom testing feature", updated: "2009-06-02T10:00:00Z", categories: [{term: "blog", scheme: "http://example.com/terms", label: "A blog post"}]}}); |
---|
285 | feature.fid = '1'; |
---|
286 | var data = writer.write(feature); |
---|
287 | t.xml_eq( |
---|
288 | data, |
---|
289 | // begin document |
---|
290 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
291 | '<category term="blog" scheme="http://example.com/terms" label="A blog post"/>' + |
---|
292 | '<id>1</id>' + |
---|
293 | '<summary>An Atom testing feature</summary>' + |
---|
294 | '<title>Atom test</title>' + |
---|
295 | '<updated>2009-06-02T10:00:00Z</updated>' + |
---|
296 | '</entry>', |
---|
297 | // end document |
---|
298 | 'Writes an entry doc with Atom constructs and categories' |
---|
299 | ); |
---|
300 | } |
---|
301 | |
---|
302 | // write entry 5: Atom authors, contributors |
---|
303 | function test_writeentry5(t) { |
---|
304 | t.plan(1); |
---|
305 | var writer = new OpenLayers.Format.Atom(); |
---|
306 | var feature = new OpenLayers.Feature.Vector(null, {title: "Test", description: "A testing feature", atom: {title: "Atom test", summary: "An Atom testing feature", updated: "2009-06-02T10:00:00Z", authors: [{name: "John Doe", uri: "http://example.com/people/jdoe", email: "jdoe@example.com"}], contributors: [{name: "Pikov Andropov", uri: "http://example.com/people/pandropov", email: "pandropov@example.com"}]}}); |
---|
307 | feature.fid = '1'; |
---|
308 | var data = writer.write(feature); |
---|
309 | t.xml_eq( |
---|
310 | data, |
---|
311 | // begin document |
---|
312 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
313 | '<author>' + |
---|
314 | ' <name>John Doe</name>' + |
---|
315 | ' <uri>http://example.com/people/jdoe</uri>' + |
---|
316 | ' <email>jdoe@example.com</email>' + |
---|
317 | '</author>' + |
---|
318 | '<contributor>' + |
---|
319 | ' <name>Pikov Andropov</name>' + |
---|
320 | ' <uri>http://example.com/people/pandropov</uri>' + |
---|
321 | ' <email>pandropov@example.com</email>' + |
---|
322 | '</contributor>' + |
---|
323 | '<id>1</id>' + |
---|
324 | '<summary>An Atom testing feature</summary>' + |
---|
325 | '<title>Atom test</title>' + |
---|
326 | '<updated>2009-06-02T10:00:00Z</updated>' + |
---|
327 | '</entry>', |
---|
328 | // end document |
---|
329 | 'Writes an entry doc with Atom constructs and persons' |
---|
330 | ); |
---|
331 | } |
---|
332 | |
---|
333 | // write entry 6: Atom links |
---|
334 | function test_writeentry6(t) { |
---|
335 | t.plan(1); |
---|
336 | |
---|
337 | // Feature attributes in Atom namespace |
---|
338 | var atomAttrib = { |
---|
339 | title: "Atom test", |
---|
340 | summary: "An Atom testing feature", |
---|
341 | updated: "2009-06-02T10:00:00Z", |
---|
342 | links: [ |
---|
343 | { href: "http://example.com/blog/1", rel: "alternate" } |
---|
344 | ] |
---|
345 | }; |
---|
346 | var fx = new OpenLayers.Feature.Vector(null, {atom: atomAttrib}); |
---|
347 | fx.fid = 'urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed'; |
---|
348 | |
---|
349 | var writer = new OpenLayers.Format.Atom(); |
---|
350 | var data = writer.write(fx); |
---|
351 | |
---|
352 | t.xml_eq( |
---|
353 | data, |
---|
354 | // begin document |
---|
355 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
356 | '<id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
357 | '<link href="http://example.com/blog/1" rel="alternate"/>' + |
---|
358 | '<summary>An Atom testing feature</summary>' + |
---|
359 | '<title>Atom test</title>' + |
---|
360 | '<updated>2009-06-02T10:00:00Z</updated>' + |
---|
361 | '</entry>', |
---|
362 | // end document |
---|
363 | 'Writes an entry doc with Atom constructs and links' |
---|
364 | ); |
---|
365 | } |
---|
366 | |
---|
367 | // write out point -- just enough to see that we're getting the |
---|
368 | // georss:where element with a Point. We'll trust GML.v3 to get the |
---|
369 | // details right. |
---|
370 | function test_writepoint(t) { |
---|
371 | t.plan(1); |
---|
372 | |
---|
373 | var point = new OpenLayers.Geometry.Point(-111.04, 45.68); |
---|
374 | var fx = new OpenLayers.Feature.Vector(point, {}); |
---|
375 | fx.fid = 'urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed'; |
---|
376 | |
---|
377 | var writer = new OpenLayers.Format.Atom(); |
---|
378 | var data = writer.write(fx); |
---|
379 | |
---|
380 | t.xml_eq( |
---|
381 | data, |
---|
382 | // begin document |
---|
383 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
384 | '<id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + |
---|
385 | '<title>untitled</title>' + |
---|
386 | '<georss:where xmlns:georss="http://www.georss.org/georss">' + |
---|
387 | ' <gml:Point xmlns:gml="http://www.opengis.net/gml">' + |
---|
388 | ' <gml:pos>45.68 -111.04</gml:pos>' + |
---|
389 | ' </gml:Point>' + |
---|
390 | '</georss:where>' + |
---|
391 | '</entry>', |
---|
392 | // end document |
---|
393 | 'Writes an entry doc with a point location' |
---|
394 | ); |
---|
395 | } |
---|
396 | |
---|
397 | // write entry 7: text type content |
---|
398 | function test_writeentry7(t) { |
---|
399 | t.plan(1); |
---|
400 | var writer = new OpenLayers.Format.Atom(); |
---|
401 | var feature = new OpenLayers.Feature.Vector(null, {title: "Test", description: "A testing feature", atom: {title: "Atom test", summary: "An Atom testing feature", updated: "2009-06-02T10:00:00Z", content: {type: "text", value: "Blah, blah, blah"}}}); |
---|
402 | feature.fid = '1'; |
---|
403 | var data = writer.write(feature); |
---|
404 | t.xml_eq( |
---|
405 | data, |
---|
406 | // begin document |
---|
407 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
408 | '<content type="text">Blah, blah, blah</content>' + |
---|
409 | '<id>1</id>' + |
---|
410 | '<summary>An Atom testing feature</summary>' + |
---|
411 | '<title>Atom test</title>' + |
---|
412 | '<updated>2009-06-02T10:00:00Z</updated>' + |
---|
413 | '</entry>', |
---|
414 | // end document |
---|
415 | 'Writes an entry doc with Atom constructs overriding well-known atts' |
---|
416 | ); |
---|
417 | } |
---|
418 | |
---|
419 | // write entry 8: +xml type content |
---|
420 | function test_writeentry8(t) { |
---|
421 | t.plan(1); |
---|
422 | var kml = new OpenLayers.Format.KML(); |
---|
423 | kml.foldersName = "A folder"; |
---|
424 | kml.foldersDesc = "It's a folder"; |
---|
425 | var kmlDoc = kml.createElementNS(kml.kmlns, "kml"); |
---|
426 | var kmlFolder = kml.createFolderXML(); |
---|
427 | kmlDoc.appendChild(kmlFolder); |
---|
428 | var writer = new OpenLayers.Format.Atom(); |
---|
429 | var feature = new OpenLayers.Feature.Vector(null, {title: "Test", description: "A testing feature", atom: {title: "Atom test", summary: "An Atom testing feature", updated: "2009-06-02T10:00:00Z", content: {type: "application/vnd.google-earth.kml+xml", value: kmlDoc}}}); |
---|
430 | feature.fid = '1'; |
---|
431 | var data = writer.write(feature); |
---|
432 | t.xml_eq( |
---|
433 | data, |
---|
434 | // begin document |
---|
435 | '<entry xmlns="http://www.w3.org/2005/Atom">' + |
---|
436 | '<content type="application/vnd.google-earth.kml+xml"><kml xmlns="http://earth.google.com/kml/2.0"><Folder><name>A folder</name><description>It\'s a folder</description></Folder></kml></content>' + |
---|
437 | '<id>1</id>' + |
---|
438 | '<summary>An Atom testing feature</summary>' + |
---|
439 | '<title>Atom test</title>' + |
---|
440 | '<updated>2009-06-02T10:00:00Z</updated>' + |
---|
441 | '</entry>', |
---|
442 | // end document |
---|
443 | 'Writes an entry doc with Atom constructs overriding well-known atts' |
---|
444 | ); |
---|
445 | } |
---|
446 | </script> |
---|
447 | </head> |
---|
448 | <body> |
---|
449 | </body> |
---|
450 | </html> |
---|