Ticket #927: test_KML.html.patch
| File test_KML.html.patch, 3.7 kB (added by openlayers, 10 months ago) |
|---|
-
/home/dcorpataux/workspace/openlayers/tests/Format/test_KML.html
old new 3 3 <script src="../../lib/OpenLayers.js"></script> 4 4 <script type="text/javascript"> 5 5 6 var test_content = '<kml xmlns="http://earth.google.com/kml/2.0"><Folder><name>OpenLayers export</name><description>Vector geometries from OpenLayers</description><Placemark><name>OpenLayers.Feature.Vector_344</name><description>Not available</description><Polygon><outerBoundaryIs><LinearRing><coordinates>5.001370157823406,49.26855713824488 8.214706453896161,49.630662409673505 8.397385910100951,48.45172350357396 5.001370157823406,49.26855713824488 </coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark><Placemark><name>OpenLayers.Feature.Vector_402</name><description>Not available</description><LineString><coordinates>5.838523393080493,49.74814616928052 5.787079558782349,48.410795432216574 8.91427702008381,49.28932499608202 </coordinates></LineString></Placemark><Placemark><name>OpenLayers.Feature.Vector_451</name><description>Not available</description><Point><coordinates>6.985073041685488,49.8682250149058 </coordinates></Point></Placemark></Folder></kml>'; 6 7 7 8 function test_Format_KML_constructor(t) { 8 9 t.plan(4); … … 14 15 t.eq(format.foo, "bar", "constructor sets options correctly"); 15 16 t.eq(typeof format.read, "function", "format has a read function"); 16 17 t.eq(typeof format.write, "function", "format has a write function"); 17 18 18 } 19 19 20 20 function test_Format_KML_read(t) { 21 t.plan(1); 22 t.ok(true, "Read tests not done yet."); 21 t.plan(4); 22 var features = (new OpenLayers.Format.KML()).read(this.test_content); 23 t.eq(features.length, 3, "Number of features read is correct"); 24 t.ok(features[0].geometry.toString() == "POLYGON((5.001370157823406 49.26855713824488,8.214706453896161 49.630662409673505,8.397385910100951 48.45172350357396,5.001370157823406 49.26855713824488))", "polygon feature geometry correctly created"); 25 t.ok(features[1].geometry.toString() == "LINESTRING(5.838523393080493 49.74814616928052,5.787079558782349 48.410795432216574,8.91427702008381 49.28932499608202)", "linestring feature geometry correctly created"); 26 t.ok(features[2].geometry.toString() == "POINT(6.985073041685488 49.8682250149058)", "point feature geometry correctly created"); 23 27 } 24 28 25 29 function test_Format_KML_write(t) { … … 24 28 25 29 function test_Format_KML_write(t) { 26 30 t.plan(1); 27 t.ok(true, "Write tests not done yet."); 28 31 var kmlExpected = this.test_content; 29 32 var format = new OpenLayers.Format.KML(); 30 //var doc = format.read(text); 31 //var out = format.write(doc); 32 //out = out.replace(/[\r\n]/g, ''); 33 //t.eq(text, out, 34 // "correctly writes an KML DOM doc"); 33 var features = format.read(kmlExpected); 34 var kmlOut = format.write(features); 35 kmlOut = kmlOut.replace(/[\r\n]/g, ''); 36 // Strips <name> dans <description> tags because content is kinda dynamic 37 kmlOut = kmlOut.replace(/<name>.*?<\/name>/g, '<name>Empty</name>'); 38 kmlOut = kmlOut.replace(/<description>.*?<\/description>/g, '<description>Empty</description>'); 39 kmlExpected = kmlExpected.replace(/<name>.*?<\/name>/g, '<name>Empty</name>'); 40 kmlExpected = kmlExpected.replace(/<description>.*?<\/description>/g, '<description>Empty</description>'); 41 t.eq(kmlExpected, kmlOut, "correctly writes an KML DOM doc"); 35 42 } 36 43 37 44 </script>
