Pullup commits from trunk to 2.6 branch:
* virtualStyle typo (Closes #1495) * JSON fix for Safari 3.1 (Closes #1493) * panzoombar off-by-one (Closes #1486) * Handler Hover exception (Closes #1480) * Popup.framedcloud exception (Closes #1479) * VML Renderer when including namespace in page (Closes #1477) * SLD/Rule/Filter changes -- most of this commit (Closes #1492) git-svn-id: http://svn.openlayers.org/branches/openlayers/2.6@6819 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
99
tests/Filter/Comparison.html
Normal file
99
tests/Filter/Comparison.html
Normal file
@@ -0,0 +1,99 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_Comparison_constructor(t) {
|
||||
t.plan(3);
|
||||
|
||||
var options = {'foo': 'bar'};
|
||||
var filter = new OpenLayers.Filter.Comparison(options);
|
||||
t.ok(filter instanceof OpenLayers.Filter.Comparison,
|
||||
"new OpenLayers.Filter.Comparison returns object" );
|
||||
t.eq(filter.foo, "bar", "constructor sets options correctly");
|
||||
t.eq(typeof filter.evaluate, "function", "filter has an evaluate function");
|
||||
}
|
||||
|
||||
function test_Comparison_destroy(t) {
|
||||
t.plan(1);
|
||||
|
||||
var filter = new OpenLayers.Filter.Comparison();
|
||||
filter.destroy();
|
||||
t.eq(filter.symbolizer, null, "symbolizer hash nulled properly");
|
||||
}
|
||||
|
||||
function test_Comparison_value2regex(t) {
|
||||
t.plan(2);
|
||||
|
||||
var filter = new OpenLayers.Filter.Comparison({
|
||||
property: "foo",
|
||||
value: "*b?r\\*\\?*",
|
||||
type: OpenLayers.Filter.Comparison.LIKE});
|
||||
filter.value2regex("*", "?", "\\");
|
||||
t.eq(filter.value, ".*b.r\\*\\?.*", "Regular expression generated correctly.");
|
||||
|
||||
filter.value = "%b.r!%!.%";
|
||||
filter.value2regex("%", ".", "!");
|
||||
t.eq(filter.value, ".*b.r\\%\\..*", "Regular expression with different wildcard and escape chars generated correctly.");
|
||||
}
|
||||
|
||||
function test_regex2value(t) {
|
||||
t.plan(8);
|
||||
|
||||
function r2v(regex) {
|
||||
return OpenLayers.Filter.Comparison.prototype.regex2value.call(
|
||||
{value: regex}
|
||||
);
|
||||
}
|
||||
|
||||
t.eq(r2v("foo"), "foo", "doesn't change string without special chars");
|
||||
t.eq(r2v("foo.*foo"), "foo*foo", "wildCard replaced");
|
||||
t.eq(r2v("foo.foo"), "foo.foo", "singleChar replaced");
|
||||
t.eq(r2v("foo\\\\foo"), "foo\\foo", "escape removed");
|
||||
t.eq(r2v("foo!foo"), "foo!!foo", "escapes !");
|
||||
t.eq(r2v("foo\\*foo"), "foo!*foo", "replaces escape on *");
|
||||
t.eq(r2v("foo\\.foo"), "foo!.foo", "replaces escape on .");
|
||||
t.eq(r2v("foo\\\\.foo"), "foo\\.foo", "unescapes only \\ before .");
|
||||
|
||||
}
|
||||
|
||||
function test_Comparison_evaluate(t) {
|
||||
t.plan(5);
|
||||
|
||||
var filter = new OpenLayers.Filter.Comparison({
|
||||
property: "area",
|
||||
lowerBoundary: 1000,
|
||||
upperBoundary: 4999,
|
||||
type: OpenLayers.Filter.Comparison.BETWEEN});
|
||||
|
||||
var features = [
|
||||
new OpenLayers.Feature.Vector(null, {
|
||||
area: 999}),
|
||||
new OpenLayers.Feature.Vector(null, {
|
||||
area: 1000}),
|
||||
new OpenLayers.Feature.Vector(null, {
|
||||
area: 4999}),
|
||||
new OpenLayers.Feature.Vector(null, {
|
||||
area: 5000})];
|
||||
// PropertyIsBetween filter: lower and upper boundary are inclusive
|
||||
var filterResults = {
|
||||
0: false,
|
||||
1: true,
|
||||
2: true,
|
||||
3: false};
|
||||
for (var i in filterResults) {
|
||||
var result = filter.evaluate(features[i].attributes);
|
||||
t.eq(result, filterResults[i], "feature "+i+
|
||||
" evaluates to "+result.toString()+" correctly.");
|
||||
}
|
||||
var context = {
|
||||
area: 4998
|
||||
};
|
||||
var result = filter.evaluate(context);
|
||||
t.eq(result, true, "evaluation against custom filter context works.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
47
tests/Filter/FeatureId.html
Normal file
47
tests/Filter/FeatureId.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_FeatureId_constructor(t) {
|
||||
t.plan(3);
|
||||
|
||||
var options = {'foo': 'bar'};
|
||||
var filter = new OpenLayers.Filter.FeatureId(options);
|
||||
t.ok(filter instanceof OpenLayers.Filter.FeatureId,
|
||||
"new OpenLayers.Filter.FeatureId returns object" );
|
||||
t.eq(filter.foo, "bar", "constructor sets options correctly");
|
||||
t.eq(typeof filter.evaluate, "function", "filter has an evaluate function");
|
||||
}
|
||||
|
||||
function test_FeatureId_destroy(t) {
|
||||
t.plan(1);
|
||||
|
||||
var filter = new OpenLayers.Filter.FeatureId();
|
||||
filter.destroy();
|
||||
t.eq(filter.symbolizer, null, "symbolizer hash nulled properly");
|
||||
}
|
||||
|
||||
function test_FeatureId_evaluate(t) {
|
||||
t.plan(3);
|
||||
|
||||
var filter = new OpenLayers.Filter.FeatureId(
|
||||
{fids: ["fid_1", "fid_3"]});
|
||||
|
||||
var filterResults = {
|
||||
"fid_1" : true,
|
||||
"fid_2" : false,
|
||||
"fid_3" : true};
|
||||
for (var i in filterResults) {
|
||||
var feature = new OpenLayers.Feature.Vector();
|
||||
feature.fid = i;
|
||||
var result = filter.evaluate(feature);
|
||||
t.eq(result, filterResults[i], "feature "+i+" evaluates to "+result.toString()+" correctly.");
|
||||
feature.destroy();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
41
tests/Filter/Logical.html
Normal file
41
tests/Filter/Logical.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_Logical_constructor(t) {
|
||||
t.plan(3);
|
||||
|
||||
var options = {'foo': 'bar'};
|
||||
var filter = new OpenLayers.Filter.Logical(options);
|
||||
t.ok(filter instanceof OpenLayers.Filter.Logical,
|
||||
"new OpenLayers.Filter.Logical returns object" );
|
||||
t.eq(filter.foo, "bar", "constructor sets options correctly");
|
||||
t.eq(typeof filter.evaluate, "function", "filter has an evaluate function");
|
||||
}
|
||||
|
||||
function test_Logical_destroy(t) {
|
||||
t.plan(1);
|
||||
|
||||
var filter = new OpenLayers.Filter.Logical();
|
||||
filter.destroy();
|
||||
t.eq(filter.filters, null, "filters array nulled properly");
|
||||
}
|
||||
|
||||
function test_Logical_evaluate(t) {
|
||||
t.plan(1);
|
||||
|
||||
var filter = new OpenLayers.Filter.Logical({
|
||||
type: OpenLayers.Filter.Logical.NOT});
|
||||
filter.filters.push(new OpenLayers.Filter());
|
||||
|
||||
var feature = new OpenLayers.Feature.Vector();
|
||||
|
||||
t.eq(filter.evaluate(feature.attributes), false,
|
||||
"feature evaluates to false correctly.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user