]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Marker/Box.html
fixes notices
[syp.git] / openlayers / tests / Marker / Box.html
1 <html>
2 <head>
3   <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5     var box; 
6     
7     function test_Box_constructor (t) {
8         t.plan( 7 );
9
10         OpenLayers.Marker.Box.prototype._setBorder = 
11             OpenLayers.Marker.Box.prototype.setBorder;
12         OpenLayers.Marker.Box.prototype.setBorder = function (x,y) {
13             g_Color = x;
14             g_Width = y;
15         };
16
17         var bounds = new OpenLayers.Bounds(1,2,3,4);
18         var borderColor = "blue";
19         var borderWidth = 55;
20
21
22         g_Color = g_Width = null;
23         box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
24
25         t.ok( box instanceof OpenLayers.Marker.Box, "new OpenLayers.Marker.Box returns Box object" );
26         t.ok( box.bounds.equals(bounds), "bounds object correctly set");
27         t.ok( box.div != null, "div created");
28         //Safari 3 separates style overflow into overflow-x and overflow-y
29         var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
30         t.eq( box.div.style[prop], "hidden", "div style overflow hidden");
31         t.ok( box.events != null, "events object created");
32         t.eq( g_Color, borderColor, "setBorder called with correct border color");        
33         t.eq( g_Width, borderWidth, "setBorder called with correct border width");        
34         
35
36         OpenLayers.Marker.Box.prototype.setBorder = 
37             OpenLayers.Marker.Box.prototype._setBorder;
38     }
39
40
41     function test_Box_setBorder(t) {
42         t.plan( 2 );
43
44         var box = {
45             div: {
46                 style: {}
47             }
48         };
49
50       //defaults
51         var args = [];
52         OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
53         t.eq(box.div.style.border, "2px solid red", "style correctly set with no good values (defaults work)");
54
55       //good vals
56         var borderColor = "blue";
57         var borderWidth = 55;
58
59         args = [borderColor, borderWidth];
60         OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
61         t.eq(box.div.style.border, borderWidth + "px solid " + borderColor, "style correctly set with both good values");
62
63     }
64     function test_Box_draw(t) {
65         t.plan( 5 );
66
67         OpenLayers.Util._modifyDOMElement = 
68             OpenLayers.Util.modifyDOMElement;
69         OpenLayers.Util.modifyDOMElement = 
70             function (element, id, px, sz) {
71                 g_Element = element;
72                 g_Id = id;
73                 g_Px = px;
74                 g_Sz = sz;
75             };
76
77         var box = {
78             div: {}
79         };
80
81         
82         var px = {};
83         var sz = {};
84         var args = [px, sz];
85
86         g_Element = g_Id = g_Px = g_Sz = null;
87         var retVal = OpenLayers.Marker.Box.prototype.draw.apply(box, args);
88
89         t.eq(g_Element, box.div, "modifyDOMElement passes box's div for element");
90         t.eq(g_Id, null, "modifyDOMElement passes null for id");
91         t.eq(g_Px, px, "modifyDOMElement passes new px value for px");
92         t.eq(g_Sz, sz, "modifyDOMElement passes new sz value for sz");
93         t.ok(retVal == box.div, "draw returns box's div");
94
95         OpenLayers.Util.modifyDOMElement = 
96             OpenLayers.Util._modifyDOMElement;
97
98     }
99
100     function test_Box_onScreen(t) {
101         t.plan( 2 );
102
103         var map = new OpenLayers.Map("map");
104
105         var url = "http://octo.metacarta.com/cgi-bin/mapserv";
106         layer = new OpenLayers.Layer.WMS("WMS Layer", url);
107
108         map.addLayer(layer);
109         
110         mlayer = new OpenLayers.Layer.Boxes('Test Layer');
111         map.addLayer(mlayer);
112                
113         map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
114
115         //onscreen box
116         var bounds = new OpenLayers.Bounds(-1,-1,1,1);
117         var box = new OpenLayers.Marker.Box(bounds);
118         mlayer.addMarker(box);
119         
120         t.ok( box.onScreen(), "box knows it's onscreen" );
121
122         //offscreen box
123         var bounds = new OpenLayers.Bounds(100,100,150,150);
124         var box2 = new OpenLayers.Marker.Box(bounds);
125         mlayer.addMarker(box2);
126
127         t.ok( !box2.onScreen(), "box knows it's offscreen" );
128         map.destroy();
129     }
130
131     function test_Box_display(t) {
132         t.plan( 2 );
133
134         var box = {
135             div: {
136                 style: {}
137             }
138         };
139
140       //display(true)
141         var args = [true];
142         OpenLayers.Marker.Box.prototype.display.apply(box, args);
143         t.eq(box.div.style.display, "", "style.display correctly set to '' when display(true)");
144
145       //display(false)
146         var args = [false];
147         OpenLayers.Marker.Box.prototype.display.apply(box, args);
148         t.eq(box.div.style.display, "none", "style.display correctly set to 'none' when display(false)");
149     }
150
151     function test_Box_destroy(t) {
152         t.plan(3);
153         
154         OpenLayers.Marker.prototype._destroy = 
155             OpenLayers.Marker.prototype.destroy;
156         OpenLayers.Marker.prototype.destroy = function() {
157             g_Destroy = true;
158         }
159                 
160         var bounds = new OpenLayers.Bounds(1,2,3,4);
161         var borderColor = "blue";
162         var borderWidth = 55;
163
164         g_Destroy = null;
165         box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
166         box.destroy();
167
168         t.eq(box.bounds, null, "bounds nullified");
169         t.eq(box.div, null, "div nullified");
170         t.ok(g_Destroy == true, "OpenLayers.Marker.destroy() called");
171
172
173         OpenLayers.Marker.prototype.destroy = 
174             OpenLayers.Marker.prototype._destroy;
175     }
176     
177
178   </script>
179 </head>
180 <body>
181     <div id="map" style="width:500px;height:550px"></div>
182 </body>
183 </html>