1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<html>
<head>
<script src="../../OLLoader.js"></script>
<script src="../../../lib/deprecated.js"></script>
<script type="text/javascript">
var tile;
var map, layer;
function setUp() {
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer(null, {
isBaseLayer: true
});
map.addLayer(layer)
map.setCenter(new OpenLayers.LonLat(0, 0));
}
function tearDown() {
map.destroy();
map = null;
layer = null;
}
function test_Tile_WFS_constructor (t) {
t.plan( 8 );
setUp();
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile.WFS(layer, position, bounds, url, size);
t.ok( tile instanceof OpenLayers.Tile.WFS, "new OpenLayers.Tile.WFS returns Tile.WFS object" );
t.ok( tile.layer === layer, "tile.layer set correctly");
t.ok( tile.position.equals(position), "tile.position set correctly");
t.ok( tile.bounds.equals(bounds), "tile.bounds set correctly");
t.eq( tile.url, url, "tile.url set correctly");
t.ok( tile.size.equals(size), "tile.size is set correctly" );
t.ok( tile.id != null, "tile is given an id");
t.ok( tile.events != null, "tile's events intitialized");
tearDown();
}
function test_Tile_WFS_requestSuccess(t) {
t.plan(2);
setUp();
var tile = {
'request': {}
};
OpenLayers.Tile.WFS.prototype.requestSuccess.apply(tile, []);
t.ok(tile.request == null, "request property on tile set to null");
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile.WFS(layer, position, bounds, url, size);
tile.destroy();
tile.requestSuccess({'requestText': '<xml><foo /></xml>'});
t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile.");
tearDown();
}
function test_Tile_WFS_loadFeaturesForRegion(t) {
t.plan(9);
var tile = {
'url': {}
};
var g_Success = {};
var _get = OpenLayers.Request.GET;
OpenLayers.Request.GET = function(config) {
t.ok(config.url == tile.url, "tile's url correctly passed");
t.ok(config.params == null, "null params");
t.ok(config.scope == tile, "tile passed as scope");
t.ok(config.success == g_Success, "success passed");
};
//no running request -- 4 tests
OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
//running request (cancelled) -- 4 tests + 1 test (for request abort)
tile.request = {
'abort': function() {
t.ok(true, "request aborted");
}
};
OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
OpenLayers.Request.GET = _get;
}
function test_Tile_WFS_destroy(t) {
t.plan(9);
setUp();
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile.WFS(layer, position, bounds, url, size);
tile.events.destroy = function() {
t.ok(true, "tile events destroy() called");
};
var _gAbort = false;
tile.request = {
abort: function() {
_gAbort = true;
}
}
tile.destroy();
t.ok(tile.layer == null, "tile.layer set to null");
t.ok(tile.bounds == null, "tile.bounds set to null");
t.ok(tile.size == null, "tile.size set to null");
t.ok(tile.position == null, "tile.position set to null");
t.ok(_gAbort, "request transport is aborted");
t.ok(tile.request == null, "tile.request set to null");
t.ok(tile.events == null, "tile.events set to null");
tile.requestSuccess({'requestText': '<xml><foo /></xml>'});
t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile.");
tearDown();
}
function test_nonxml_format(t) {
t.plan(2);
setUp();
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"}}}'
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
var log = [];
var l = new OpenLayers.Layer(null, {
vectorMode: true,
formatObject: new OpenLayers.Format.GeoJSON(),
addFeatures: function(features) {
log.push(features);
}
})
map.addLayer(l);
var tile = new OpenLayers.Tile.WFS(l, position, bounds, url, size);
tile.requestSuccess({responseText: data});
t.eq(log.length, 1, "one call logged")
t.eq(log[0] && log[0].length, 1, "GeoJSON format returned a single feature which was added.");
tearDown();
}
function test_xml_string_and_dom(t) {
t.plan(4);
setUp();
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&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=OWLS&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>';
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "bobob";
var size = new OpenLayers.Size(5,6);
var l = new OpenLayers.Layer();
map.addLayer(l);
var tile = new OpenLayers.Tile.WFS(l, position, bounds, url, size);
var log = [];
tile.addResults = function(results) {
log.push(results);
}
tile.requestSuccess({responseText: data});
t.eq(log.length, 1, "first call logged");
t.eq(log[0] && log[0].length, 1, "results count is correct when passing in XML as a string into non-vectormode");
log.length = 0;
tile.addResults = function(results) {
log.push(results);
}
tile.requestSuccess({responseXML: OpenLayers.Format.XML.prototype.read(data)});
t.eq(log.length, 1, "second call logged");
t.eq(log[0] && log[0].length, 1, "results count is correct when passing in XML as DOM into non-vectormode");
tearDown();
}
</script>
</head>
<body>
</body>
</html>
|