Adding support for cloning rules and filters. r=ahocevar (closes #1919)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9071 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-03-17 16:08:12 +00:00
parent 7fa74f1b0b
commit 576e931dac
11 changed files with 241 additions and 3 deletions
+23
View File
@@ -175,6 +175,29 @@
}
}
function test_clone(t) {
t.plan(3);
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "prop",
value: "val"
});
var clone = filter.clone();
// modify the original
filter.type = OpenLayers.Filter.Comparison.NOT_EQUAL_TO;
t.eq(clone.type, OpenLayers.Filter.Comparison.EQUAL_TO, "clone has proper type");
t.eq(clone.property, "prop", "clone has proper property");
t.eq(clone.value, "val", "clone has proper value");
filter.destroy();
}
</script>
+20
View File
@@ -40,6 +40,26 @@
feature.destroy();
}
}
function test_clone(t) {
t.plan(1);
var filter = new OpenLayers.Filter.FeatureId({
fids: [1, 2, 3]
});
var clone = filter.clone();
// modify the original
filter.fids.push(4);
t.eq(clone.fids.length, 3, "clone has proper fids length");
filter.destroy();
}
</script>
</head>
<body>
+34
View File
@@ -34,6 +34,40 @@
t.eq(filter.evaluate(feature.attributes), false,
"feature evaluates to false correctly.");
}
function test_clone(t) {
t.plan(2);
var filter = new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.AND,
filters: [
new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "prop1",
value: "val1"
}),
new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
property: "prop2",
value: "val2"
})
]
});
var clone = filter.clone();
// modify the original
filter.type = OpenLayers.Filter.Logical.OR;
filter.filters[0].value = "nada";
t.eq(clone.type, OpenLayers.Filter.Logical.AND, "clone has proper type");
t.eq(clone.filters[0].value, "val1", "clone has cloned child filters");
filter.destroy();
}
</script>
</head>
<body>
+25
View File
@@ -71,6 +71,31 @@
t.eq(res, false,
"evaluates returns correct value when feature does not intersect bounds");
}
function test_clone(t) {
t.plan(2);
var bounds = new OpenLayers.Bounds(0, 0, 10, 10);
var filter = new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.BBOX,
value: bounds
});
var clone = filter.clone();
// modify the original
filter.value.bottom = -100;
t.eq(clone.type, OpenLayers.Filter.Spatial.BBOX, "clone has proper type");
t.eq(clone.value.toBBOX(), "0,0,10,10", "clone has proper value");
filter.destroy();
clone.destroy();
}
</script>
</head>
<body>
+43
View File
@@ -40,6 +40,49 @@
t.eq(context.foobar, "world", "value returned by getContext is correct"
+ " if a context is given in constructor options");
}
function test_clone(t) {
t.plan(7);
var rule = new OpenLayers.Rule({
name: "test rule",
minScaleDenominator: 10,
maxScaleDenominator: 20,
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "prop",
value: "value"
}),
symbolizer: {
fillColor: "black"
},
context: {
foo: "bar"
}
});
var clone = rule.clone();
t.eq(clone.name, "test rule", "name copied");
t.eq(clone.minScaleDenominator, 10, "minScaleDenominator copied");
t.eq(clone.filter.type, OpenLayers.Filter.Comparison.EQUAL_TO, "clone has correct filter type");
// modify original
rule.filter.property = "new";
rule.symbolizer.fillColor = "white";
rule.context.foo = "baz";
// confirm that clone didn't change
t.eq(clone.filter.property, "prop", "clone has clone of filter");
t.eq(clone.symbolizer.fillColor, "black", "clone has clone of symbolizer");
t.eq(clone.context.foo, "bar", "clone has clone of context");
// confirm that ids are different
t.ok(clone.id !== rule.id, "clone has different id");
rule.destroy();
clone.destroy();
}
function test_Rule_destroy(t) {
t.plan(1);