~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/Tile/WFS.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <script src="../../lib/OpenLayers.js"></script>
 
4
  <script type="text/javascript">
 
5
    var tile; 
 
6
    
 
7
    function test_Tile_WFS_constructor (t) {
 
8
        t.plan( 8 );
 
9
     
 
10
        var layer = {}; // bogus layer
 
11
        var position = new OpenLayers.Pixel(10,20);
 
12
        var bounds = new OpenLayers.Bounds(1,2,3,4);
 
13
        var url = "bobob";
 
14
        var size = new OpenLayers.Size(5,6);
 
15
        
 
16
        tile = new OpenLayers.Tile.WFS(layer, position, bounds, url, size);
 
17
 
 
18
        t.ok( tile instanceof OpenLayers.Tile.WFS, "new OpenLayers.Tile.WFS returns Tile.WFS object" );
 
19
        t.eq( tile.layer, layer, "tile.layer set correctly");
 
20
        t.ok( tile.position.equals(position), "tile.position set correctly");
 
21
        t.ok( tile.bounds.equals(bounds), "tile.bounds set correctly");
 
22
        t.eq( tile.url, url, "tile.url set correctly");        
 
23
        t.ok( tile.size.equals(size), "tile.size is set correctly" );
 
24
 
 
25
        t.ok( tile.id != null, "tile is given an id");
 
26
        t.ok( tile.events != null, "tile's events intitialized");
 
27
    }
 
28
 
 
29
    function test_Tile_WFS_requestSuccess(t) {
 
30
        t.plan(2);
 
31
 
 
32
        var tile = {
 
33
            'request': {}
 
34
        };
 
35
            
 
36
        OpenLayers.Tile.WFS.prototype.requestSuccess.apply(tile, []);
 
37
        
 
38
        t.ok(tile.request == null, "request property on tile set to null");
 
39
 
 
40
        var layer = {
 
41
            SUPPORTED_TRANSITIONS: [],
 
42
            events: {
 
43
                unregister: function() {}
 
44
            }
 
45
        }; // bogus layer
 
46
        var position = new OpenLayers.Pixel(10,20);
 
47
        var bounds = new OpenLayers.Bounds(1,2,3,4);
 
48
        var url = "bobob";
 
49
        var size = new OpenLayers.Size(5,6);
 
50
        
 
51
        tile = new OpenLayers.Tile.WFS(layer, position, bounds, url, size);
 
52
        tile.destroy();
 
53
        tile.requestSuccess({'requestText': '<xml><foo /></xml>'});
 
54
        t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile.");
 
55
        
 
56
    }
 
57
    
 
58
    function test_Tile_WFS_loadFeaturesForRegion(t) {
 
59
        t.plan(9);
 
60
        
 
61
        var tile = {
 
62
            'url': {}
 
63
        };
 
64
 
 
65
        var g_Success = {};        
 
66
 
 
67
        var _get = OpenLayers.Request.GET;
 
68
        OpenLayers.Request.GET = function(config) {
 
69
            t.ok(config.url == tile.url, "tile's url correctly passed");
 
70
            t.ok(config.params == null, "null params");
 
71
            t.ok(config.scope == tile, "tile passed as scope");
 
72
            t.ok(config.success == g_Success, "success passed");
 
73
        };
 
74
        
 
75
      //no running request -- 4 tests
 
76
        OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
 
77
 
 
78
      //running request (cancelled) -- 4 tests + 1 test (for request abort)
 
79
        tile.request = {
 
80
            'abort': function() {
 
81
                    t.ok(true, "request aborted");
 
82
            }
 
83
        };
 
84
        OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
 
85
 
 
86
        OpenLayers.Request.GET = _get;
 
87
    }
 
88
    
 
89
    function test_Tile_WFS_destroy(t) {
 
90
        t.plan(9);
 
91
 
 
92
        var layer = {
 
93
            SUPPORTED_TRANSITIONS: [],
 
94
            events: {
 
95
                unregister: function() {}
 
96
            }
 
97
        }; // bogus layer
 
98
        var position = new OpenLayers.Pixel(10,20);
 
99
        var bounds = new OpenLayers.Bounds(1,2,3,4);
 
100
        var url = "bobob";
 
101
        var size = new OpenLayers.Size(5,6);
 
102
        
 
103
        tile = new OpenLayers.Tile.WFS(layer, position, bounds, url, size);
 
104
        tile.events.destroy = function() {
 
105
            t.ok(true, "tile events destroy() called");
 
106
        };
 
107
 
 
108
 
 
109
        var _gAbort = false; 
 
110
        tile.request = { 
 
111
            abort: function() { 
 
112
                _gAbort = true; 
 
113
            } 
 
114
        } 
 
115
 
 
116
        
 
117
        tile.destroy();
 
118
 
 
119
        t.ok(tile.layer == null, "tile.layer set to null");
 
120
        t.ok(tile.bounds == null, "tile.bounds set to null");
 
121
        t.ok(tile.size == null, "tile.size set to null");
 
122
        t.ok(tile.position == null, "tile.position set to null");
 
123
        t.ok(_gAbort, "request transport is aborted");
 
124
        t.ok(tile.request == null, "tile.request set to null");
 
125
        
 
126
        t.ok(tile.events == null, "tile.events set to null");
 
127
        
 
128
        tile.requestSuccess({'requestText': '<xml><foo /></xml>'});
 
129
        t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile.");
 
130
    }
 
