Removing the simpleFilterSerializer method on OpenLayers.Protocol in favor of a format for serializing filters for use with query strings. r=sbrunner (closes #3163)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11758 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -3,26 +3,33 @@
|
||||
<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_filterToParams(t) {
|
||||
function test_write(t) {
|
||||
t.plan(30);
|
||||
|
||||
// setup
|
||||
|
||||
var protocol, filter, params;
|
||||
var format, filter, params;
|
||||
|
||||
protocol = new OpenLayers.Protocol.HTTP({
|
||||
filterToParams: OpenLayers.Protocol.simpleFilterSerializer
|
||||
});
|
||||
format = new OpenLayers.Format.QueryStringFilter();
|
||||
|
||||
// 1 test
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
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");
|
||||
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;
|
||||
@@ -31,24 +38,19 @@
|
||||
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");
|
||||
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 = 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");
|
||||
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.
|
||||
|
||||
@@ -67,9 +69,8 @@
|
||||
type: OpenLayers.Filter.Logical.AND,
|
||||
filters: []
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
t.eq(params, {},
|
||||
"filterToParams returns empty object if given empty AND Logical filter");
|
||||
params = format.write(filter);
|
||||
t.eq(params, {}, "returns empty object if given empty AND Logical filter");
|
||||
|
||||
// 1 test
|
||||
filter = new OpenLayers.Filter.Logical({
|
||||
@@ -78,9 +79,8 @@
|
||||
bboxFilter1
|
||||
]
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
t.eq(params, {},
|
||||
"filterToParams does not support OR Logical filter");
|
||||
params = format.write(filter);
|
||||
t.eq(params, {}, "does not support OR Logical filter");
|
||||
|
||||
// 1 test
|
||||
filter = new OpenLayers.Filter.Logical({
|
||||
@@ -89,10 +89,9 @@
|
||||
bboxFilter1
|
||||
]
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.bbox, [0, 0, 10, 10],
|
||||
"filterToParams sets correct bbox param if passed " +
|
||||
"a Logical filter containing a BBOX");
|
||||
"correct bbox param if passed a Logical filter containing a BBOX");
|
||||
|
||||
// 1 test
|
||||
filter = new OpenLayers.Filter.Logical({
|
||||
@@ -101,10 +100,9 @@
|
||||
bboxFilter1, bboxFilter2
|
||||
]
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.bbox, [0, 0, 20, 20],
|
||||
"filterToParams sets correct bbox param if passed " +
|
||||
"multiple BBOX filter in a Logical filter");
|
||||
"correct bbox param if passed multiple BBOX filter in a Logical filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -112,11 +110,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an EQUAL_TO filter");
|
||||
"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");
|
||||
"correct param key and value if passed an EQUAL_TO filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -124,11 +122,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an NOT_EQUAL_TO filter");
|
||||
"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");
|
||||
"correct param key and value if passed an NOT_EQUAL_TO filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -136,11 +134,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
var params = protocol.filterToParams(filter);
|
||||
var params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an LESS_THAN filter");
|
||||
"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");
|
||||
"correct param key and value if passed an LESS_THAN filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -148,11 +146,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
var params = protocol.filterToParams(filter);
|
||||
var params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an LESS_THAN_OR_EQUAL_TO filter");
|
||||
"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");
|
||||
"correct param key and value if passed an LESS_THAN_OR_EQUAL_TO filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -160,11 +158,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an GREATER_THAN filter");
|
||||
"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");
|
||||
"correct param key and value if passed an GREATER_THAN filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -172,11 +170,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an GREATER_THAN_OR_EQUAL_TO filter");
|
||||
"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");
|
||||
"correct param key and value if passed an GREATER_THAN_OR_EQUAL_TO filter");
|
||||
|
||||
// 2 tests
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -184,11 +182,11 @@
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed a LIKE filter");
|
||||
"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");
|
||||
"correct param key and value if passed an LIKE filter");
|
||||
|
||||
// 4 tests
|
||||
filter = new OpenLayers.Filter.Logical({
|
||||
@@ -206,28 +204,28 @@
|
||||
})
|
||||
]
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed an EQUAL_TO filter within a AND filter");
|
||||
"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");
|
||||
"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");
|
||||
"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");
|
||||
"correct param key and value if passed a LESS_THAN filter within a AND filter");
|
||||
|
||||
// 2 tests
|
||||
protocol = new OpenLayers.Protocol.HTTP({wildcarded: true});
|
||||
format = new OpenLayers.Format.QueryStringFilter({wildcarded: true});
|
||||
filter = new OpenLayers.Filter.Comparison({
|
||||
type: OpenLayers.Filter.Comparison.LIKE,
|
||||
property: "foo",
|
||||
value: "bar"
|
||||
});
|
||||
params = protocol.filterToParams(filter);
|
||||
params = format.write(filter);
|
||||
t.eq(params.queryable[0], "foo",
|
||||
"filterToParams sets correct queryable param if passed a LIKE filter (wildcarded true)");
|
||||
"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)");
|
||||
"correct param key and value if passed an LIKE filter (wildcarded true)");
|
||||
}
|
||||
|
||||
function test_regex2value(t) {
|
||||
@@ -235,9 +233,7 @@
|
||||
|
||||
// setup
|
||||
|
||||
var protocol = new OpenLayers.Protocol.HTTP({
|
||||
filterToParams: OpenLayers.Protocol.simpleFilterSerializer
|
||||
});
|
||||
var format = new OpenLayers.Format.QueryStringFilter();
|
||||
|
||||
var value;
|
||||
var filter = new OpenLayers.Filter.Comparison({
|
||||
@@ -247,7 +243,7 @@
|
||||
|
||||
function serialize(value) {
|
||||
filter.value = value;
|
||||
return protocol.filterToParams(filter).prop__ilike;
|
||||
return format.write(filter).prop__ilike;
|
||||
}
|
||||
|
||||
// test
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user