diff options
Diffstat (limited to 'misc/openlayers/tests/Protocol')
-rw-r--r-- | misc/openlayers/tests/Protocol/CSW.html | 90 | ||||
-rw-r--r-- | misc/openlayers/tests/Protocol/HTTP.html | 842 | ||||
-rw-r--r-- | misc/openlayers/tests/Protocol/SOS.html | 57 | ||||
-rw-r--r-- | misc/openlayers/tests/Protocol/Script.html | 282 | ||||
-rw-r--r-- | misc/openlayers/tests/Protocol/WFS.html | 471 |
5 files changed, 1742 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Protocol/CSW.html b/misc/openlayers/tests/Protocol/CSW.html new file mode 100644 index 0000000..8c0847c --- /dev/null +++ b/misc/openlayers/tests/Protocol/CSW.html @@ -0,0 +1,90 @@ +<html> +<head> + <script src="../../lib/OpenLayers.js"></script> + <script type="text/javascript"> + + function test_initialize(t) { + t.plan(3); + + var protocol = new OpenLayers.Protocol.CSW({formatOptions: {foo: "bar"}}); + t.ok(protocol instanceof OpenLayers.Protocol.CSW.v2_0_2, + "initialize returns instance of default versioned protocol"); + var format = protocol.format; + t.ok(format instanceof OpenLayers.Format.CSWGetRecords.v2_0_2, "Default format created"); + t.ok(format.foo, "bar", "formatOptions set correctly"); + protocol.destroy(); + } + + function test_read(t) { + t.plan(6); + + var protocol = new OpenLayers.Protocol.CSW({ + url: "http://some.url.org", + parseData: function(request) { + t.eq(request.responseText, "foo", "parseData called properly"); + return "foo"; + } + }); + + var _POST = OpenLayers.Request.POST; + + var expected, status; + OpenLayers.Request.POST = function(obj) { + t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetRecords request is correct"); + obj.status = status; + obj.responseText = "foo"; + obj.options = {}; + t.delay_call(0.1, function() {obj.callback.call(this)}); + return obj; + }; + + expected = readXML("GetRecords"); + status = 200; + var data = { + "resultType": "results", + "maxRecords": 100, + "Query": { + "typeNames": "gmd:MD_Metadata", + "ElementSetName": { + "value": "full" + } + } + }; + var response = protocol.read({ + params: data, + callback: function(response) { + t.eq(response.data, "foo", "user callback properly called with data"); + t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly to user callback"); + } + }); + + var options = { + params: data, + callback: function(response) { + t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback"); + } + }; + status = 400; + var response = protocol.read(options); + + OpenLayers.Request.POST = _POST; + } + + function readXML(id) { + var xml = document.getElementById(id).firstChild.nodeValue; + return new OpenLayers.Format.XML().read(xml).documentElement; + } + + </script> +</head> +<body> +<div id="map" style="width:512px; height:256px"> </div> +<div id="GetRecords"><!-- +<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" resultType="results" maxRecords="100"> + <csw:Query typeNames="gmd:MD_Metadata"> + <csw:ElementSetName>full</csw:ElementSetName> + </csw:Query> +</csw:GetRecords> +--></div> +</body> +</html> diff --git a/misc/openlayers/tests/Protocol/HTTP.html b/misc/openlayers/tests/Protocol/HTTP.html new file mode 100644 index 0000000..fac460b --- /dev/null +++ b/misc/openlayers/tests/Protocol/HTTP.html @@ -0,0 +1,842 @@ +<html> +<head> + <script src="../OLLoader.js"></script> + <script type="text/javascript"> + + function test_constructor(t) { + t.plan(8); + var a = new OpenLayers.Protocol.HTTP({ + url: "foo" + }); + + // 4 tests + t.eq(a.url, "foo", "constructor sets url"); + t.eq(a.options.url, a.url, "constructor copies url to options.url"); + t.eq(a.params, {}, "constructor sets params"); + t.eq(a.options.params, undefined, "constructor do not copy params to options.params"); + + var params = {hello: "world"}; + var b = new OpenLayers.Protocol.HTTP({ + url: "bar", + params: params + }); + + // 4 tests + t.eq(b.url, "bar", "constructor sets url"); + t.eq(b.options.url, b.url, "constructor copies url to options.url"); + t.eq(b.params, params, "constructor sets params"); + t.eq(b.options.params, b.params, "constructor copies params to options.params"); + } + + function test_destroy(t) { + t.plan(3); + var protocol = new OpenLayers.Protocol.HTTP({ + url: "bar", + params: {hello: "world"} + }); + protocol.destroy(); + t.eq(protocol.options, null, "destroy nullifies options"); + t.eq(protocol.params, null, "destroy nullifies params"); + t.eq(protocol.headers, null, "destroy nullifies headers"); + } + + function test_read(t) { + t.plan(10); + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'params': {'k': 'foo_param'} + }); + + // fake XHR request object + var request = {'status': 200}; + + // options to pass to read + var readOptions = { + 'url': 'bar_url', + 'params': {'k': 'bar_param'}, + 'headers': {'k': 'bar_header'}, + 'scope': {'hello': 'world'}, + 'callback': function() {} + }; + + var response; + + protocol.handleResponse = function(resp, opt) { + // 4 tests + var req = resp.priv; + t.ok(this == protocol, + 'handleResponse called with correct scope'); + t.ok(opt == readOptions, + 'handleResponse called with correct options'); + t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response', + 'handleResponse called with a Response object'); + t.eq(req, request, + 'handleResponse called with correct request'); + + response = resp; + }; + + var _get = OpenLayers.Request.GET; + + OpenLayers.Request.GET = function(options) { + // 5 tests + t.eq(options.url, readOptions.url, + 'GET called with correct url in options'); + t.eq(options.params['k'], readOptions.params['k'], + 'GET called with correct params in options'); + t.eq(options.headers['k'], readOptions.headers['k'], + 'GET called with correct headers in options'); + t.eq(options.scope, undefined, + 'GET called with correct scope in options'); + t.ok(typeof options.callback == 'function', + 'GET called with a callback in options'); + t.delay_call(0.1, function() { + options.callback(request); + t.ok(resp == response, + 'read returns the expected response object'); + // cleanup + protocol.destroy(); + OpenLayers.Request.GET = _get; + }); + return request; + }; + + var resp = protocol.read(readOptions); + + OpenLayers.Request.GET = _get; + } + + function test_readWithPOST(t) { + t.plan(10); + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'params': {'k': 'foo_param'} + }); + + // fake XHR request object + var request = {'status': 200}; + + // options to pass to read + var readOptions = { + 'url': 'bar_url', + 'params': {'k': 'bar_param'}, + 'scope': {'hello': 'world'}, + 'callback': function() {}, + 'readWithPOST': true + }; + + var response; + + protocol.handleResponse = function(resp, opt) { + // 4 tests + var req = resp.priv; + t.ok(this == protocol, + 'handleResponse called with correct scope'); + t.ok(opt == readOptions, + 'handleResponse called with correct options'); + t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response', + 'handleResponse called with a Response object'); + t.eq(req, request, + 'handleResponse called with correct request'); + + response = resp; + }; + + var _post = OpenLayers.Request.POST; + + OpenLayers.Request.POST = function(options) { + // 5 tests + t.eq(options.url, readOptions.url, + 'GET with POST called with correct url in options'); + t.eq(options.data, OpenLayers.Util.getParameterString(readOptions.params), + 'GET with POST called with correct params encoded in options'); + t.eq(options.headers, {"Content-Type": "application/x-www-form-urlencoded"}, + 'GET with POST called with correct headers (application/x-www-form-urlencoded)'); + t.eq(options.scope, undefined, + 'GET with POST called with correct scope in options'); + t.ok(typeof options.callback == 'function', + 'GET with POST called with a callback in options'); + t.delay_call(0.1, function() { + options.callback(request); + t.ok(resp == response, + 'read returns the expected response object'); + // cleanup + protocol.destroy(); + OpenLayers.Request.POST = _post; + }); + return request; + }; + + var resp = protocol.read(readOptions); + + OpenLayers.Request.POST = _post; + } + + function test_read_method(t) { + t.plan(4); + + var _post = OpenLayers.Request.POST; + OpenLayers.Request.POST = function(options) { return 'post'; } + var _get = OpenLayers.Request.GET; + OpenLayers.Request.GET = function(options) { return 'get'; } + + var protocol = new OpenLayers.Protocol.HTTP({}); + + t.eq(protocol.read({}).priv, 'get', + 'readWithPOST is false by default'); + t.eq(protocol.read({readWithPOST: true}).priv, 'post', + 'readWithPOST can be set in read options'); + + var protocol = new OpenLayers.Protocol.HTTP({readWithPOST: true}); + + t.eq(protocol.read({}).priv, 'post', + 'readWithPOST can be set in constructor'); + t.eq(protocol.read({readWithPOST: false}).priv, 'get', + 'readWithPOST can be overridden in read options'); + + OpenLayers.Request.POST = _post; + OpenLayers.Request.GET = _get; + } + + function test_read_bbox(t) { + t.plan(6); + + var _get = OpenLayers.Request.GET; + + var bounds = new OpenLayers.Bounds(1, 2, 3, 4); + var filter = new OpenLayers.Filter.Spatial({ + type: OpenLayers.Filter.Spatial.BBOX, + value: bounds, + projection: new OpenLayers.Projection("foo") + }); + + // log requests + var log, exp; + OpenLayers.Request.GET = function(options) { + log.push(options.params.bbox); + return {status: 200}; + }; + + // 1) issue request with default protocol + log = []; + new OpenLayers.Protocol.HTTP().read({filter: filter}); + + t.eq(log.length, 1, "1) GET called once"); + t.ok(log[0] instanceof Array, "1) bbox param is array"); + exp = bounds.toArray(); + t.eq(log[0], exp, "1) bbox param doesn't include SRS id by default"); + + // 2) issue request with default protocol + log = []; + new OpenLayers.Protocol.HTTP({srsInBBOX: true}).read({filter: filter}); + + t.eq(log.length, 1, "2) GET called once"); + t.ok(log[0] instanceof Array, "2) bbox param is array"); + exp = bounds.toArray(); + exp.push("foo"); + t.eq(log[0], exp, "2) bbox param includes SRS id if srsInBBOX is true"); + + OpenLayers.Request.GET = _get; + } + + function test_parseFeatures(t) { + t.plan(5); + + var protocol = new OpenLayers.Protocol.HTTP(); + + // test responseXML - 2 tests + var request = { + 'responseXML': { + 'documentElement': 'xml' + } + }; + protocol.format = { + 'read': function(doc) { + t.eq(doc.documentElement, 'xml', + 'format.read called with correct doc'); + return doc.documentElement; + } + }; + var ret = protocol.parseFeatures(request); + t.eq(ret, 'xml', 'parseFeatures returns expected value'); + + // test responseText - 2 tests + var request = { + 'responseText': 'text' + }; + protocol.format = { + 'read': function(doc) { + t.eq(doc, 'text', + 'format.read called with correct doc'); + return doc; + } + }; + var ret = protocol.parseFeatures(request); + t.eq(ret, 'text', 'parseFeatures returns expected value'); + + // test empty responseText - 1 test + var request = { + 'responseText': '' + }; + protocol.format = { + 'read': function(doc) { + t.fail('format.read should not be called'); + } + }; + var ret = protocol.parseFeatures(request); + t.eq(ret, null, 'parseFeatures returns expected value'); + } + + function test_create(t) { + t.plan(10); + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'format': {'write': function() {}} + }); + + // fake XHR request object + var request = {'status': 200}; + + // features to pass to create + var features = ['feature']; + + // options to pass to create + var createOptions = { + 'url': 'bar_url', + 'headers': {'k': 'bar_header'}, + 'scope': {'hello': 'world'}, + 'callback': function() {} + }; + + var response; + + protocol.handleCreate = function(resp, opt) { + // 5 tests + var req = resp.priv; + t.ok(this == protocol, + 'handleCreate called with correct scope'); + t.ok(opt == createOptions, + 'handleCreate called with correct options'); + t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response', + 'handleCreate called with a Response object'); + t.ok(resp.reqFeatures == features, + 'handleCreate called with correct requested features in response'); + t.eq(req, request, + 'handleCreate called with correct request'); + + response = resp; + }; + + var _post = OpenLayers.Request.POST; + + OpenLayers.Request.POST = function(options) { + // 4 tests + t.eq(options.url, createOptions.url, + 'POST called with correct url in options'); + t.eq(options.headers['k'], createOptions.headers['k'], + 'POST called with correct headers in options'); + t.eq(options.scope, undefined, + 'POST called with correct scope in options'); + t.ok(typeof options.callback == 'function', + 'POST called with a callback in options'); + // call callback - delayed because this function has to return first + t.delay_call(0.1, function() { + options.callback(request); + t.ok(resp == response, + 'create returns the expected response object'); + // cleanup + protocol.destroy(); + OpenLayers.Request.POST = _post; + }); + return request; + }; + + var resp = protocol.create(features, createOptions); + + OpenLayers.Request.POST = _post; + } + + function test_update(t) { + t.plan(10); + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'format': {'write': function() {}} + }); + + // fake XHR request object + var request = {'status': 200}; + + // feature to pass to update + var feature = {'feature':'feature'}; + + // options to pass to update + var updateOptions = { + 'url': 'bar_url', + 'headers': {'k': 'bar_header'}, + 'scope': {'hello': 'world'}, + 'callback': function() {} + }; + + var response; + + protocol.handleUpdate = function(resp, opt) { + var req = resp.priv; + // 5 tests + t.ok(this == protocol, + 'handleUpdate called with correct scope'); + t.ok(opt == updateOptions, + 'handleUpdate called with correct options'); + t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response', + 'handleUpdate called with a Response object'); + t.ok(resp.reqFeatures == feature, + 'handleUpdate called with correct requested feature in response'); + t.eq(req, request, + 'handleUpdate called with correct request'); + + response = resp; + }; + + var _put = OpenLayers.Request.PUT; + + OpenLayers.Request.PUT = function(options) { + // 4 tests + t.eq(options.url, updateOptions.url, + 'PUT called with correct url in options'); + t.eq(options.headers['k'], updateOptions.headers['k'], + 'PUT called with correct headers in options'); + t.eq(options.scope, undefined, + 'PUT called with correct scope in options'); + t.ok(typeof options.callback == 'function', + 'PUT called with a callback in options'); + // call callback - delayed because this function has to return first + t.delay_call(0.1, function() { + options.callback(request); + t.ok(resp == response, + 'update returns the expected response object'); + // cleanup + protocol.destroy(); + OpenLayers.Request.PUT = _put; + }); + return request; + }; + + var resp = protocol.update(feature, updateOptions); + + OpenLayers.Request.PUT = _put; + } + + function test_update_featureurl(t) { + + // test that OpenLayers.Request.PUT receives the URL + // set in the feature + // http://trac.openlayers.org/ticket/2393#comment:11 + + t.plan(1); + + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'format': {'write': function() {}} + }); + + // feature to pass to update + var feature = {'feature':'feature', 'url': 'bar_url'}; + + var _put = OpenLayers.Request.PUT; + + OpenLayers.Request.PUT = function(options) { + t.eq(options.url, feature.url, + 'PUT called with correct url in options'); + }; + + protocol.update(feature); + + OpenLayers.Request.PUT = _put; + } + + function test_handleResponse(t) { + t.plan(6); + + var protocol = new OpenLayers.Protocol.HTTP(); + + var options, response, request, features; + + // test options - 2 tests + var scope = {'fake': 'scope'}; + options = { + 'scope': scope, + 'callback': function(resp) { + t.ok(this == scope, + '[no status] callback called with correct scope'); + t.ok(resp == response, + '[no status] callback called with correct response'); + } + }; + response = {priv: {}}; + protocol.handleResponse(response, options); + + // test failure condition - 1 test + options = { + 'callback': function(resp) { + t.eq(resp.code, OpenLayers.Protocol.Response.FAILURE, + '[status 400] callback called with correct response code'); + } + }; + response = {priv: {status: 400}}; + protocol.handleResponse(response, options); + + // test success condition - 3 tests + features = {'fake': 'features'}; + options = { + 'callback': function(resp) { + t.eq(resp.code, OpenLayers.Protocol.Response.SUCCESS, + '[status 200] callback called with correct response code'); + t.eq(resp.features, features, + '[status 200] callback called with correct features in response'); + } + }; + response = {priv: {status: 200}}; + protocol.parseFeatures = function(request) { + t.ok(request == response.priv, + '[status 200] parseFeatures called with correct request'); + return features; + } + protocol.handleResponse(response, options); + + // cleanup + protocol.destroy(); + } + + function test_delete(t) { + t.plan(10); + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url' + }); + + // fake XHR request object + var request = {'status': 200}; + + // feature to pass to delete + var feature = {'url': 'bar_url'}; + + // options to pass to delete + var deleteOptions = { + 'url': 'bar_url', + 'headers': {'k': 'bar_header'}, + 'scope': {'hello': 'world'}, + 'callback': function() {} + }; + + var response; + + protocol.handleDelete = function(resp, opt) { + // 5 tests + var req = resp.priv; + t.ok(this == protocol, + 'handleDelete called with correct scope'); + t.ok(opt == deleteOptions, + 'handleDelete called with correct options'); + t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response', + 'handleDelete called with a Response object'); + t.ok(resp.reqFeatures == feature, + 'handleDelete called with correct requested feature in response'); + t.eq(req, request, + 'handleDelete called with correct request'); + + response = resp; + }; + + var _delete = OpenLayers.Request.DELETE; + + OpenLayers.Request.DELETE = function(options) { + // 4 tests + t.eq(options.url, deleteOptions.url, + 'DELETE called with correct url in options'); + t.eq(options.headers['k'], deleteOptions.headers['k'], + 'DELETE called with correct headers in options'); + t.eq(options.scope, undefined, + 'DELETE called with correct scope in options'); + t.ok(typeof options.callback == 'function', + 'DELETE called with a callback in options'); + // call callback - delayed because this function has to return first + t.delay_call(0.1, function() { + options.callback(request); + t.ok(resp == response, + 'read returns the expected response object'); + // cleanup + protocol.destroy(); + OpenLayers.Request.DELETE = _delete; + }); + return request; + }; + + var resp = protocol['delete'](feature, deleteOptions); + + OpenLayers.Request.DELETE = _delete; + } + + function test_delete_featureurl(t) { + + // test that OpenLayers.Request.DELETE receives the URL + // set in the feature + // http://trac.openlayers.org/ticket/2393#comment:11 + + t.plan(1); + + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'format': {'write': function() {}} + }); + + // feature to pass to update + var feature = {'feature':'feature', 'url': 'bar_url'}; + + var _delete = OpenLayers.Request.DELETE; + + OpenLayers.Request.DELETE = function(options) { + t.eq(options.url, feature.url, + 'DELETE called with correct url in options'); + }; + + protocol['delete'](feature); + + OpenLayers.Request.DELETE = _delete; + } + + function test_handleDelete(t) { + t.plan(4); + + var protocol = new OpenLayers.Protocol.HTTP(); + + var options, response, request, features; + + // test options - 2 tests + var scope = {'fake': 'scope'}; + options = { + 'scope': scope, + 'callback': function(resp) { + t.ok(this == scope, + 'callback called with correct scope'); + t.ok(resp == response, + 'callback called with correct response'); + } + }; + response = {priv: {}}; + protocol.handleDelete(response, options); + + // test failure condition - 1 test + options = { + 'callback': function(resp) { + t.eq(resp.code, OpenLayers.Protocol.Response.FAILURE, + 'callback called with correct response code'); + } + }; + response = {priv: {status: 400}}; + protocol.handleDelete(response, options); + + // test success condition - 1 test + options = { + 'callback': function(resp) { + t.eq(resp.code, OpenLayers.Protocol.Response.SUCCESS, + 'callback called with correct response code'); + } + }; + response = {priv: {status: 200}}; + protocol.handleDelete(response, options); + + // cleanup + protocol.destroy(); + } + + function test_commit(t) { + t.plan(17); + + var protocol = new OpenLayers.Protocol.HTTP(); + + // 6 features + var features = [ + {'state': OpenLayers.State.INSERT}, + {'state': OpenLayers.State.INSERT}, + {'state': OpenLayers.State.UPDATE}, + {'state': OpenLayers.State.UPDATE}, + {'state': OpenLayers.State.DELETE}, + {'state': OpenLayers.State.DELETE} + ]; + + var options = { + 'create': { + 'callback': function(resp) { + } + }, + 'update': { + 'callback': function(resp) { + } + }, + 'delete': { + 'callback': function(resp) { + } + } + }; + + var respCreate = new OpenLayers.Protocol.Response(); + var respUpdate = new OpenLayers.Protocol.Response(); + var respDelete = new OpenLayers.Protocol.Response(); + + // 2 tests + protocol['create'] = function(feature, options) { + t.ok(options.scope == protocol, + 'create called with correct scope'); + t.ok(typeof options.callback == 'function', + 'create called with a callback in options'); + options.callback.call(options.scope, respCreate); + return respCreate; + }; + // 4 tests + protocol['update'] = function(feature, options) { + t.ok(options.scope == protocol, + 'update called with correct scope'); + t.ok(typeof options.callback == 'function', + 'update called with a callback in options'); + options.callback.call(options.scope, respUpdate); + return respUpdate; + }; + // 4 tests + protocol['delete'] = function(feature, options) { + t.ok(options.scope == protocol, + 'delete called with correct scope'); + t.ok(typeof options.callback == 'function', + 'delete called with a callback in options'); + options.callback.call(options.scope, respDelete); + return respDelete; + }; + + var count = 0; + + // 5 tests + protocol.callUserCallback = function(resp, opt) { + t.ok(opt == options, + 'callUserCallback called with correction options map'); + count++; + }; + + var resp = protocol.commit(features, options); + + // 2 tests + t.eq(count, 5, 'callUserCallback called for each request'); + t.eq(resp.length, 5, 'commit returns array with correct length'); + + // cleanup + protocol.destroy(); + } + + function test_callUserCallback(t) { + t.plan(1); + + var protocol = new OpenLayers.Protocol.HTTP(); + + var scope = {'fake': 'scope'}; + + // test commit callback + var log = {}; + var options = { + foo: { + callback: function() { + log.scope = this; + }, + scope: scope + } + }; + var resp = {requestType: 'foo'}; + protocol.callUserCallback(resp, options); + t.ok(log.scope, scope, 'correct callback called with correct scope'); + + } + + function test_options(t) { + t.plan(6); + + var log1 = {}; + + // test that read with no options uses protocol options - 5 tests + var url = "."; + var headers = {}; + var params = {}; + var scope = {}; + var protocol = new OpenLayers.Protocol.HTTP({ + format: new OpenLayers.Format({ + read: function() {}, + write: function() {} + }), + url: url, + headers: headers, + params: params, + callback: function(resp) { + log1.callbackCalled = true; + log1.callbackScope = this; + log1.request = resp && resp.priv; + log1.requestType = resp && resp.requestType; + }, + scope: scope + }); + protocol.read(); + + t.delay_call(2, function() { + t.eq(log1.callbackCalled, true, "[read] callback called"); + t.eq(log1.callbackScope, scope, "[read] correct scope"); + t.ok(log1.request instanceof OpenLayers.Request.XMLHttpRequest, "[read] correct priv type"); + t.eq(log1.requestType, "read", "[read] correct request type"); + }); + + + // test that commit with no options uses protocol options - 2 tests + var log2 = {called: 0}; + protocol.options.callback = function() { + log2.called++; + log2.scope = this; + }; + protocol.commit([ + {state: OpenLayers.State.INSERT}, + {state: OpenLayers.State.INSERT}, + {state: OpenLayers.State.UPDATE, url: "./1"}, + {state: OpenLayers.State.UPDATE, url: "./2"}, + {state: OpenLayers.State.DELETE, url: "./3"}, + {state: OpenLayers.State.DELETE, url: "./4"} + ]); + t.delay_call(2, function() { + t.eq(log2.called, 1, "[commit] Callback called once."); + t.eq(log2.scope, scope, "[commit] Correct scope."); + }); + } + + function test_read_global_options(t) { + + // test that calling read doesn't write params into the protocol's + // options object, see ticket #3237 + + t.plan(2); + + var protocol = new OpenLayers.Protocol.HTTP({ + url: '.', + callback: function() {}, + params: {'a': 'a'} + }); + + // check initial state first + t.eq(protocol.options.params, {'a': 'a'}, + 'protocol params are ok at initial state'); + + var filter = new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.EQUAL_TO, + property: 'b', + value: 'b' + }); + protocol.read({filter: filter}); + t.eq(protocol.options.params, {'a': 'a'}, + "protocol params are ok after read"); + } + + + </script> +</head> +<body> +</body> +</html> diff --git a/misc/openlayers/tests/Protocol/SOS.html b/misc/openlayers/tests/Protocol/SOS.html new file mode 100644 index 0000000..58e6607 --- /dev/null +++ b/misc/openlayers/tests/Protocol/SOS.html @@ -0,0 +1,57 @@ +<html> +<head> + <script src="../OLLoader.js"></script> + <script type="text/javascript"> + + function test_constructor(t) { + t.plan(4); + var a = new OpenLayers.Protocol.SOS({ + url: "foo", + fois: ["a", "b", "c"] + }); + + t.eq(a.url, "foo", "constructor sets url"); + t.eq(a.options.url, a.url, "constructor copies url to options.url"); + t.eq(a.fois[0], "a", "constructor sets the fois correctly"); + t.eq((a.format instanceof OpenLayers.Format.SOSGetFeatureOfInterest), true, "Constructor sets format correctly"); + } + + function test_read(t) { + t.plan(4); + + var protocol = new OpenLayers.Protocol.SOS({ + url: "http://some.url.org/sos?", + fois: ["foi1", "foi2"], + parseFeatures: function(request) { + t.eq(request.responseText, "foo", "parseFeatures called properly"); + return "foo"; + } + }); + + var _POST = OpenLayers.Request.POST; + + var expected, status; + OpenLayers.Request.POST = function(obj) { + t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeatureOfInterest request is correct"); + obj.status = status; + obj.responseText = "foo"; + obj.options = {}; + t.delay_call(0.1, function() {obj.callback.call(this)}); + return obj; + }; + + var xml = '<GetFeatureOfInterest xmlns="http://www.opengis.net/sos/1.0" version="1.0.0" service="SOS" xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosAll.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><FeatureOfInterestId>foi1</FeatureOfInterestId><FeatureOfInterestId>foi2</FeatureOfInterestId></GetFeatureOfInterest>'; + expected = new OpenLayers.Format.XML().read(xml).documentElement; + status = 200; + var response = protocol.read({callback: function(response) { + t.eq(response.features, "foo", "user callback properly called with features"); + t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly"); + }}); + + } + + </script> +</head> +<body> +</body> +</html> diff --git a/misc/openlayers/tests/Protocol/Script.html b/misc/openlayers/tests/Protocol/Script.html new file mode 100644 index 0000000..894427a --- /dev/null +++ b/misc/openlayers/tests/Protocol/Script.html @@ -0,0 +1,282 @@ +<html> +<head> + <script src="../../lib/OpenLayers.js"></script> + <script type="text/javascript"> + + function test_constructor(t) { + t.plan(11); + var a = new OpenLayers.Protocol.Script({ + url: "foo" + }); + + // 7 tests + t.eq(a.url, "foo", "constructor sets url"); + t.eq(a.options.url, a.url, "constructor copies url to options.url"); + t.eq(a.params, {}, "constructor sets params"); + t.eq(a.options.params, undefined, "constructor does not copy params to options.params"); + t.ok(a.format instanceof OpenLayers.Format.GeoJSON, + "constructor sets a GeoJSON format by default"); + t.eq(a.callbackKey, 'callback', + "callbackKey is set to 'callback' by default"); + t.eq(a.callbackPrefix, '', + "callbackPrefix is set to '' by default"); + + var params = {hello: "world"}; + var b = new OpenLayers.Protocol.Script({ + url: "bar", + params: params, + callbackKey: 'cb_key', + callbackPrefix: 'cb_prefix' + }); + + // 6 tests + t.eq(b.params, params, "constructor sets params"); + t.eq(b.options.params, b.params, "constructor copies params to options.params"); + t.eq(b.callbackKey, 'cb_key', + "callbackKey is set to 'cb_key'"); + t.eq(b.callbackPrefix, 'cb_prefix', + "callbackPrefix is set to 'cb_prefix'"); + } + + function test_destroy(t) { + t.plan(3); + var aborted = false; + var protocol = new OpenLayers.Protocol.Script({ + url: "bar", + params: {hello: "world"}, + abort: function() { + aborted = true; + } + }); + protocol.destroy(); + t.ok(aborted, "destroy aborts request"); + t.eq(protocol.params, null, "destroy nullifies params"); + t.eq(protocol.format, null, "destroy nullifies format"); + } + + function test_read(t) { + t.plan(5); + var protocol = new OpenLayers.Protocol.Script({ + 'url': 'foo_url', + 'params': {'k': 'foo_param'} + }); + + // fake XHR request object + var request = {'status': 200}; + + // options to pass to read + var readOptions = { + 'url': 'bar_url', + 'params': {'k': 'bar_param'} + }; + + var response; + + protocol.createRequest = function(url, params, callback) { + // 4 tests + t.ok(this == protocol, + 'createRequest called with correct scope'); + t.ok(url == readOptions.url, + 'createRequest called with correct url'); + t.ok(params == readOptions.params, + 'createRequest called with correct params'); + t.ok(callback instanceof Function, + 'createRequest called with a function as callback'); + + return 'foo_request'; + }; + + var resp = protocol.read(readOptions); + + t.eq(resp.priv, 'foo_request', + 'response priv property set to what the createRequest method returns'); + } + + function test_read_bbox(t) { + t.plan(6); + + var _createRequest = OpenLayers.Protocol.Script.prototype.createRequest; + + var bounds = new OpenLayers.Bounds(1, 2, 3, 4); + var filter = new OpenLayers.Filter.Spatial({ + type: OpenLayers.Filter.Spatial.BBOX, + value: bounds, + projection: new OpenLayers.Projection("foo") + }); + + // log requests + var log, exp; + OpenLayers.Protocol.Script.prototype.createRequest = function(url, params, + callback) { + log.push(params.bbox); + return null; + }; + + // 1) issue request with default protocol + log = []; + new OpenLayers.Protocol.Script().read({filter: filter}); + + t.eq(log.length, 1, "1) createRequest called once"); + t.ok(log[0] instanceof Array, "1) bbox param is array"); + exp = bounds.toArray(); + t.eq(log[0], exp, "1) bbox param doesn't include SRS id by default"); + + // 2) issue request with default protocol + log = []; + new OpenLayers.Protocol.Script({srsInBBOX: true}).read({filter: filter}); + + t.eq(log.length, 1, "2) createRequest called once"); + t.ok(log[0] instanceof Array, "2) bbox param is array"); + exp = bounds.toArray(); + exp.push("foo"); + t.eq(log[0], exp, "2) bbox param includes SRS id if srsInBBOX is true"); + + OpenLayers.Protocol.Script.prototype.createRequest = _createRequest; + } + + function test_createRequest(t) { + t.plan(6); + var protocol = new OpenLayers.Protocol.Script({ + callbackKey: 'cb_key', + callbackPrefix: 'cb_prefix:' + }); + + var _register = OpenLayers.Protocol.Script.register; + OpenLayers.Protocol.Script.register = function() { + return 'bar'; + }; + + var script = protocol.createRequest('http://bar_url/', {'k': 'bar_param'}, 'bar_callback'); + + t.eq(script.type, 'text/javascript', + 'created script has a correct type'); + + var params = OpenLayers.Util.getParameters(script.src); + t.eq(params.k, "bar_param", "custom query string param"); + t.eq(params.cb_key, "cb_prefix:OpenLayers.Protocol.Script.registry.bar", "callback with prefix"); + + t.eq(script.id, 'OpenLayers_Protocol_Script_bar', + 'created script has a correct id'); + + protocol.callbackTemplate = "customCallback(${id})"; + script = protocol.createRequest('http://bar_url/', {'k': 'bar_param2'}, 'bar_callback'); + + params = OpenLayers.Util.getParameters(script.src); + t.eq(params.k, "bar_param2", "custom query string param"); + t.eq(params.cb_key, "cb_prefix:customCallback(bar)", "custom callback with prefix"); + + OpenLayers.Protocol.Script.register = _register; + + } + + function test_destroyRequest(t) { + t.plan(2); + + var protocol = new OpenLayers.Protocol.Script({}); + + var _unregister = OpenLayers.Protocol.Script.unregister; + OpenLayers.Protocol.Script.unregister = function(id) { + t.eq(id, 'foo', "destroyRequest calls unregister with correct id"); + }; + var script = { + id: 'script_foo' + }; + protocol.destroyRequest(script); + t.eq(protocol.pendingRequests[script.id], null, + "destroyRequest nullifies the pending request"); + + OpenLayers.Protocol.Script.unregister = _unregister; + } + + function test_handleResponse(t) { + t.plan(8); + + var protocol = new OpenLayers.Protocol.Script(); + + // 2 tests (should be called only twive) + protocol.destroyRequest = function(priv) { + t.eq(priv, 'foo_priv', 'destroyRequest called with correct argument'); + } + + // 1 test (should be called only once) + protocol.parseFeatures = function(data) { + t.eq(data, 'foo_data', 'parseFeatures called with correct argument'); + return 'foo_features'; + } + + var response = { + priv: 'foo_priv', + data: 'foo_data' + } + var options = { + // 2 tests (should be called twice) + scope: 'foo_scope', + callback: function(resp) { + t.eq(this, 'foo_scope', 'callback called with correct scope'); + } + } + protocol.handleResponse(response, options); + // 2 tests + t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, + 'response code correctly set'); + t.eq(response.features, 'foo_features', + 'response features takes a correct value'); + + response = { + priv: 'foo_priv' + } + protocol.handleResponse(response, options); + // 1 test + t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, + 'response code correctly set'); + } + + function test_parseFeatures(t) { + t.plan(1); + + var protocol = new OpenLayers.Protocol.Script(); + + protocol.format = { + 'read': function(data) { + t.ok(true, 'format.read called'); + } + }; + + var ret = protocol.parseFeatures({foo: 'bar'}); + } + + function test_abort(t) { + t.plan(2); + + var protocol = new OpenLayers.Protocol.Script(); + + // 1 test + protocol.destroyRequest = function(priv) { + t.eq(priv, 'foo_priv', 'destroyRequest called with correct argument'); + } + + var response = { + priv: 'foo_priv' + } + + protocol.abort(response); + + var calls = []; + protocol.pendingRequests = { + 'foo': 'foo_request', + 'bar': 'bar_request' + } + protocol.destroyRequest = function(priv) { + calls.push(priv); + } + protocol.abort(); + // 1 test + t.eq(calls, ['foo_request', 'bar_request'], + 'destroyRequest called for each pending requests'); + } + + </script> +</head> +<body> +</body> +</html> diff --git a/misc/openlayers/tests/Protocol/WFS.html b/misc/openlayers/tests/Protocol/WFS.html new file mode 100644 index 0000000..24e775d --- /dev/null +++ b/misc/openlayers/tests/Protocol/WFS.html @@ -0,0 +1,471 @@ +<html> +<head> + <script src="../OLLoader.js"></script> + <script type="text/javascript"> + + function test_initialize(t) { + t.plan(2); + + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type" + }); + t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_0_0, + "initialize returns instance of default versioned protocol") + + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type", + version: "1.1.0" + }); + t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_1_0, + "initialize returns instance of custom versioned protocol") + } + + function test_setGeometryName(t) { + t.plan(4); + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type", + geometryName: "geom" + }); + t.eq(protocol.geometryName, "geom", "geometryName set correctly by constructor"); + t.eq(protocol.format.geometryName, "geom", "geometryName correctly set on format by constructor"); + // change the geometryName on the fly + protocol.setGeometryName("SHAPE"); + t.eq(protocol.geometryName, "SHAPE", "geometryName changed correctly by setGeometryName"); + t.eq(protocol.format.geometryName, "SHAPE", "geometryName correctly changed on format by setGeometryName"); + protocol.destroy(); + } + + function test_setFeatureType(t) { + t.plan(4); + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type" + }); + t.eq(protocol.featureType, "type", "featureType set correctly by constructor"); + t.eq(protocol.format.featureType, "type", "featureType correctly set on format by constructor"); + // change the feature type on the fly + protocol.setFeatureType("foo"); + t.eq(protocol.featureType, "foo", "featureType changed correctly by setFeatureType"); + t.eq(protocol.format.featureType, "foo", "featureType correctly changed on format by setFeatureType"); + protocol.destroy(); + } + + function test_read(t) { + t.plan(7); + + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type", + parseResponse: function(request, options) { + t.eq(request.responseText, "foo", "parseResponse called properly"); + t.eq(options, {foo: "bar"}, "parseResponse receives readOptions"); + return "foo"; + } + }); + + var _POST = OpenLayers.Request.POST; + + var expected, status; + OpenLayers.Request.POST = function(obj) { + t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct"); + obj.status = status; + obj.responseText = "foo"; + t.delay_call(0.1, function() {obj.callback.call(this)}); + return obj; + }; + + expected = readXML("GetFeature_1"); + status = 200; + var response = protocol.read({readOptions: {foo: "bar"}, callback: function(response) { + t.eq(response.features, "foo", "user callback properly called with features"); + t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly"); + }}); + + options = { + maxFeatures: 10, + featureType: 'type2', + srsName: 'EPSG:900913', + featureNS: 'htttp://alternative.namespace.org', + callback: function(response) { + t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback"); + } + }; + expected = readXML("GetFeature_2"); + status = 400; + var response = protocol.read(options); + + OpenLayers.Request.POST = _POST; + } + + function test_parseResponse_poorconfig(t) { + t.plan(2); + + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featurePrefix: "topp", + featureType: "tasmania_roads", + geometryName: null + }); + + protocol.parseResponse({responseText: document.getElementById("query_response").firstChild.nodeValue}); + t.eq(protocol.geometryName, "geom", "geometryName configured correctly"); + t.eq(protocol.featureNS, "http://www.openplans.org/topp", "featureNS configured correctly"); + } + + function test_exception(t) { + t.plan(8); + var url = "http://some.url.org"; + var protocol = new OpenLayers.Protocol.WFS({ + url: url, + version: "1.1.0", + featureNS: "http://namespace.org", + featureType: "type" + }); + // mock up a response + var response = { + priv: { + status: 200, + responseText: '<?xml version="1.0" encoding="UTF-8"?><ows:ExceptionReport language="en" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows"><ows:Exception locator="foo" exceptionCode="InvalidParameterValue"><ows:ExceptionText>Update error: Error occurred updating features</ows:ExceptionText><ows:ExceptionText>Second exception line</ows:ExceptionText></ows:Exception></ows:ExceptionReport>' + } + }; + var log, entry, expected; + + // test GetFeature + log = []; + protocol.handleRead(OpenLayers.Util.extend({}, response), { + callback: function(resp) { + log.push(resp); + } + }); + expected = { + exceptionReport: { + version: "1.0.0", + language: "en", + exceptions: [{ + code: "InvalidParameterValue", + locator: "foo", + texts: [ + "Update error: Error occurred updating features", + "Second exception line" + ] + }] + }, + success: false + }; + + t.eq(log.length, 1, "GetFeature handled"); + entry = log[0]; + t.eq(entry.code, OpenLayers.Protocol.Response.FAILURE, "GetFeature failure reported"); + t.ok(!!entry.error, "GetFeature got error"); + t.eq(entry.error, expected, "GetFeature error matches expected"); + + // test a commit + log = []; + protocol.handleCommit(response, { + callback: function(resp) { + log.push(resp); + } + }); + t.eq(log.length, 1, "commit handled"); + entry = log[0]; + t.eq(entry.code, OpenLayers.Protocol.Response.FAILURE, "commit failure reported"); + t.ok(!!entry.error, "commit got error"); + t.eq(entry.error, expected, "GetFeature error matches expected"); + + } + + function test_commit(t){ + t.plan(5); + + var url = "http://some.url.org"; + var protocol = new OpenLayers.Protocol.WFS({ + url: url, + featureNS: "http://namespace.org", + featureType: "type" + }); + protocol.format.read = function(data) { + t.eq(data, "foo", "callback called with correct argument"); + return { + insertIds: new Array(3), + success: true + } + }; + + var _POST = OpenLayers.Request.POST; + + var expected; + OpenLayers.Request.POST = function(obj) { + t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "Transaction XML with Insert, Update and Delete created correctly"); + t.eq(obj.headers, {foo: 'bar'}, "HTTP headers passed from commit to Request.POST"); + obj.responseText = "foo"; + t.delay_call(0.1, function() {obj.callback.call(this)}); + return obj; + }; + + var featureDelete = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(42, 7), {has : "cheeseburger"}); + featureDelete.fid = "fid.37"; + featureDelete.state = OpenLayers.State.DELETE; + featureDelete.layer = { + projection: { + getCode : function(){ + return "EPSG:4326"; + } + } + } + var featureInsert = featureDelete.clone(); + featureInsert.state = OpenLayers.State.INSERT; + var featureModify = featureDelete.clone(); + featureModify.fid = "fid.37"; + featureModify.state = OpenLayers.State.UPDATE; + + options = { + featureNS: "http://some.namespace.org", + featureType: "type", + headers: {foo: 'bar'}, + callback: function(response) { + t.eq(response.insertIds.length, 3, "correct response passed to user callback"); + t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success properly reported to user callback"); + } + } + + expected = readXML("commit"); + var response = protocol.commit([featureInsert, featureModify, featureDelete], options); + + OpenLayers.Request.POST = _POST; + + } + + function test_filterDelete(t) { + t.plan(2) + + var url = "http://some.url.org"; + var protocol = new OpenLayers.Protocol.WFS({ + url: url, + featureNS: "http://namespace.org", + featureType: "type" + }); + + var filter = new OpenLayers.Filter.Spatial({ + type: OpenLayers.Filter.Spatial.BBOX, + value: new OpenLayers.Bounds(-5, -5, 5, 5) + }); + + var _POST = OpenLayers.Request.POST; + + var expected = readXML("filter_delete"); + OpenLayers.Request.POST = function(obj) { + t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "request data correct"); + t.delay_call(0.1, function() {obj.callback.call(this)}); + return obj; + }; + + var response = protocol.filterDelete(filter, { + callback: function() { + t.ok("user callback function called"); + } + }); + + OpenLayers.Request.POST = _POST; + } + + function test_abort(t) { + t.plan(1); + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://example.com", + featureNS: "http://example.com#namespace", + featureType: "type" + }); + + var response = { + priv: { + abort: function() { + aborted = true; + } + } + }; + + // call abort with mocked response + var aborted = false; + protocol.abort(response); + t.eq(aborted, true, "abort called on response.priv"); + + } + + function test_fromWMSLayer(t) { + t.plan(9); + var map = new OpenLayers.Map("map", { + projection: "CRS:84" + }); + var layer = new OpenLayers.Layer.WMS("foo", "htttp://foo/ows", + {layers: "topp:states"} + ); + map.addLayer(layer); + var protocol = OpenLayers.Protocol.WFS.fromWMSLayer(layer); + t.eq(protocol.url, "htttp://foo/ows", "url taken from wms layer"); + t.eq(protocol.featurePrefix, "topp", "feature prefix correctly extracted"); + t.eq(protocol.featureType, "states", "typeName correctly extracted"); + t.eq(protocol.srsName, "CRS:84", "srsName set correctly"); + t.eq(protocol.version, "1.1.0", "version set correctly"); + t.eq(protocol.format.geometryName, null, "format's geometryName set to null"); + + layer.params["LAYERS"] = ["topp:street_centerline", "topp:states"]; + layer.projection = new OpenLayers.Projection("EPSG:900913"); + protocol = OpenLayers.Protocol.WFS.fromWMSLayer(layer); + t.eq(protocol.featurePrefix, "topp", "featurePrefix from layer param array"); + t.eq(protocol.featureType, "street_centerline", "first layer from layer param array as featureType"); + t.eq(protocol.srsName, "EPSG:900913", "projection from layer preferred"); + } + + function test_readFormat(t) { + t.plan(1); + + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type", + formatOptions: {outputFormat: 'json'}, + readFormat: new OpenLayers.Format.GeoJSON() + }); + + var request = {}; + request.responseText = '{"type":"FeatureCollection","features":[{"type":"Feature","id":"V_HECTOPUNTEN.108411","geometry":{"type":"MultiPoint","coordinates":[[190659.467,349576.19]]},"geometry_name":"ORA_GEOMETRY","properties":{"WEGNUMMER":"002","HECTOMTRNG_ORG":2200,"HECTOMTRNG":"220.00","bbox":[190659.467,349576.19,190659.467,349576.19]}}]}'; + var features = protocol.parseResponse(request); + t.eq(features.length, 1, "the right format is used to read the request (GeoJSON)"); + } + + function test_outputFormat(t) { + t.plan(2); + + var protocol = new OpenLayers.Protocol.WFS({ + version: "1.1.0", + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type", + outputFormat: 'json' + }); + + t.ok(protocol.readFormat instanceof OpenLayers.Format.GeoJSON, "the correct readFormat is used for outputFormat JSON"); + + protocol = new OpenLayers.Protocol.WFS({ + version: "1.1.0", + url: "http://some.url.org", + featureNS: "http://namespace.org", + featureType: "type", + outputFormat: 'GML2' + }); + + t.ok(protocol.readFormat instanceof OpenLayers.Format.GML.v2, "the correct readFormat is used for outputFormat GML2"); + } + + function test_readOptions(t) { + t.plan(1); + + var protocol = new OpenLayers.Protocol.WFS({ + url: "http://some.url.org", + version: "1.1.0", + featureNS: "http://namespace.org", + featureType: "type", + readOptions: {'output': 'object'}, + parseResponse: function(request, options) { + t.eq(options.output, "object", "Options object correctly set to pass on to Format's read"); + } + }); + + var _POST = OpenLayers.Request.POST; + + OpenLayers.Request.POST = function(obj) { + obj.status = 200; + obj.responseText = "foo"; + t.delay_call(0.1, function() {obj.callback.call(this)}); + return obj; + }; + + protocol.read({ + callback: function() {} + }); + + OpenLayers.Request.POST = _POST; + } + + function readXML(id) { + var xml = document.getElementById(id).firstChild.nodeValue; + return new OpenLayers.Format.XML().read(xml).documentElement; + } + + </script> +</head> +<body> +<div id="map" style="width:512px; height:256px"> </div> +<div id="GetFeature_1"><!-- +<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"> + <wfs:Query typeName="feature:type" xmlns:feature="http://namespace.org"/> +</wfs:GetFeature> +--></div> +<div id="GetFeature_2"><!-- +<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"> + <wfs:Query typeName="feature:type2" xmlns:feature="htttp://alternative.namespace.org"/> +</wfs:GetFeature> +--></div> +<div id="commit"><!-- +<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"> + <wfs:Insert> + <feature:type xmlns:feature="http://namespace.org"> + <feature:the_geom> + <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> + <gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates> + </gml:Point> + </feature:the_geom> + <feature:has>cheeseburger</feature:has> + </feature:type> + </wfs:Insert> + <wfs:Update typeName="feature:type" xmlns:feature="http://namespace.org"> + <wfs:Property> + <wfs:Name>the_geom</wfs:Name> + <wfs:Value> + <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> + <gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates> + </gml:Point> + </wfs:Value> + </wfs:Property> + <wfs:Property> + <wfs:Name>has</wfs:Name> + <wfs:Value>cheeseburger</wfs:Value> + </wfs:Property> + <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> + <ogc:FeatureId fid="fid.37"/> + </ogc:Filter> + </wfs:Update> + <wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org"> + <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> + <ogc:FeatureId fid="fid.37"/> + </ogc:Filter> + </wfs:Delete> +</wfs:Transaction> +--></div> +<div id="filter_delete"><!-- +<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"> + <wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org"> + <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> + <ogc:BBOX> + <gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> + <gml:coordinates decimal="." cs="," ts=" ">-5,-5 5,5</gml:coordinates> + </gml:Box> + </ogc:BBOX> + </ogc:Filter> + </wfs:Delete> +</wfs:Transaction> +--></div> +<div id="query_response"><!-- +<?xml version="1.0" encoding="UTF-8"?> +<wfs:FeatureCollection xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink"><gml:boundedBy><gml:Envelope srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lowerCorner>5450000.0 500000.0</gml:lowerCorner><gml:upperCorner>5450000.0 540000.0</gml:upperCorner></gml:Envelope></gml:boundedBy><gml:featureMembers><topp:tasmania_roads gml:id="tasmania_roads.1"><gml:boundedBy><gml:Envelope srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lowerCorner>5450000.0 500000.0</gml:lowerCorner><gml:upperCorner>5450000.0 540000.0</gml:upperCorner></gml:Envelope></gml:boundedBy><topp:geom><gml:MultiLineString srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lineStringMember><gml:LineString><gml:posList>5450000.0 500000.0 5450000.0 540000.0</gml:posList></gml:LineString></gml:lineStringMember></gml:MultiLineString></topp:geom><topp:TYPE>street</topp:TYPE></topp:tasmania_roads></gml:featureMembers></wfs:FeatureCollection> +--></div> +</body> +</html> |