]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Rule.html
initial commit
[syp.git] / openlayers / tests / Rule.html
1 <html> 
2 <head> 
3     <script src="../lib/OpenLayers.js"></script> 
4     <script type="text/javascript">
5
6     function test_Rule_constructor(t) { 
7         t.plan(3); 
8          
9         var options = {'foo': 'bar'}; 
10         var rule = new OpenLayers.Rule(options); 
11         t.ok(rule instanceof OpenLayers.Rule, 
12              "new OpenLayers.Rule returns object" ); 
13         t.eq(rule.foo, "bar", "constructor sets options correctly"); 
14         t.eq(typeof rule.evaluate, "function", "rule has an evaluate function"); 
15     }
16     
17     function test_Rule_getContext(t) { 
18         t.plan(2);
19         var rule, options;
20         
21         var feature = {
22             attributes: {
23                 'dude': 'hello'
24             },
25             'foobar': 'world'
26         }
27         
28         rule = new OpenLayers.Rule();
29         var context = rule.getContext(feature);
30         t.eq(context.dude, "hello", "value returned by getContext is correct"
31             + " if no context is specified"); 
32         
33         var options = {
34             context: function(feature){
35                 return feature;
36             }
37         };
38         rule = new OpenLayers.Rule(options);
39         var context = rule.getContext(feature);
40         t.eq(context.foobar, "world", "value returned by getContext is correct"
41             + " if a context is given in constructor options"); 
42     }
43     
44     function test_clone(t) {
45         
46         t.plan(7);
47         
48         var rule = new OpenLayers.Rule({
49             name: "test rule",
50             minScaleDenominator: 10,
51             maxScaleDenominator: 20,
52             filter: new OpenLayers.Filter.Comparison({
53                 type: OpenLayers.Filter.Comparison.EQUAL_TO,
54                 property: "prop",
55                 value: "value"
56             }),
57             symbolizer: {
58                 fillColor: "black"
59             },
60             context: {
61                 foo: "bar"
62             }
63         });
64         var clone = rule.clone();
65         t.eq(clone.name, "test rule", "name copied");
66         t.eq(clone.minScaleDenominator, 10, "minScaleDenominator copied");
67         t.eq(clone.filter.type, OpenLayers.Filter.Comparison.EQUAL_TO, "clone has correct filter type");
68         
69         // modify original
70         rule.filter.property = "new";
71         rule.symbolizer.fillColor = "white";
72         rule.context.foo = "baz";
73         
74         // confirm that clone didn't change
75         t.eq(clone.filter.property, "prop", "clone has clone of filter");
76         t.eq(clone.symbolizer.fillColor, "black", "clone has clone of symbolizer");
77         t.eq(clone.context.foo, "bar", "clone has clone of context");
78         
79         // confirm that ids are different
80         t.ok(clone.id !== rule.id, "clone has different id");
81         
82         rule.destroy();
83         clone.destroy();
84         
85     }
86
87     function test_Rule_destroy(t) {
88         t.plan(1);
89         
90         var rule = new OpenLayers.Rule();
91         rule.destroy();
92         t.eq(rule.symbolizer, null, "symbolizer hash nulled properly");
93     }
94
95     </script> 
96 </head> 
97 <body> 
98 </body> 
99 </html>