OpenLayers OpenLayers

root/trunk/openlayers/tests/Control.html

Revision 7829, 2.7 kB (checked in by euzuro, 3 months ago)

Small patch to allow an 'id' property to be custom-set on controls -- without being overrided by the default random id generator. Thanks to Stephen I for the bug report. r=elemoine (Closes #1687)

  • Property svn:eol-style set to native
Line 
1 <html>
2 <head>
3   <script src="../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5     function test_Control_constructor(t) {
6         t.plan(4);
7    
8         var control = new OpenLayers.Control();
9
10         t.ok(control instanceof OpenLayers.Control, "new OpenLayers.Control returns object");
11         t.eq(control.displayClass, "olControl", "displayClass set correctly");
12         t.ok(control.id != null, "default id assigned to control");
13        
14         var testID = {};
15         control = new OpenLayers.Control({ 'id': testID });
16         t.ok(control.id == testID, "if id specified in options, no default assigned.");
17     }
18
19     function test_Control_addControl(t) {
20         t.plan(2);
21    
22         var map = new OpenLayers.Map('map');
23         var control = new OpenLayers.Control();
24         map.addControl(control);
25
26         t.ok(control.map === map, "Control.map is set to the map object" );
27         t.ok(map.controls[map.controls.length - 1] === control, "map.controls contains control");
28     }
29    
30     function test_Control_title(t) {
31         t.plan( 1 );
32         var titleText = 'Title test';
33         control = new OpenLayers.Control({title:titleText});
34         t.eq( control.title, titleText, "control.title set correctly" );
35     }
36    
37     function test_eventListeners(t) {
38         t.plan(1);
39        
40         var method = OpenLayers.Events.prototype.on;
41         // test that events.on is called at control construction
42         var options = {
43             eventListeners: {foo: "bar"}
44         };
45         OpenLayers.Events.prototype.on = function(obj) {
46             t.eq(obj, options.eventListeners, "events.on called with eventListeners");
47         }
48         var control = new OpenLayers.Control(options);
49         OpenLayers.Events.prototype.on = method;
50         control.destroy();
51
52         // if events.on is called again, this will fail due to an extra test
53         // test control without eventListeners
54         OpenLayers.Events.prototype.on = function(obj) {
55             t.fail("events.on called without eventListeners");
56         }
57         var control2 = new OpenLayers.Control();
58         OpenLayers.Events.prototype.on = method;
59         control2.destroy();
60     }
61
62     function test_Control_destroy(t) {
63         t.plan(3);
64    
65         var map = new OpenLayers.Map('map');
66         var control = new OpenLayers.Control();
67         map.addControl(control);
68
69         control.destroy();
70         t.ok(map.controls[map.controls.length - 1] != control, "map.controls doesn't contains control");
71
72         t.ok(control.map == null, "Control.map is null");
73         t.ok(control.handler == null, "Control.handler is null");
74     }
75
76   </script>
77 </head>
78 <body>
79     <div id="map" style="width: 1024px; height: 512px;"/>
80 </body>
81 </html>
Note: See TracBrowser for help on using the browser.