[OpenLayers-Commits] r11064 - in sandbox/tschaub/xdomain: examples
lib lib/OpenLayers/Protocol tests tests/Protocol
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Jan 27 15:49:34 EST 2011
Author: tschaub
Date: 2011-01-27 12:49:34 -0800 (Thu, 27 Jan 2011)
New Revision: 11064
Removed:
sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/FilterSerializer.js
sandbox/tschaub/xdomain/tests/Protocol/FilterSerializer.html
Modified:
sandbox/tschaub/xdomain/examples/cross-origin.js
sandbox/tschaub/xdomain/lib/OpenLayers.js
sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/HTTP.js
sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/Script.js
sandbox/tschaub/xdomain/tests/Protocol/HTTP.html
sandbox/tschaub/xdomain/tests/Protocol/Script.html
sandbox/tschaub/xdomain/tests/list-tests.html
Log:
Addresssing the MapFish specific parts in #3032.
Modified: sandbox/tschaub/xdomain/examples/cross-origin.js
===================================================================
--- sandbox/tschaub/xdomain/examples/cross-origin.js 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/examples/cross-origin.js 2011-01-27 20:49:34 UTC (rev 11064)
@@ -19,6 +19,16 @@
request: "GetFeature",
typeName: "world:cities",
outputFormat: "json"
+ },
+ filterToParams: function(filter, params) {
+ // example to demonstrate BBOX serialization
+ if (filter.type === OpenLayers.Filter.Spatial.BBOX) {
+ params.bbox = filter.value.toArray();
+ if (filter.projection) {
+ params.bbox.push(filter.projection.getCode());
+ }
+ }
+ return params;
}
})
})
Deleted: sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/FilterSerializer.js
===================================================================
--- sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/FilterSerializer.js 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/FilterSerializer.js 2011-01-27 20:49:34 UTC (rev 11064)
@@ -1,133 +0,0 @@
-/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
- * full list of contributors). Published under the Clear BSD license.
- * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
- * full text of the license. */
-
-/**
- * @requires OpenLayers/Protocol.js
- */
-
-/**
- * Class: OpenLayers.Protocol.FilterSerializer
- * A mixin for protocols that need to serialize filter parameters.
- */
-OpenLayers.Protocol.FilterSerializer = {
-
- /**
- * 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();
- if (this.srsInBBOX && filter.projection) {
- params.bbox.push(filter.projection.getCode());
- }
- 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;
- }
-};
Modified: sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/HTTP.js
===================================================================
--- sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/HTTP.js 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/HTTP.js 2011-01-27 20:49:34 UTC (rev 11064)
@@ -109,10 +109,6 @@
this.params = {};
this.headers = {};
OpenLayers.Protocol.prototype.initialize.apply(this, arguments);
-
- if (OpenLayers.Protocol.FilterSerializer) {
- OpenLayers.Util.extend(this, OpenLayers.Protocol.FilterSerializer);
- }
},
/**
@@ -153,7 +149,6 @@
options.params = OpenLayers.Util.applyDefaults(
options.params, this.options.params);
if(options.filter) {
- // requires the OpenLayers.Protocol.FilterSerializer mixin
options.params = this.filterToParams(
options.filter, options.params);
}
@@ -195,6 +190,124 @@
},
/**
+ * 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();
+ if (this.srsInBBOX && filter.projection) {
+ params.bbox.push(filter.projection.getCode());
+ }
+ 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
* Construct a request for writing newly created features.
*
Modified: sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/Script.js
===================================================================
--- sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/Script.js 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/lib/OpenLayers/Protocol/Script.js 2011-01-27 20:49:34 UTC (rev 11064)
@@ -113,9 +113,6 @@
if (!this.format) {
this.format = new OpenLayers.Format.GeoJSON();
}
- if (OpenLayers.Protocol.FilterSerializer) {
- OpenLayers.Util.extend(this, OpenLayers.Protocol.FilterSerializer);
- }
},
/**
@@ -144,8 +141,7 @@
options.params = OpenLayers.Util.applyDefaults(
options.params, this.options.params
);
- if (options.filter) {
- // requires the OpenLayers.Protocol.FilterSerializer mixin
+ if (options.filter && this.filterToParams) {
options.params = this.filterToParams(
options.filter, options.params
);
@@ -156,14 +152,28 @@
options.params,
OpenLayers.Function.bind(function(data) {
response.data = data;
- this.handleRead(response, options)
+ this.handleRead(response, options);
}, this)
);
response.priv = request;
return response;
},
-
+
/**
+ * APIMethod: filterToParams
+ * Optional method to translate an <OpenLayers.Filter> object into an object
+ * that can be serialized as request query string provided. If a custom
+ * method is not provided, any filter will not be serialized.
+ *
+ * Parameters:
+ * filter - {<OpenLayers.Filter>} filter to convert.
+ * params - {Object} The parameters object.
+ *
+ * Returns:
+ * {Object} The resulting parameters object.
+ */
+
+ /**
* Method: createRequest
* Issues a request for features by creating injecting a script in the
* document head.
@@ -343,6 +353,6 @@
var callback = registry[id];
o.unregister(id);
return callback;
- };
+ };
})();
Modified: sandbox/tschaub/xdomain/lib/OpenLayers.js
===================================================================
--- sandbox/tschaub/xdomain/lib/OpenLayers.js 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/lib/OpenLayers.js 2011-01-27 20:49:34 UTC (rev 11064)
@@ -215,7 +215,6 @@
"OpenLayers/Filter/Comparison.js",
"OpenLayers/Filter/Spatial.js",
"OpenLayers/Protocol.js",
- "OpenLayers/Protocol/FilterSerializer.js",
"OpenLayers/Protocol/HTTP.js",
"OpenLayers/Protocol/Script.js",
"OpenLayers/Protocol/SQL.js",
Deleted: sandbox/tschaub/xdomain/tests/Protocol/FilterSerializer.html
===================================================================
--- sandbox/tschaub/xdomain/tests/Protocol/FilterSerializer.html 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/tests/Protocol/FilterSerializer.html 2011-01-27 20:49:34 UTC (rev 11064)
@@ -1,296 +0,0 @@
-<html>
-<head>
- <script src="../../lib/OpenLayers.js"></script>
- <script type="text/javascript">
-
-
- function test_filterToParams(t) {
- t.plan(30);
-
- // setup
-
- var protocol, filter, params;
-
- protocol = OpenLayers.Protocol.FilterSerializer;
-
- // 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 "*.%_\\\\%\\\\_\\%"');
- }
-
- </script>
-</head>
-<body>
-</body>
-</html>
Modified: sandbox/tschaub/xdomain/tests/Protocol/HTTP.html
===================================================================
--- sandbox/tschaub/xdomain/tests/Protocol/HTTP.html 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/tests/Protocol/HTTP.html 2011-01-27 20:49:34 UTC (rev 11064)
@@ -287,6 +287,291 @@
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) {
t.plan(10);
var protocol = new OpenLayers.Protocol.HTTP({
Modified: sandbox/tschaub/xdomain/tests/Protocol/Script.html
===================================================================
--- sandbox/tschaub/xdomain/tests/Protocol/Script.html 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/tests/Protocol/Script.html 2011-01-27 20:49:34 UTC (rev 11064)
@@ -92,25 +92,6 @@
'response priv property set to what the createRequest method returns');
}
- function test_read_bbox(t) {
- t.plan(1);
- var protocol = new OpenLayers.Protocol.Script();
-
- var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
- var filter = new OpenLayers.Filter.Spatial({
- type: OpenLayers.Filter.Spatial.BBOX,
- value: bounds,
- projection: "foo"
- });
-
- protocol.createRequest = function(url, params, callback) {
- t.eq(params['bbox'].toString(), bounds.toArray().toString(),
- 'createRequest called with bbox filter in params');
- };
-
- var resp = protocol.read({filter: filter});
- }
-
function test_createRequest(t) {
t.plan(3);
var protocol = new OpenLayers.Protocol.Script({
Modified: sandbox/tschaub/xdomain/tests/list-tests.html
===================================================================
--- sandbox/tschaub/xdomain/tests/list-tests.html 2011-01-27 20:43:53 UTC (rev 11063)
+++ sandbox/tschaub/xdomain/tests/list-tests.html 2011-01-27 20:49:34 UTC (rev 11064)
@@ -168,7 +168,6 @@
<li>Popup/FramedCloud.html</li>
<li>Projection.html</li>
<li>Protocol.html</li>
- <li>Protocol/FilterSerializer.html</li>
<li>Protocol/HTTP.html</li>
<li>Protocol/Script.html</li>
<li>Protocol/SQL.html</li>
More information about the Commits
mailing list