OpenLayers OpenLayers

Ticket #927: test_KML.html.patch

File test_KML.html.patch, 3.7 kB (added by openlayers, 10 months ago)

Tests for KML.js, working on ff2/linux, carshing on IE7 (KML.write() throws an error)

  • /home/dcorpataux/workspace/openlayers/tests/Format/test_KML.html

    old new  
    33    <script src="../../lib/OpenLayers.js"></script>  
    44    <script type="text/javascript"> 
    55 
     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>'; 
    67 
    78    function test_Format_KML_constructor(t) {  
    89        t.plan(4);  
     
    1415        t.eq(format.foo, "bar", "constructor sets options correctly");  
    1516        t.eq(typeof format.read, "function", "format has a read function");  
    1617        t.eq(typeof format.write, "function", "format has a write function"); 
    17  
    1818    } 
    1919 
    2020    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"); 
    2327    } 
    2428 
    2529    function test_Format_KML_write(t) { 
     
    2428 
    2529    function test_Format_KML_write(t) { 
    2630        t.plan(1); 
    27         t.ok(true, "Write tests not done yet."); 
    28  
     31        var kmlExpected = this.test_content; 
    2932        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"); 
    3542    } 
    3643 
    3744    </script>