]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Control/Panel.html
do not allow empty passwords
[syp.git] / openlayers / tests / Control / Panel.html
1 <html>
2 <head>
3   <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5     function test_Control_Panel_constructor (t) {
6         t.plan( 2 );
7     
8         control = new OpenLayers.Control.Panel();
9         t.ok( control instanceof OpenLayers.Control.Panel, "new OpenLayers.Control returns object" );
10         t.eq( control.displayClass,  "olControlPanel", "displayClass is correct" );
11     }
12     function test_Control_Panel_constructor (t) {
13         t.plan(6);
14         var map = new OpenLayers.Map('map');
15         var panel = new OpenLayers.Control.Panel();
16         var toolControl = new OpenLayers.Control.ZoomBox();
17         var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
18               CLASS_NAME: 'mbControl.TestTool',
19               type: OpenLayers.Control.TYPE_TOOL
20         });
21         var anotherToolControl = new AnotherToolControl();
22         var ToggleControl = OpenLayers.Class(OpenLayers.Control, {
23               CLASS_NAME: 'mbControl.TestToggle',
24               type: OpenLayers.Control.TYPE_TOGGLE
25         });
26         var toggleControl = new ToggleControl();
27
28         t.ok(panel instanceof OpenLayers.Control.Panel, 
29               "new OpenLayers.Control.Panel returns object");
30
31         panel.addControls([toolControl, anotherToolControl, toggleControl]);
32
33         t.eq(panel.controls.length, 3,
34               "added three controls to the panel");
35         map.addControl(panel);
36
37         panel.activateControl(toolControl);
38         t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active,
39               "activated one tool control, the other one is inactive and the toggle control also.");
40
41         panel.redraw = function(){
42             t.ok(true,"Redraw called on activated toggle");
43         }
44               
45         panel.activateControl(toggleControl);
46         t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active,
47               "activated the toggle control, which has no influence on the tool controls.");
48               
49         panel.activateControl(anotherToolControl);
50         t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active,
51               "activated the other tool control, the first one is inactive and the toggle control still active.");
52     }
53     function test_Control_Panel_titles (t) { 
54         t.plan(2); 
55         var panel = new OpenLayers.Control.Panel(); 
56         var toolControl = new OpenLayers.Control.ZoomBox({ 
57             title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging." 
58         }); 
59         panel.addControls([toolControl]); 
60         t.eq(panel.controls.length, 1, "added a control to the panel"); 
61         t.eq(panel.controls[0].title, toolControl.panel_div.title, "the title is correctly set"); 
62     } 
63     
64     function test_Control_Panel_getBy(t) {
65         
66         var panel = {
67             getBy: OpenLayers.Control.Panel.prototype.getBy,
68             getControlsBy: OpenLayers.Control.Panel.prototype.getControlsBy,
69             controls: [
70                 {foo: "foo", id: Math.random()},
71                 {foo: "bar", id: Math.random()},
72                 {foo: "foobar", id: Math.random()},
73                 {foo: "foo bar", id: Math.random()},
74                 {foo: "foo", id: Math.random()}
75             ]
76         };
77
78         var cases = [
79             {
80                 got: panel.getControlsBy("foo", "foo"),
81                 expected: [panel.controls[0], panel.controls[4]],
82                 message: "(string literal) got two controls matching foo"
83             }, {
84                 got: panel.getControlsBy("foo", "bar"),
85                 expected: [panel.controls[1]],
86                 message: "(string literal) got one control matching foo"
87             }, {
88                 got: panel.getControlsBy("foo", "barfoo"),
89                 expected: [],
90                 message: "(string literal) got empty array for no foo match"
91             }, {
92                 got: panel.getControlsBy("foo", /foo/),
93                 expected: [panel.controls[0], panel.controls[2], panel.controls[3], panel.controls[4]],
94                 message: "(regexp literal) got three controls containing string"
95             }, {
96                 got: panel.getControlsBy("foo", /foo$/),
97                 expected: [panel.controls[0], panel.controls[4]],
98                 message: "(regexp literal) got three controls ending with string"
99             }, {
100                 got: panel.getControlsBy("foo", /\s/),
101                 expected: [panel.controls[3]],
102                 message: "(regexp literal) got control containing space"
103             }, {
104                 got: panel.getControlsBy("foo", new RegExp("BAR", "i")),
105                 expected: [panel.controls[1], panel.controls[2], panel.controls[3]],
106                 message: "(regexp object) got layers ignoring case"
107             }, {
108                 got: panel.getControlsBy("foo", {test: function(str) {return str.length > 3;}}),
109                 expected: [panel.controls[2], panel.controls[3]],
110                 message: "(custom object) got controls with foo length greater than 3"
111             }
112         ];
113         t.plan(cases.length);
114         for(var i=0; i<cases.length; ++i) {
115             t.eq(cases[i].got, cases[i].expected, cases[i].message);
116         }
117
118
119     }
120
121   </script>
122 </head>
123 <body>
124     <div id="map" style="width: 1024px; height: 512px;"/>
125 </body>
126 </html>