[OpenLayers-Commits] r11758 - in trunk/openlayers: lib lib/OpenLayers/Format lib/OpenLayers/Protocol tests tests/Format tests/Protocol

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Mar 29 15:22:17 EDT 2011


Author: tschaub
Date: 2011-03-29 12:22:13 -0700 (Tue, 29 Mar 2011)
New Revision: 11758

Added:
   trunk/openlayers/lib/OpenLayers/Format/QueryStringFilter.js
   trunk/openlayers/tests/Format/QueryStringFilter.html
Removed:
   trunk/openlayers/lib/OpenLayers/Protocol/SimpleFilterSerializer.js
   trunk/openlayers/tests/Protocol/SimpleFilterSerializer.html
Modified:
   trunk/openlayers/lib/OpenLayers.js
   trunk/openlayers/lib/OpenLayers/Protocol/HTTP.js
   trunk/openlayers/lib/OpenLayers/Protocol/Script.js
   trunk/openlayers/tests/list-tests.html
Log:
Removing the simpleFilterSerializer method on OpenLayers.Protocol in favor of a format for serializing filters for use with query strings.  r=sbrunner (closes #3163)

Added: trunk/openlayers/lib/OpenLayers/Format/QueryStringFilter.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/QueryStringFilter.js	                        (rev 0)
+++ trunk/openlayers/lib/OpenLayers/Format/QueryStringFilter.js	2011-03-29 19:22:13 UTC (rev 11758)
@@ -0,0 +1,180 @@
+/* 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/Format.js
+ * @requires OpenLayers/Filter/Comparison.js
+ */
+
+/**
+ * Class: OpenLayers.Format.QueryStringFilter
+ * Parser for reading a query string and creating a simple filter.
+ *
+ * Inherits from:
+ *  - <OpenLayers.Format>
+ */
+OpenLayers.Format.QueryStringFilter = (function() {
+
+    /** 
+     * Map the OpenLayers.Filter.Comparison types to the operation strings of 
+     * the protocol.
+     */
+    var cmpToStr = {};
+    cmpToStr[OpenLayers.Filter.Comparison.EQUAL_TO] = "eq";
+    cmpToStr[OpenLayers.Filter.Comparison.NOT_EQUAL_TO] = "ne";
+    cmpToStr[OpenLayers.Filter.Comparison.LESS_THAN] = "lt";
+    cmpToStr[OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO] = "lte";
+    cmpToStr[OpenLayers.Filter.Comparison.GREATER_THAN] = "gt";
+    cmpToStr[OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO] = "gte";
+    cmpToStr[OpenLayers.Filter.Comparison.LIKE] = "ilike";
+
+    /**
+     * Function: 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.
+     */
+    function regex2value(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;
+    }
+    
+    return OpenLayers.Class(OpenLayers.Format, {
+        
+        /**
+         * 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,
+
+        /**
+         * APIProperty: srsInBBOX
+         * {Boolean} Include the SRS identifier in BBOX query string parameter.  
+         *     Default is false.  If true and the layer has a projection object set,
+         *     any BBOX filter will be serialized with a fifth item identifying the
+         *     projection.  E.g. bbox=-1000,-1000,1000,1000,EPSG:900913
+         */
+        srsInBBOX: false,
+
+        /**
+         * APIMethod: write
+         * Serialize an <OpenLayers.Filter> objects using the "simple" filter syntax for 
+         *     query string parameters.  This function must be called as a method of
+         *     a protocol instance.
+         *
+         * Parameters:
+         * filter - {<OpenLayers.Filter>} filter to convert.
+         * params - {Object} The parameters object.
+         *
+         * Returns:
+         * {Object} The resulting parameters object.
+         */
+        write: 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 = cmpToStr[filter.type];
+                    if (op !== undefined) {
+                        var value = filter.value;
+                        if (filter.type == OpenLayers.Filter.Comparison.LIKE) {
+                            value = 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.write(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;
+        },
+        
+        CLASS_NAME: "OpenLayers.Format.QueryStringFilter"
+        
+    });
+
+
+})();
\ No newline at end of file

Modified: trunk/openlayers/lib/OpenLayers/Protocol/HTTP.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/HTTP.js	2011-03-29 19:04:40 UTC (rev 11757)
+++ trunk/openlayers/lib/OpenLayers/Protocol/HTTP.js	2011-03-29 19:22:13 UTC (rev 11758)
@@ -15,7 +15,7 @@
 
 /**
  * TODO: remove this dependency in 3.0
- * @requires OpenLayers/Protocol/SimpleFilterSerializer.js
+ * @requires OpenLayers/Format/QueryStringFilter.js
  */
 
 /**
@@ -115,10 +115,14 @@
         this.headers = {};
         OpenLayers.Protocol.prototype.initialize.apply(this, arguments);
 
-        if (!this.filterToParams && OpenLayers.Protocol.simpleFilterSerializer) {
-            this.filterToParams = OpenLayers.Function.bind(
-                OpenLayers.Protocol.simpleFilterSerializer, this
-            );
+        if (!this.filterToParams && OpenLayers.Format.QueryStringFilter) {
+            var format = new OpenLayers.Format.QueryStringFilter({
+                wildcarded: this.wildcarded,
+                srsInBBOX: this.srsInBBOX
+            });
+            this.filterToParams = function(filter, params) {
+                return format.write(filter, params);
+            }
         }
     },
     
@@ -146,7 +150,7 @@
      * Returns:
      * {Object} The resulting parameters object.
      */
-
+    
     /**
      * APIMethod: read
      * Construct a request for reading new features.

Modified: trunk/openlayers/lib/OpenLayers/Protocol/Script.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/Script.js	2011-03-29 19:04:40 UTC (rev 11757)
+++ trunk/openlayers/lib/OpenLayers/Protocol/Script.js	2011-03-29 19:22:13 UTC (rev 11758)
@@ -91,6 +91,17 @@
     pendingRequests: null,
 
     /**
+     * APIProperty: srsInBBOX
+     * {Boolean} Include the SRS identifier in BBOX query string parameter.
+     *     Setting this property has no effect if a custom filterToParams method
+     *     is provided.   Default is false.  If true and the layer has a 
+     *     projection object set, any BBOX filter will be serialized with a 
+     *     fifth item identifying the projection.  
+     *     E.g. bbox=-1000,-1000,1000,1000,EPSG:900913
+     */
+    srsInBBOX: false,
+
+    /**
      * Constructor: OpenLayers.Protocol.Script
      * A class for giving layers generic Script protocol.
      *
@@ -113,10 +124,13 @@
             this.format = new OpenLayers.Format.GeoJSON();
         }
 
-        if (!this.filterToParams && OpenLayers.Protocol.simpleFilterSerializer) {
-            this.filterToParams = OpenLayers.Function.bind(
-                OpenLayers.Protocol.simpleFilterSerializer, this
-            );
+        if (!this.filterToParams && OpenLayers.Format.QueryStringFilter) {
+            var format = new OpenLayers.Format.QueryStringFilter({
+                srsInBBOX: this.srsInBBOX
+            });
+            this.filterToParams = function(filter, params) {
+                return format.write(filter, params);
+            }
         }
     },
     

Deleted: trunk/openlayers/lib/OpenLayers/Protocol/SimpleFilterSerializer.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/SimpleFilterSerializer.js	2011-03-29 19:04:40 UTC (rev 11757)
+++ trunk/openlayers/lib/OpenLayers/Protocol/SimpleFilterSerializer.js	2011-03-29 19:22:13 UTC (rev 11758)
@@ -1,145 +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
- */
-
-/**
- * Function: OpenLayers.Protocol.simpleFilterSerializer
- * Serialize an <OpenLayers.Filter> objects using the "simple" filter syntax for 
- *     query string parameters.  This function must be called as a method of
- *     a protocol instance.
- *
- * Parameters:
- * filter - {<OpenLayers.Filter>} filter to convert.
- * params - {Object} The parameters object.
- *
- * Returns:
- * {Object} The resulting parameters object.
- */
-OpenLayers.Protocol.simpleFilterSerializer = (function() {
-
-    /** 
-     * Map the OpenLayers.Filter.Comparison types to the operation strings of 
-     * the protocol.
-     */
-    var cmpToStr = {};
-    cmpToStr[OpenLayers.Filter.Comparison.EQUAL_TO] = "eq";
-    cmpToStr[OpenLayers.Filter.Comparison.NOT_EQUAL_TO] = "ne";
-    cmpToStr[OpenLayers.Filter.Comparison.LESS_THAN] = "lt";
-    cmpToStr[OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO] = "lte";
-    cmpToStr[OpenLayers.Filter.Comparison.GREATER_THAN] = "gt";
-    cmpToStr[OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO] = "gte";
-    cmpToStr[OpenLayers.Filter.Comparison.LIKE] = "ilike";
-
-    /**
-     * Function: 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.
-     */
-    function regex2value(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;
-    }
-
-    return function simpleFilterSerializer(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 = cmpToStr[filter.type];
-                if (op !== undefined) {
-                    var value = filter.value;
-                    if (filter.type == OpenLayers.Filter.Comparison.LIKE) {
-                        value = 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;
-    };
-    
-})();

Modified: trunk/openlayers/lib/OpenLayers.js
===================================================================
--- trunk/openlayers/lib/OpenLayers.js	2011-03-29 19:04:40 UTC (rev 11757)
+++ trunk/openlayers/lib/OpenLayers.js	2011-03-29 19:22:13 UTC (rev 11758)
@@ -247,7 +247,6 @@
                 "OpenLayers/Filter/Function.js",                
                 "OpenLayers/Protocol.js",
                 "OpenLayers/Protocol/HTTP.js",
-                "OpenLayers/Protocol/SimpleFilterSerializer.js",
                 "OpenLayers/Protocol/SQL.js",
                 "OpenLayers/Protocol/SQL/Gears.js",
                 "OpenLayers/Protocol/WFS.js",
@@ -264,6 +263,7 @@
                 "OpenLayers/StyleMap.js",
                 "OpenLayers/Rule.js",
                 "OpenLayers/Format.js",
+                "OpenLayers/Format/QueryStringFilter.js",
                 "OpenLayers/Format/XML.js",
                 "OpenLayers/Format/Context.js",
                 "OpenLayers/Format/ArcXML.js",

Added: trunk/openlayers/tests/Format/QueryStringFilter.html
===================================================================
--- trunk/openlayers/tests/Format/QueryStringFilter.html	                        (rev 0)
+++ trunk/openlayers/tests/Format/QueryStringFilter.html	2011-03-29 19:22:13 UTC (rev 11758)
@@ -0,0 +1,306 @@
+<html>
+<head>
+  <script src="../../lib/OpenLayers.js"></script>
+  <script type="text/javascript">
+
+    function test_constructor(t) {
+        t.plan(4);
+        var options = {'foo': 'bar'};
+        var format  = new OpenLayers.Format.QueryStringFilter(options);
+        t.ok(format instanceof OpenLayers.Format.QueryStringFilter,
+           "new OpenLayers.Format.QueryStringFilter object");
+        t.eq(format.foo, "bar", "constructor sets options correctly")
+        t.eq(typeof format.write, 'function', 'format has a write function');
+        t.eq(format.options, options, "format.options correctly set");
+    }
+
+    function test_write(t) {
+        t.plan(30);
+
+        // setup
+
+        var format, filter, params;
+
+        format = new OpenLayers.Format.QueryStringFilter();
+
+        // 1 test
+        filter = new OpenLayers.Filter.Spatial({
+            type: OpenLayers.Filter.Spatial.BBOX,
+            value: new OpenLayers.Bounds(0, 1, 2, 3)
+        });
+        params = format.write(filter);
+        t.eq(params.bbox, [0, 1, 2, 3], "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 = format.write(filter);
+        t.eq(params.lon, lon, "correct lon param if passed a DWITHIN filter");
+        t.eq(params.lat, lat, "correct lat param if passed a DWITHIN filter");
+        t.eq(params.tolerance, tolerance, "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 = format.write(filter);
+        t.eq(params.lon, lon, "correct lon param if passed a WITHIN filter");
+        t.eq(params.lat, lat, "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 = format.write(filter);
+        t.eq(params, {}, "returns empty object if given empty AND Logical filter");
+
+        // 1 test
+        filter = new OpenLayers.Filter.Logical({
+            type: OpenLayers.Filter.Logical.OR,
+            filters: [
+                bboxFilter1
+            ]
+        });
+        params = format.write(filter);
+        t.eq(params, {}, "does not support OR Logical filter");
+
+        // 1 test
+        filter = new OpenLayers.Filter.Logical({
+            type: OpenLayers.Filter.Logical.AND,
+            filters: [
+                bboxFilter1
+            ]
+        });
+        params = format.write(filter);
+        t.eq(params.bbox, [0, 0, 10, 10],
+             "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 = format.write(filter);
+        t.eq(params.bbox, [0, 0, 20, 20],
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an EQUAL_TO filter");
+        t.eq(params["foo__eq"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an NOT_EQUAL_TO filter");
+        t.eq(params["foo__ne"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an LESS_THAN filter");
+        t.eq(params["foo__lt"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an LESS_THAN_OR_EQUAL_TO filter");
+        t.eq(params["foo__lte"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an GREATER_THAN filter");
+        t.eq(params["foo__gt"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an GREATER_THAN_OR_EQUAL_TO filter");
+        t.eq(params["foo__gte"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed a LIKE filter");
+        t.eq(params["foo__ilike"], "bar",
+             "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 = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed an EQUAL_TO filter within a AND filter");
+        t.eq(params["foo__eq"], "bar",
+             "correct param key and value if passed an EQUAL_TO filter within a AND filter");
+        t.eq(params.queryable[1], "foo2",
+             "correct queryable param if passed a LESS_THAN filter within a AND filter");
+        t.eq(params["foo2__lt"], "baz",
+             "correct param key and value if passed a LESS_THAN filter within a AND filter");
+
+        // 2 tests
+        format = new OpenLayers.Format.QueryStringFilter({wildcarded: true});
+        filter = new OpenLayers.Filter.Comparison({
+            type: OpenLayers.Filter.Comparison.LIKE,
+            property: "foo",
+            value: "bar"
+        });
+        params = format.write(filter);
+        t.eq(params.queryable[0], "foo",
+             "correct queryable param if passed a LIKE filter (wildcarded true)");
+        t.eq(params["foo__ilike"], "%bar%",
+             "correct param key and value if passed an LIKE filter (wildcarded true)");
+    }
+
+    function test_regex2value(t) {
+        t.plan(16);
+
+        // setup
+
+        var format = new OpenLayers.Format.QueryStringFilter();
+
+        var value;
+        var filter = new OpenLayers.Filter.Comparison({
+            type: OpenLayers.Filter.Comparison.LIKE,
+            property: "prop"
+        });
+        
+        function serialize(value) {
+            filter.value = value;
+            return format.write(filter).prop__ilike;
+        }
+
+        // test
+
+        value = serialize("foo");
+        t.eq(value, "foo", 'regex2value converts "foo" to "foo"');
+
+        value = serialize("foo%");
+        t.eq(value, "foo\\%", 'regex2value converts "foo%" to "foo\\%"');
+
+        value = serialize("foo.*");
+        t.eq(value, "foo%", 'regex2value converts "foo.*" to "foo%"');
+
+        value = serialize("f.*oo.*");
+        t.eq(value, "f%oo%", 'regex2value converts "f.*oo.*" to "f%oo%"');
+
+        value = serialize("foo.");
+        t.eq(value, "foo_", 'regex2value converts "foo." to "foo_"');
+
+        value = serialize("f.oo.");
+        t.eq(value, "f_oo_", 'regex2value converts "f.oo." to "f_oo_"');
+
+        value = serialize("f.oo.*");
+        t.eq(value, "f_oo%", 'regex2value converts "f.oo.*" to "f_oo%"');
+
+        value = serialize("foo\\\\");
+        t.eq(value, "foo\\\\", 'regex2value converts "foo\\\\" to "foo\\\\"');
+
+        value = serialize("foo\\.");
+        t.eq(value, "foo.", 'regex2value converts "foo\\." to "foo."');
+
+        value = serialize("foo\\\\.");
+        t.eq(value, "foo\\\\_", 'regex2value converts "foo\\\\." to "foo\\\\_"');
+
+        value = serialize("foo\\*");
+        t.eq(value, "foo*", 'regex2value converts "foo\\*" to "foo*"');
+
+        value = serialize("foo\\\\*");
+        t.eq(value, "foo\\\\*", 'regex2value converts "foo\\\\*" to "foo\\\\*"');
+
+        value = serialize("foo\\\\.*");
+        t.eq(value, "foo\\\\%", 'regex2value converts "foo\\\\.*" to "foo\\\\%"');
+
+        value = serialize("fo\\.o.*");
+        t.eq(value, "fo.o%", 'regex2value converts from "fo\\.o.*" to "fo.o%"');
+
+        value = serialize("fo.*o\\.");
+        t.eq(value, "fo%o.", 'regex2value converts from "fo.*o\\." to "to%o."');
+
+        value = serialize("\\*\\..*.\\\\.*\\\\.%");
+        t.eq(value, "*.%_\\\\%\\\\_\\%",
+             'regex2value converts from "\\*\\..*.\\\\.*\\\\.%" ' +
+             'to "*.%_\\\\%\\\\_\\%"');
+    }
+
+  </script>
+</head>
+<body>
+</body>
+</html>

Deleted: trunk/openlayers/tests/Protocol/SimpleFilterSerializer.html
===================================================================
--- trunk/openlayers/tests/Protocol/SimpleFilterSerializer.html	2011-03-29 19:04:40 UTC (rev 11757)
+++ trunk/openlayers/tests/Protocol/SimpleFilterSerializer.html	2011-03-29 19:22:13 UTC (rev 11758)
@@ -1,310 +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 = new OpenLayers.Protocol.HTTP({
-            filterToParams: OpenLayers.Protocol.simpleFilterSerializer
-        });
-
-        // 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({
-            filterToParams: OpenLayers.Protocol.simpleFilterSerializer
-        });
-
-        var value;
-        var filter = new OpenLayers.Filter.Comparison({
-            type: OpenLayers.Filter.Comparison.LIKE,
-            property: "prop"
-        });
-        
-        function serialize(value) {
-            filter.value = value;
-            return protocol.filterToParams(filter).prop__ilike;
-        }
-
-        // test
-
-        value = serialize("foo");
-        t.eq(value, "foo", 'regex2value converts "foo" to "foo"');
-
-        value = serialize("foo%");
-        t.eq(value, "foo\\%", 'regex2value converts "foo%" to "foo\\%"');
-
-        value = serialize("foo.*");
-        t.eq(value, "foo%", 'regex2value converts "foo.*" to "foo%"');
-
-        value = serialize("f.*oo.*");
-        t.eq(value, "f%oo%", 'regex2value converts "f.*oo.*" to "f%oo%"');
-
-        value = serialize("foo.");
-        t.eq(value, "foo_", 'regex2value converts "foo." to "foo_"');
-
-        value = serialize("f.oo.");
-        t.eq(value, "f_oo_", 'regex2value converts "f.oo." to "f_oo_"');
-
-        value = serialize("f.oo.*");
-        t.eq(value, "f_oo%", 'regex2value converts "f.oo.*" to "f_oo%"');
-
-        value = serialize("foo\\\\");
-        t.eq(value, "foo\\\\", 'regex2value converts "foo\\\\" to "foo\\\\"');
-
-        value = serialize("foo\\.");
-        t.eq(value, "foo.", 'regex2value converts "foo\\." to "foo."');
-
-        value = serialize("foo\\\\.");
-        t.eq(value, "foo\\\\_", 'regex2value converts "foo\\\\." to "foo\\\\_"');
-
-        value = serialize("foo\\*");
-        t.eq(value, "foo*", 'regex2value converts "foo\\*" to "foo*"');
-
-        value = serialize("foo\\\\*");
-        t.eq(value, "foo\\\\*", 'regex2value converts "foo\\\\*" to "foo\\\\*"');
-
-        value = serialize("foo\\\\.*");
-        t.eq(value, "foo\\\\%", 'regex2value converts "foo\\\\.*" to "foo\\\\%"');
-
-        value = serialize("fo\\.o.*");
-        t.eq(value, "fo.o%", 'regex2value converts from "fo\\.o.*" to "fo.o%"');
-
-        value = serialize("fo.*o\\.");
-        t.eq(value, "fo%o.", 'regex2value converts from "fo.*o\\." to "to%o."');
-
-        value = serialize("\\*\\..*.\\\\.*\\\\.%");
-        t.eq(value, "*.%_\\\\%\\\\_\\%",
-             'regex2value converts from "\\*\\..*.\\\\.*\\\\.%" ' +
-             'to "*.%_\\\\%\\\\_\\%"');
-    }
-
-  </script>
-</head>
-<body>
-</body>
-</html>

Modified: trunk/openlayers/tests/list-tests.html
===================================================================
--- trunk/openlayers/tests/list-tests.html	2011-03-29 19:04:40 UTC (rev 11757)
+++ trunk/openlayers/tests/list-tests.html	2011-03-29 19:22:13 UTC (rev 11758)
@@ -74,6 +74,7 @@
     <li>Format/Filter/v1.html</li>
     <li>Format/Filter/v1_0_0.html</li>
     <li>Format/Filter/v1_1_0.html</li>
+    <li>Format/QueryStringFilter.html</li>
     <li>Format/WFS.html</li>
     <li>Format/WFSCapabilities.html</li>
     <li>Format/WFSCapabilities/v1.html</li>
@@ -179,7 +180,6 @@
     <li>Protocol.html</li>
     <li>Protocol/HTTP.html</li>
     <li>Protocol/Script.html</li>
-    <li>Protocol/SimpleFilterSerializer.html</li>
     <li>Protocol/SQL.html</li>
     <li>Protocol/SQL/Gears.html</li>
     <li>Protocol/WFS.html</li>



More information about the Commits mailing list