1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<html>
<head>
<script src="OLLoader.js"></script>
<script type="text/javascript">
function test_Rule_constructor(t) {
t.plan(3);
var options = {'foo': 'bar'};
var rule = new OpenLayers.Rule(options);
t.ok(rule instanceof OpenLayers.Rule,
"new OpenLayers.Rule returns object" );
t.eq(rule.foo, "bar", "constructor sets options correctly");
t.eq(typeof rule.evaluate, "function", "rule has an evaluate function");
}
function test_Rule_getContext(t) {
t.plan(2);
var rule, options;
var feature = {
attributes: {
'dude': 'hello'
},
'foobar': 'world'
}
rule = new OpenLayers.Rule();
var context = rule.getContext(feature);
t.eq(context.dude, "hello", "value returned by getContext is correct"
+ " if no context is specified");
var options = {
context: function(feature){
return feature;
}
};
rule = new OpenLayers.Rule(options);
var context = rule.getContext(feature);
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(9);
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();
// test multiple symbolizers
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"
}),
symbolizers: [
new OpenLayers.Symbolizer.Line({
strokeColor: "black"
})
]
});
clone = rule.clone();
t.eq(clone.symbolizers.length, 1, "clone has one symbolizer");
t.ok(clone.symbolizers[0] !== rule.symbolizers[0], "clone has different symbolizers than original");
clone.destroy();
rule.destroy();
}
function test_Rule_destroy(t) {
t.plan(1);
var rule = new OpenLayers.Rule();
rule.destroy();
t.eq(rule.symbolizer, null, "symbolizer hash nulled properly");
}
</script>
</head>
<body>
</body>
</html>
|