3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
7 var name = "Test Layer";
8 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
9 var params = { map: '/mapdata/vmap_wms.map',
12 var options = { chicken: 151, foo: "bar" };
14 function test_Layer_HTTPRequest_constructor (t) {
17 layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
19 t.ok( layer instanceof OpenLayers.Layer.HTTPRequest, "new OpenLayers.Layer.HTTPRequest returns correctly typed object" );
21 // correct bubbling up to Layer.initialize()
22 t.eq( layer.name, name, "layer.name is correct" );
23 t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly set" );
25 // HTTPRequest-specific properties
26 t.eq( layer.url, url, "layer.name is correct" );
27 t.ok( ((layer.params["map"] == '/mapdata/vmap_wms.map') &&
28 (layer.params["layers"] == "basic") &&
29 (layer.params["format"] == "image/png")), "layer.params correctly set" );
34 function test_Layer_HTTPRequest_clone (t) {
37 var toClone = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
38 toClone.chocolate = 5;
40 var layer = toClone.clone();
42 t.eq(layer.chocolate, 5, "correctly copied randomly assigned property");
44 t.ok( layer instanceof OpenLayers.Layer.HTTPRequest, "new OpenLayers.Layer.HTTPRequest returns correctly typed object" );
46 // correct bubbling up to Layer.initialize()
47 t.eq( layer.name, name, "layer.name is correct" );
48 t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly set" );
50 // HTTPRequest-specific properties
51 t.eq( layer.url, url, "layer.name is correct" );
52 t.ok( ((layer.params["map"] == '/mapdata/vmap_wms.map') &&
53 (layer.params["layers"] == "basic") &&
54 (layer.params["format"] == "image/png")), "layer.params correctly set" );
58 function test_Layer_HTTPRequest_setUrl (t) {
61 layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
64 t.eq( layer.url, "foo", "setUrl() works");
67 function test_Layer_HTTPRequest_mergeNewParams (t) {
70 layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
72 var newParams = { layers: 'sooper',
73 chickpeas: 'image/png'};
75 layer.mergeNewParams(newParams);
77 t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
78 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
80 newParams.chickpeas = 151;
82 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hash");
84 layer.redraw = function() {
85 t.ok(true, "layer.mergeNewParams calls layer.redraw");
87 layer.mergeNewParams();
92 function test_Layer_HTTPRequest_getFullRequestString (t) {
94 tParams = { layers: 'basic',
100 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
101 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
102 str = layer.getFullRequestString();
103 t.eq(str, tUrl + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url sans ?");
107 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?";
108 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
109 str = layer.getFullRequestString();
110 t.eq(str, tUrl + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url with ?");
113 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5";
114 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
115 str = layer.getFullRequestString();
116 t.eq(str, tUrl + '&' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url with ?param1=5");
119 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&format=image/jpeg";
120 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
121 str = layer.getFullRequestString();
122 t.eq(str, tUrl + '&' + OpenLayers.Util.getParameterString({'layers':'basic'}), "getFullRequestString() doesn't override already-existing params in URL");
126 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&";
127 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
128 str = layer.getFullRequestString();
129 t.eq(str, tUrl + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url with ?param1=5&");
133 // passing in new params
134 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
135 str = layer.getFullRequestString( { chicken: 6,
137 t.eq(str, tUrl + OpenLayers.Util.getParameterString({layers: 'road', format: "image/png", chicken: 6}), "getFullRequestString() works for passing in new params");
139 // layer with null params
140 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, null, null);
141 str = layer.getFullRequestString();
142 t.eq(str, tUrl + OpenLayers.Util.getParameterString({}), "getFullRequestString() works for layer with null params");
144 // layer with null params passing in new params
145 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, null, null);
146 str = layer.getFullRequestString( { chicken: 6,
148 t.eq(str, tUrl + OpenLayers.Util.getParameterString({chicken: 6, layers: "road"}), "getFullRequestString() works for layer with null params passing in new params");
150 // with specified altUrl parameter
151 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
152 layer = new OpenLayers.Layer.HTTPRequest(name, "chicken", tParams, null);
153 str = layer.getFullRequestString(null, tUrl);
154 t.eq(str, tUrl + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works with specified altUrl parameter");
157 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv"];
158 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
159 str = layer.getFullRequestString();
160 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for list of one url");
163 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"];
164 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
165 str = layer.getFullRequestString();
166 t.eq(str, tUrl[1] + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for list of two urls");
167 str = layer.getFullRequestString({'a':'b'});
168 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'a':'b'})), "getFullRequestString() works for list of two urls and is deterministic");
172 function test_Layer_HTTPRequest_selectUrl (t) {
175 layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
177 urls = ["wms1", "wms2", "wms3", "wms4"];
178 t.eq( layer.selectUrl("bbox=-180,0,0,90", urls), "wms3", "selectUrl(-90,-180) returns 4" );
179 t.eq( layer.selectUrl("bbox=-180,-90,0,0", urls), "wms1", "selectUrl(90,-180) returns 3" );
180 t.eq( layer.selectUrl("bbox=0,90,180,0", urls), "wms1", "selectUrl(-90,180) returns 1" );
181 t.eq( layer.selectUrl("bbox=0,0,180,90", urls), "wms4", "selectUrl(90,180) returns 2" );
184 function test_Layer_HTTPRequest_destroy (t) {
187 var map = new OpenLayers.Map('map');
189 layer = new OpenLayers.Layer.HTTPRequest("Test Layer",
190 "http://www.openlayers.org",
192 { opt1: 8, opt2: 9});
197 // Ensure Layer.destroy() is called
198 t.eq( layer.name, null, "layer.name is null after destroy" );
199 t.eq( layer.div, null, "layer.div is null after destroy" );
200 t.eq( layer.map, null, "layer.map is null after destroy" );
201 t.eq( layer.options, null, "layer.options is null after destroy" );
204 // Specific to HTTPRequest
205 t.eq( layer.url, null, "layer.url is null after destroy" );
206 t.eq( layer.params, null, "layer.params is null after destroy" );