extend Protocol.HTTP for MapFish and FeatureServer. p=elemoine, r=bartvde,me (closes #2393)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10129 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+5
-5
@@ -206,6 +206,11 @@
|
|||||||
"OpenLayers/Strategy/BBOX.js",
|
"OpenLayers/Strategy/BBOX.js",
|
||||||
"OpenLayers/Strategy/Save.js",
|
"OpenLayers/Strategy/Save.js",
|
||||||
"OpenLayers/Strategy/Refresh.js",
|
"OpenLayers/Strategy/Refresh.js",
|
||||||
|
"OpenLayers/Filter.js",
|
||||||
|
"OpenLayers/Filter/FeatureId.js",
|
||||||
|
"OpenLayers/Filter/Logical.js",
|
||||||
|
"OpenLayers/Filter/Comparison.js",
|
||||||
|
"OpenLayers/Filter/Spatial.js",
|
||||||
"OpenLayers/Protocol.js",
|
"OpenLayers/Protocol.js",
|
||||||
"OpenLayers/Protocol/HTTP.js",
|
"OpenLayers/Protocol/HTTP.js",
|
||||||
"OpenLayers/Protocol/SQL.js",
|
"OpenLayers/Protocol/SQL.js",
|
||||||
@@ -221,11 +226,6 @@
|
|||||||
"OpenLayers/Style.js",
|
"OpenLayers/Style.js",
|
||||||
"OpenLayers/StyleMap.js",
|
"OpenLayers/StyleMap.js",
|
||||||
"OpenLayers/Rule.js",
|
"OpenLayers/Rule.js",
|
||||||
"OpenLayers/Filter.js",
|
|
||||||
"OpenLayers/Filter/FeatureId.js",
|
|
||||||
"OpenLayers/Filter/Logical.js",
|
|
||||||
"OpenLayers/Filter/Comparison.js",
|
|
||||||
"OpenLayers/Filter/Spatial.js",
|
|
||||||
"OpenLayers/Format.js",
|
"OpenLayers/Format.js",
|
||||||
"OpenLayers/Format/XML.js",
|
"OpenLayers/Format/XML.js",
|
||||||
"OpenLayers/Format/ArcXML.js",
|
"OpenLayers/Format/ArcXML.js",
|
||||||
|
|||||||
+163
-17
@@ -5,6 +5,9 @@
|
|||||||
/**
|
/**
|
||||||
* @requires OpenLayers/Protocol.js
|
* @requires OpenLayers/Protocol.js
|
||||||
* @requires OpenLayers/Feature/Vector.js
|
* @requires OpenLayers/Feature/Vector.js
|
||||||
|
* @requires OpenLayers/Filter/Spatial.js
|
||||||
|
* @requires OpenLayers/Filter/Comparison.js
|
||||||
|
* @requires OpenLayers/Filter/Logical.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,6 +65,17 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
*/
|
*/
|
||||||
readWithPOST: false,
|
readWithPOST: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: wildcarded.
|
||||||
|
* {Boolean} If true percent signs are added around values
|
||||||
|
* read from LIKE filters, for example if the protocol
|
||||||
|
* read method is passed a LIKE filter whose property
|
||||||
|
* is "foo" and whose value is "bar" the string
|
||||||
|
* "foo__ilike=%bar%" will be sent in the query string;
|
||||||
|
* defaults to false.
|
||||||
|
*/
|
||||||
|
wildcarded: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Protocol.HTTP
|
* Constructor: OpenLayers.Protocol.HTTP
|
||||||
* A class for giving layers generic HTTP protocol.
|
* A class for giving layers generic HTTP protocol.
|
||||||
@@ -79,6 +93,7 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* scope - {Object}
|
* scope - {Object}
|
||||||
*/
|
*/
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
|
options = options || {};
|
||||||
this.params = {};
|
this.params = {};
|
||||||
this.headers = {};
|
this.headers = {};
|
||||||
OpenLayers.Protocol.prototype.initialize.apply(this, arguments);
|
OpenLayers.Protocol.prototype.initialize.apply(this, arguments);
|
||||||
@@ -106,10 +121,8 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* url - {String} Url for the request.
|
* url - {String} Url for the request.
|
||||||
* params - {Object} Parameters to get serialized as a query string.
|
* params - {Object} Parameters to get serialized as a query string.
|
||||||
* headers - {Object} Headers to be set on the request.
|
* headers - {Object} Headers to be set on the request.
|
||||||
* filter - {<OpenLayers.Filter.BBOX>} If a bbox filter is sent, it will be
|
* filter - {<OpenLayers.Filter>} Filter to get serialized as a
|
||||||
* serialized according to the OpenSearch Geo extension
|
* query string.
|
||||||
* (bbox=minx,miny,maxx,maxy). Note that a BBOX filter as the child
|
|
||||||
* of a logical filter will not be serialized.
|
|
||||||
* readWithPOST - {Boolean} If the request should be done with POST.
|
* readWithPOST - {Boolean} If the request should be done with POST.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
@@ -121,18 +134,15 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
read: function(options) {
|
read: function(options) {
|
||||||
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
||||||
options = OpenLayers.Util.applyDefaults(options, this.options);
|
options = OpenLayers.Util.applyDefaults(options, this.options);
|
||||||
|
options.params = OpenLayers.Util.applyDefaults(
|
||||||
|
options.params, this.options.params);
|
||||||
|
if(options.filter) {
|
||||||
|
options.params = this.filterToParams(
|
||||||
|
options.filter, options.params);
|
||||||
|
}
|
||||||
var readWithPOST = (options.readWithPOST !== undefined) ?
|
var readWithPOST = (options.readWithPOST !== undefined) ?
|
||||||
options.readWithPOST : this.readWithPOST;
|
options.readWithPOST : this.readWithPOST;
|
||||||
var resp = new OpenLayers.Protocol.Response({requestType: "read"});
|
var resp = new OpenLayers.Protocol.Response({requestType: "read"});
|
||||||
|
|
||||||
if(options.filter && options.filter instanceof OpenLayers.Filter.Spatial) {
|
|
||||||
if(options.filter.type == OpenLayers.Filter.Spatial.BBOX) {
|
|
||||||
options.params = OpenLayers.Util.extend(options.params, {
|
|
||||||
bbox: options.filter.value.toArray()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(readWithPOST) {
|
if(readWithPOST) {
|
||||||
resp.priv = OpenLayers.Request.POST({
|
resp.priv = OpenLayers.Request.POST({
|
||||||
url: options.url,
|
url: options.url,
|
||||||
@@ -150,7 +160,6 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
headers: options.headers
|
headers: options.headers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -167,7 +176,122 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
handleRead: function(resp, options) {
|
handleRead: function(resp, options) {
|
||||||
this.handleResponse(resp, options);
|
this.handleResponse(resp, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: filterToParams
|
||||||
|
* Convert an <OpenLayers.Filter> object to parameters.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* filter - {OpenLayers.Filter} filter to convert.
|
||||||
|
* params - {Object} The parameters object.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} The resulting parameters object.
|
||||||
|
*/
|
||||||
|
filterToParams: function(filter, params) {
|
||||||
|
params = params || {};
|
||||||
|
var className = filter.CLASS_NAME;
|
||||||
|
var filterType = className.substring(className.lastIndexOf(".") + 1);
|
||||||
|
switch(filterType) {
|
||||||
|
case "Spatial":
|
||||||
|
switch(filter.type) {
|
||||||
|
case OpenLayers.Filter.Spatial.BBOX:
|
||||||
|
params.bbox = filter.value.toArray();
|
||||||
|
break;
|
||||||
|
case OpenLayers.Filter.Spatial.DWITHIN:
|
||||||
|
params.tolerance = filter.distance;
|
||||||
|
// no break here
|
||||||
|
case OpenLayers.Filter.Spatial.WITHIN:
|
||||||
|
params.lon = filter.value.x;
|
||||||
|
params.lat = filter.value.y;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
OpenLayers.Console.warn(
|
||||||
|
"Unknown spatial filter type " + filter.type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Comparison":
|
||||||
|
var op = OpenLayers.Protocol.HTTP.COMP_TYPE_TO_OP_STR[filter.type];
|
||||||
|
if(op !== undefined) {
|
||||||
|
var value = filter.value;
|
||||||
|
if(filter.type == OpenLayers.Filter.Comparison.LIKE) {
|
||||||
|
value = this.regex2value(value);
|
||||||
|
if(this.wildcarded) {
|
||||||
|
value = "%" + value + "%";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
params[filter.property + "__" + op] = value;
|
||||||
|
params.queryable = params.queryable || [];
|
||||||
|
params.queryable.push(filter.property);
|
||||||
|
} else {
|
||||||
|
OpenLayers.Console.warn(
|
||||||
|
"Unknown comparison filter type " + filter.type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Logical":
|
||||||
|
if(filter.type === OpenLayers.Filter.Logical.AND) {
|
||||||
|
for(var i=0,len=filter.filters.length; i<len; i++) {
|
||||||
|
params = this.filterToParams(filter.filters[i], params);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
OpenLayers.Console.warn(
|
||||||
|
"Unsupported logical filter type " + filter.type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
OpenLayers.Console.warn("Unknown filter type " + filterType);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: regex2value
|
||||||
|
* Convert the value from a regular expression string to a LIKE/ILIKE
|
||||||
|
* string known to the web service.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* value - {String} The regex string.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {String} The converted string.
|
||||||
|
*/
|
||||||
|
regex2value: function(value) {
|
||||||
|
|
||||||
|
// highly sensitive!! Do not change this without running the
|
||||||
|
// Protocol/HTTP.html unit tests
|
||||||
|
|
||||||
|
// convert % to \%
|
||||||
|
value = value.replace(/%/g, "\\%");
|
||||||
|
|
||||||
|
// convert \\. to \\_ (\\.* occurences converted later)
|
||||||
|
value = value.replace(/\\\\\.(\*)?/g, function($0, $1) {
|
||||||
|
return $1 ? $0 : "\\\\_";
|
||||||
|
});
|
||||||
|
|
||||||
|
// convert \\.* to \\%
|
||||||
|
value = value.replace(/\\\\\.\*/g, "\\\\%");
|
||||||
|
|
||||||
|
// convert . to _ (\. and .* occurences converted later)
|
||||||
|
value = value.replace(/(\\)?\.(\*)?/g, function($0, $1, $2) {
|
||||||
|
return $1 || $2 ? $0 : "_";
|
||||||
|
});
|
||||||
|
|
||||||
|
// convert .* to % (\.* occurnces converted later)
|
||||||
|
value = value.replace(/(\\)?\.\*/g, function($0, $1) {
|
||||||
|
return $1 ? $0 : "%";
|
||||||
|
});
|
||||||
|
|
||||||
|
// convert \. to .
|
||||||
|
value = value.replace(/\\\./g, ".");
|
||||||
|
|
||||||
|
// replace \* with * (watching out for \\*)
|
||||||
|
value = value.replace(/(\\)?\\\*/g, function($0, $1) {
|
||||||
|
return $1 ? $0 : "*";
|
||||||
|
});
|
||||||
|
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: create
|
* APIMethod: create
|
||||||
* Construct a request for writing newly created features.
|
* Construct a request for writing newly created features.
|
||||||
@@ -234,8 +358,10 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* the feature received from the server.
|
* the feature received from the server.
|
||||||
*/
|
*/
|
||||||
update: function(feature, options) {
|
update: function(feature, options) {
|
||||||
var url = options.url || feature.url || this.options.url;
|
|
||||||
options = OpenLayers.Util.applyDefaults(options, this.options);
|
options = OpenLayers.Util.applyDefaults(options, this.options);
|
||||||
|
var url = options.url ||
|
||||||
|
feature.url ||
|
||||||
|
this.options.url + "/" + feature.fid;
|
||||||
|
|
||||||
var resp = new OpenLayers.Protocol.Response({
|
var resp = new OpenLayers.Protocol.Response({
|
||||||
reqFeatures: feature,
|
reqFeatures: feature,
|
||||||
@@ -282,8 +408,10 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* completes.
|
* completes.
|
||||||
*/
|
*/
|
||||||
"delete": function(feature, options) {
|
"delete": function(feature, options) {
|
||||||
var url = options.url || feature.url || this.options.url;
|
|
||||||
options = OpenLayers.Util.applyDefaults(options, this.options);
|
options = OpenLayers.Util.applyDefaults(options, this.options);
|
||||||
|
var url = options.url ||
|
||||||
|
feature.url ||
|
||||||
|
this.options.url + "/" + feature.fid;
|
||||||
|
|
||||||
var resp = new OpenLayers.Protocol.Response({
|
var resp = new OpenLayers.Protocol.Response({
|
||||||
reqFeatures: feature,
|
reqFeatures: feature,
|
||||||
@@ -503,3 +631,21 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Protocol.HTTP"
|
CLASS_NAME: "OpenLayers.Protocol.HTTP"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: OpenLayers.Protocol.HTTP.COMP_TYPE_TO_OP_STR
|
||||||
|
* {Object} A private class-level property mapping the
|
||||||
|
* OpenLayers.Filter.Comparison types to the operation
|
||||||
|
* strings of the protocol.
|
||||||
|
*/
|
||||||
|
(function() {
|
||||||
|
var o = OpenLayers.Protocol.HTTP.COMP_TYPE_TO_OP_STR = {};
|
||||||
|
o[OpenLayers.Filter.Comparison.EQUAL_TO] = "eq";
|
||||||
|
o[OpenLayers.Filter.Comparison.NOT_EQUAL_TO] = "ne";
|
||||||
|
o[OpenLayers.Filter.Comparison.LESS_THAN] = "lt";
|
||||||
|
o[OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO] = "lte";
|
||||||
|
o[OpenLayers.Filter.Comparison.GREATER_THAN] = "gt";
|
||||||
|
o[OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO] = "gte";
|
||||||
|
o[OpenLayers.Filter.Comparison.LIKE] = "ilike";
|
||||||
|
})();
|
||||||
|
|
||||||
|
|||||||
+287
-2
@@ -273,6 +273,291 @@
|
|||||||
t.eq(ret, null, 'parseFeatures returns expected value');
|
t.eq(ret, null, 'parseFeatures returns expected value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_filterToParams(t) {
|
||||||
|
t.plan(30);
|
||||||
|
|
||||||
|
// setup
|
||||||
|
|
||||||
|
var protocol, filter, params;
|
||||||
|
|
||||||
|
protocol = new OpenLayers.Protocol.HTTP();
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
var filter = new OpenLayers.Filter.Spatial({
|
||||||
|
type: OpenLayers.Filter.Spatial.BBOX,
|
||||||
|
value: new OpenLayers.Bounds(0, 1, 2, 3)
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.bbox, [0, 1, 2, 3],
|
||||||
|
"filterToParams sets correct bbox param if passed a BBOX filter");
|
||||||
|
|
||||||
|
// 3 tests
|
||||||
|
var lon = 100, lat = 200, tolerance = 10;
|
||||||
|
filter = new OpenLayers.Filter.Spatial({
|
||||||
|
type: OpenLayers.Filter.Spatial.DWITHIN,
|
||||||
|
value: new OpenLayers.Geometry.Point(lon, lat),
|
||||||
|
distance: tolerance
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.lon, lon,
|
||||||
|
"filterToParams sets correct lon param if passed a DWITHIN filter");
|
||||||
|
t.eq(params.lat, lat,
|
||||||
|
"filterToParams sets correct lat param if passed a DWITHIN filter");
|
||||||
|
t.eq(params.tolerance, tolerance,
|
||||||
|
"filterToParams sets correct tolerance param if passed a DWITHIN filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Spatial({
|
||||||
|
type: OpenLayers.Filter.Spatial.WITHIN,
|
||||||
|
value: new OpenLayers.Geometry.Point(lon, lat)
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.lon, lon,
|
||||||
|
"filterToParams sets correct lon param if passed a WITHIN filter");
|
||||||
|
t.eq(params.lat, lat,
|
||||||
|
"filterToParams sets correct lat param if passed a WITHIN filter");
|
||||||
|
|
||||||
|
// Some bbox filters used in the next tests.
|
||||||
|
|
||||||
|
var bboxFilter1 = new OpenLayers.Filter.Spatial({
|
||||||
|
type: OpenLayers.Filter.Spatial.BBOX,
|
||||||
|
value: new OpenLayers.Bounds(0, 0, 10, 10)
|
||||||
|
});
|
||||||
|
|
||||||
|
var bboxFilter2 = new OpenLayers.Filter.Spatial({
|
||||||
|
type: OpenLayers.Filter.Spatial.BBOX,
|
||||||
|
value: new OpenLayers.Bounds(0, 0, 20, 20)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: []
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params, {},
|
||||||
|
"filterToParams returns empty object if given empty AND Logical filter");
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.OR,
|
||||||
|
filters: [
|
||||||
|
bboxFilter1
|
||||||
|
]
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params, {},
|
||||||
|
"filterToParams does not support OR Logical filter");
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: [
|
||||||
|
bboxFilter1
|
||||||
|
]
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.bbox, [0, 0, 10, 10],
|
||||||
|
"filterToParams sets correct bbox param if passed " +
|
||||||
|
"a Logical filter containing a BBOX");
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: [
|
||||||
|
bboxFilter1, bboxFilter2
|
||||||
|
]
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.bbox, [0, 0, 20, 20],
|
||||||
|
"filterToParams sets correct bbox param if passed " +
|
||||||
|
"multiple BBOX filter in a Logical filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.EQUAL_TO,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an EQUAL_TO filter");
|
||||||
|
t.eq(params["foo__eq"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an EQUAL_TO filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an NOT_EQUAL_TO filter");
|
||||||
|
t.eq(params["foo__ne"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an NOT_EQUAL_TO filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.LESS_THAN,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
var params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an LESS_THAN filter");
|
||||||
|
t.eq(params["foo__lt"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an LESS_THAN filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
var params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an LESS_THAN_OR_EQUAL_TO filter");
|
||||||
|
t.eq(params["foo__lte"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an LESS_THAN_OR_EQUAL_TO filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.GREATER_THAN,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an GREATER_THAN filter");
|
||||||
|
t.eq(params["foo__gt"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an GREATER_THAN filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an GREATER_THAN_OR_EQUAL_TO filter");
|
||||||
|
t.eq(params["foo__gte"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an GREATER_THAN_OR_EQUAL_TO filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.LIKE,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed a LIKE filter");
|
||||||
|
t.eq(params["foo__ilike"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an LIKE filter");
|
||||||
|
|
||||||
|
// 4 tests
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: [
|
||||||
|
new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.EQUAL_TO,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
}),
|
||||||
|
new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.LESS_THAN,
|
||||||
|
property: "foo2",
|
||||||
|
value: "baz"
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed an EQUAL_TO filter within a AND filter");
|
||||||
|
t.eq(params["foo__eq"], "bar",
|
||||||
|
"filterToParams sets correct param key and value if passed an EQUAL_TO filter within a AND filter");
|
||||||
|
t.eq(params.queryable[1], "foo2",
|
||||||
|
"filterToParams sets correct queryable param if passed a LESS_THAN filter within a AND filter");
|
||||||
|
t.eq(params["foo2__lt"], "baz",
|
||||||
|
"filterToParams sets correct param key and value if passed a LESS_THAN filter within a AND filter");
|
||||||
|
|
||||||
|
// 2 tests
|
||||||
|
protocol = new OpenLayers.Protocol.HTTP({wildcarded: true});
|
||||||
|
filter = new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.LIKE,
|
||||||
|
property: "foo",
|
||||||
|
value: "bar"
|
||||||
|
});
|
||||||
|
params = protocol.filterToParams(filter);
|
||||||
|
t.eq(params.queryable[0], "foo",
|
||||||
|
"filterToParams sets correct queryable param if passed a LIKE filter (wildcarded true)");
|
||||||
|
t.eq(params["foo__ilike"], "%bar%",
|
||||||
|
"filterToParams sets correct param key and value if passed an LIKE filter (wildcarded true)");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_regex2value(t) {
|
||||||
|
t.plan(16);
|
||||||
|
|
||||||
|
// setup
|
||||||
|
|
||||||
|
var protocol = new OpenLayers.Protocol.HTTP();
|
||||||
|
var value;
|
||||||
|
|
||||||
|
// test
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo");
|
||||||
|
t.eq(value, "foo", 'regex2value converts "foo" to "foo"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo%");
|
||||||
|
t.eq(value, "foo\\%", 'regex2value converts "foo%" to "foo\\%"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo.*");
|
||||||
|
t.eq(value, "foo%", 'regex2value converts "foo.*" to "foo%"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("f.*oo.*");
|
||||||
|
t.eq(value, "f%oo%", 'regex2value converts "f.*oo.*" to "f%oo%"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo.");
|
||||||
|
t.eq(value, "foo_", 'regex2value converts "foo." to "foo_"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("f.oo.");
|
||||||
|
t.eq(value, "f_oo_", 'regex2value converts "f.oo." to "f_oo_"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("f.oo.*");
|
||||||
|
t.eq(value, "f_oo%", 'regex2value converts "f.oo.*" to "f_oo%"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo\\\\");
|
||||||
|
t.eq(value, "foo\\\\", 'regex2value converts "foo\\\\" to "foo\\\\"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo\\.");
|
||||||
|
t.eq(value, "foo.", 'regex2value converts "foo\\." to "foo."');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo\\\\.");
|
||||||
|
t.eq(value, "foo\\\\_", 'regex2value converts "foo\\\\." to "foo\\\\_"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo\\*");
|
||||||
|
t.eq(value, "foo*", 'regex2value converts "foo\\*" to "foo*"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo\\\\*");
|
||||||
|
t.eq(value, "foo\\\\*", 'regex2value converts "foo\\\\*" to "foo\\\\*"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("foo\\\\.*");
|
||||||
|
t.eq(value, "foo\\\\%", 'regex2value converts "foo\\\\.*" to "foo\\\\%"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("fo\\.o.*");
|
||||||
|
t.eq(value, "fo.o%", 'regex2value converts from "fo\\.o.*" to "fo.o%"');
|
||||||
|
|
||||||
|
value = protocol.regex2value("fo.*o\\.");
|
||||||
|
t.eq(value, "fo%o.", 'regex2value converts from "fo.*o\\." to "to%o."');
|
||||||
|
|
||||||
|
value = protocol.regex2value("\\*\\..*.\\\\.*\\\\.%");
|
||||||
|
t.eq(value, "*.%_\\\\%\\\\_\\%",
|
||||||
|
'regex2value converts from "\\*\\..*.\\\\.*\\\\.%" ' +
|
||||||
|
'to "*.%_\\\\%\\\\_\\%"');
|
||||||
|
}
|
||||||
|
|
||||||
function test_create(t) {
|
function test_create(t) {
|
||||||
t.plan(10);
|
t.plan(10);
|
||||||
var protocol = new OpenLayers.Protocol.HTTP({
|
var protocol = new OpenLayers.Protocol.HTTP({
|
||||||
@@ -709,7 +994,7 @@
|
|||||||
});
|
});
|
||||||
protocol.read();
|
protocol.read();
|
||||||
|
|
||||||
t.delay_call(0.5, function() {
|
t.delay_call(1, function() {
|
||||||
t.eq(log1.callbackCalled, true, "[read] callback called");
|
t.eq(log1.callbackCalled, true, "[read] callback called");
|
||||||
t.eq(log1.callbackScope, scope, "[read] correct scope");
|
t.eq(log1.callbackScope, scope, "[read] correct scope");
|
||||||
t.ok(log1.request instanceof OpenLayers.Request.XMLHttpRequest, "[read] correct priv type");
|
t.ok(log1.request instanceof OpenLayers.Request.XMLHttpRequest, "[read] correct priv type");
|
||||||
@@ -731,7 +1016,7 @@
|
|||||||
{state: OpenLayers.State.DELETE, url: "./3"},
|
{state: OpenLayers.State.DELETE, url: "./3"},
|
||||||
{state: OpenLayers.State.DELETE, url: "./4"}
|
{state: OpenLayers.State.DELETE, url: "./4"}
|
||||||
]);
|
]);
|
||||||
t.delay_call(0.5, function() {
|
t.delay_call(1, function() {
|
||||||
t.eq(log2.called, 1, "[commit] Callback called once.");
|
t.eq(log2.called, 1, "[commit] Callback called once.");
|
||||||
t.eq(log2.scope, scope, "[commit] Correct scope.");
|
t.eq(log2.scope, scope, "[commit] Correct scope.");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user