131
    function test_nonxml_format(t) {
 
132
        t.plan(1);
 
133
        var data = '{"type":"Feature", "id":"OpenLayers.Feature.Vector_135", "properties":{}, "geometry":{"type":"Point", "coordinates":[118.125, -18.6328125]}, "crs":{"type":"OGC", "properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}'
 
134
        var position = new OpenLayers.Pixel(10,20);
 
135
        var bounds = new OpenLayers.Bounds(1,2,3,4);
 
136
        var url = "bobob";
 
137
        var size = new OpenLayers.Size(5,6);
 
138
        
 
139
        var tile = new OpenLayers.Tile.WFS({
 
140
            vectorMode: true, 
 
141
            formatObject: new OpenLayers.Format.GeoJSON(), 
 
142
            addFeatures: function(features) { 
 
143
                t.eq(features.length, 1, "GeoJSON format returned a single feature which was added.")
 
144
            }
 
145
        }, position, bounds, url, size);
 
146
        tile.requestSuccess({responseText: data});
 
147
    }  
 
148
     
 
149
    function test_xml_string_and_dom(t) {
 
150
        t.plan(2);
 
151
        var data = '<?xml version="1.0" encoding="ISO-8859-1" ?><wfs:FeatureCollection   xmlns:bsc="http://www.bsc-eoc.org/bsc"   xmlns:wfs="http://www.opengis.net/wfs"   xmlns:gml="http://www.opengis.net/gml"   xmlns:ogc="http://www.opengis.net/ogc"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd                        http://www.bsc-eoc.org/bsc http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=OWLS&amp;OUTPUTFORMAT=XMLSCHEMA">      <gml:boundedBy>        <gml:Box srsName="EPSG:4326">            <gml:coordinates>-94.989723,43.285833 -74.755001,51.709520</gml:coordinates>        </gml:Box>      </gml:boundedBy>    <gml:featureMember>      <bsc:OWLS>        <gml:boundedBy>            <gml:Box srsName="EPSG:4326">                <gml:coordinates>-94.142500,50.992777 -94.142500,50.992777</gml:coordinates>            </gml:Box>        </gml:boundedBy>        <bsc:msGeometry>        <gml:Point srsName="EPSG:4326">          <gml:coordinates>-94.142500,50.992777</gml:coordinates>        </gml:Point>        </bsc:msGeometry>        <bsc:ROUTEID>ON_2</bsc:ROUTEID>        <bsc:ROUTE_NAME>Suffel Road</bsc:ROUTE_NAME>        <bsc:LATITUDE>50.9927770</bsc:LATITUDE>        <bsc:LONGITUDE>-94.1425000</bsc:LONGITUDE>      </bsc:OWLS>    </gml:featureMember></wfs:FeatureCollection>';
 
152
        var position = new OpenLayers.Pixel(10,20);
 
153
        var bounds = new OpenLayers.Bounds(1,2,3,4);
 
154
        var url = "bobob";
 
155
        var size = new OpenLayers.Size(5,6);
 
156
        var tile = new OpenLayers.Tile.WFS({
 
157
        }, position, bounds, url, size);
 
158
        tile.addResults = function(results) {
 
159
            t.eq(results.length, 1, "results count is correct when passing in XML as a string into non-vectormode");
 
160
        } 
 
161
        tile.requestSuccess({responseText: data});
 
162
        
 
163
        tile.addResults = function(results) {
 
164
            t.eq(results.length, 1, "results count is correct when passing in XML as DOM into non-vectormode");
 
165
        } 
 
166
        tile.requestSuccess({responseXML: OpenLayers.Format.XML.prototype.read(data)}); 
 
167
    }         
 
168
  </script>
 
169
</head>
 
170
<body>
 
171
</body>
 
172
</html>
 
173