3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_initialize(t) {
9 var protocol = new OpenLayers.Protocol.WFS({
10 url: "http://some.url.org",
11 featureNS: "http://namespace.org",
14 t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_0_0,
15 "initialize returns instance of default versioned protocol")
17 var protocol = new OpenLayers.Protocol.WFS({
18 url: "http://some.url.org",
19 featureNS: "http://namespace.org",
23 t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_1_0,
24 "initialize returns instance of custom versioned protocol")
27 function test_read(t) {
30 var protocol = new OpenLayers.Protocol.WFS({
31 url: "http://some.url.org",
32 featureNS: "http://namespace.org",
34 parseFeatures: function(request) {
35 t.eq(request.responseText, "foo", "parseFeatures called properly");
40 var _POST = OpenLayers.Request.POST;
43 OpenLayers.Request.POST = function(obj) {
44 t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct");
46 obj.responseText = "foo";
48 t.delay_call(0.1, function() {obj.callback.call(this)});
52 expected = readXML("GetFeature_1");
54 var response = protocol.read({callback: function(response) {
55 t.eq(response.features, "foo", "user callback properly called with features");
56 t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
62 srsName: 'EPSG:900913',
63 featureNS: 'htttp://alternative.namespace.org',
64 callback: function(response) {
65 t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback");
68 expected = readXML("GetFeature_2");
70 var response = protocol.read(options);
72 OpenLayers.Request.POST = _POST;
75 function test_commit(t){
78 var url = "http://some.url.org";
79 var protocol = new OpenLayers.Protocol.WFS({
81 featureNS: "http://namespace.org",
84 protocol.format.read = function(data) {
85 t.eq(data, "foo", "callback called with correct argument");
87 insertIds: new Array(3),
92 var _POST = OpenLayers.Request.POST;
95 OpenLayers.Request.POST = function(obj) {
96 t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "Transaction XML with Insert, Update and Delete created correctly");
97 obj.responseText = "foo";
99 t.delay_call(0.1, function() {obj.callback.call(this)});
103 var featureDelete = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(42, 7), {has : "cheeseburger"});
104 featureDelete.fid = "fid.37";
105 featureDelete.state = OpenLayers.State.DELETE;
106 featureDelete.layer = {
108 getCode : function(){
113 var featureInsert = featureDelete.clone();
114 featureInsert.state = OpenLayers.State.INSERT;
115 var featureModify = featureDelete.clone();
116 featureModify.fid = "fid.37";
117 featureModify.state = OpenLayers.State.UPDATE;
120 featureNS: "http://some.namespace.org",
122 callback: function(response) {
123 t.eq(response.insertIds.length, 3, "correct response passed to user callback");
124 t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success properly reported to user callback");
128 expected = readXML("commit");
129 var response = protocol.commit([featureInsert, featureModify, featureDelete], options);
131 OpenLayers.Request.POST = _POST;
135 function test_filterDelete(t) {
138 var url = "http://some.url.org";
139 var protocol = new OpenLayers.Protocol.WFS({
141 featureNS: "http://namespace.org",
145 var filter = new OpenLayers.Filter.Spatial({
146 type: OpenLayers.Filter.Spatial.BBOX,
147 value: new OpenLayers.Bounds(-5, -5, 5, 5)
150 var _POST = OpenLayers.Request.POST;
152 var expected = readXML("filter_delete");
153 OpenLayers.Request.POST = function(obj) {
154 t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "request data correct");
155 t.delay_call(0.1, function() {obj.callback.call(this)});
159 var response = protocol.filterDelete(filter, {
160 callback: function() {
161 t.ok("user callback function called");
165 OpenLayers.Request.POST = _POST;
168 function test_abort(t) {
170 var protocol = new OpenLayers.Protocol.WFS({
171 url: "http://example.com",
172 featureNS: "http://example.com#namespace",
184 // call abort with mocked response
186 protocol.abort(response);
187 t.eq(aborted, true, "abort called on response.priv");
191 function test_fromWMSLayer(t) {
193 var map = new OpenLayers.Map("map", {
194 projection: "EPSG:1234"
196 var layer = new OpenLayers.Layer.WMS("foo", "htttp://foo/ows",
197 {layers: "topp:states"}
200 var protocol = OpenLayers.Protocol.WFS.fromWMSLayer(layer);
201 t.eq(protocol.url, "htttp://foo/ows", "url taken from wms layer");
202 t.eq(protocol.featurePrefix, "topp", "feature prefix correctly extracted");
203 t.eq(protocol.featureType, "states", "typeName correctly extracted");
204 t.eq(protocol.srsName, "EPSG:1234", "srsName set correctly");
205 t.eq(protocol.version, "1.1.0", "version set correctly");
207 layer.params["LAYERS"] = ["topp:street_centerline", "topp:states"];
208 layer.projection = new OpenLayers.Projection("EPSG:900913");
209 protocol = OpenLayers.Protocol.WFS.fromWMSLayer(layer);
210 t.eq(protocol.featurePrefix, "topp", "featurePrefix from layer param array");
211 t.eq(protocol.featureType, "street_centerline", "first layer from layer param array as featureType");
212 t.eq(protocol.srsName, "EPSG:900913", "projection from layer preferred");
215 function readXML(id) {
216 var xml = document.getElementById(id).firstChild.nodeValue;
217 return new OpenLayers.Format.XML().read(xml).documentElement;
223 <div id="map" style="width:512px; height:256px"> </div>
224 <div id="GetFeature_1"><!--
225 <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
226 <wfs:Query typeName="feature:type" xmlns:feature="http://namespace.org"/>
229 <div id="GetFeature_2"><!--
230 <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="10" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
231 <wfs:Query typeName="feature:type2" xmlns:feature="htttp://alternative.namespace.org"/>
234 <div id="commit"><!--
235 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
237 <feature:type xmlns:feature="http://namespace.org">
239 <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
240 <gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates>
243 <feature:has>cheeseburger</feature:has>
246 <wfs:Update typeName="feature:type" xmlns:feature="http://namespace.org">
248 <wfs:Name>the_geom</wfs:Name>
250 <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
251 <gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates>
256 <wfs:Name>has</wfs:Name>
257 <wfs:Value>cheeseburger</wfs:Value>
259 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
260 <ogc:FeatureId fid="fid.37"/>
263 <wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
264 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
265 <ogc:FeatureId fid="fid.37"/>
270 <div id="filter_delete"><!--
271 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0">
272 <wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
273 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
276 <gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
277 <gml:coordinates decimal="." cs="," ts=" ">-5,-5 5,5</gml:coordinates>