1
|
<html>
|
2
|
<head>
|
3
|
<script src="../lib/OpenLayers.js"></script>
|
4
|
<script type="text/javascript"><!--
|
5
|
var layer;
|
6
|
|
7
|
var name = "Test Layer";
|
8
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
9
|
var params = { map: '/mapdata/vmap_wms.map',
|
10
|
layers: 'basic',
|
11
|
format: 'image/png'};
|
12
|
var options = { chicken: 151, foo: "bar" };
|
13
|
|
14
|
function test_01_Layer_HTTPRequest_constructor (t) {
|
15
|
t.plan( 5 );
|
16
|
|
17
|
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
|
18
|
|
19
|
t.ok( layer instanceof OpenLayers.Layer.HTTPRequest, "new OpenLayers.Layer.HTTPRequest returns correctly typed object" );
|
20
|
|
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" );
|
24
|
|
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" );
|
30
|
|
31
|
|
32
|
}
|
33
|
|
34
|
function test_02_Layer_HTTPRequest_clone (t) {
|
35
|
t.plan( 6 );
|
36
|
|
37
|
var toClone = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
|
38
|
toClone.chocolate = 5;
|
39
|
|
40
|
var layer = toClone.clone();
|
41
|
|
42
|
t.eq(layer.chocolate, 5, "correctly copied randomly assigned property");
|
43
|
|
44
|
t.ok( layer instanceof OpenLayers.Layer.HTTPRequest, "new OpenLayers.Layer.HTTPRequest returns correctly typed object" );
|
45
|
|
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" );
|
49
|
|
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" );
|
55
|
|
56
|
}
|
57
|
|
58
|
function test_03_Layer_HTTPRequest_setUrl (t) {
|
59
|
t.plan( 1 );
|
60
|
|
61
|
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
|
62
|
|
63
|
layer.setUrl("foo");
|
64
|
t.eq( layer.url, "foo", "setUrl() works");
|
65
|
}
|
66
|
|
67
|
function test_05_Layer_HTTPRequest_mergeNewParams (t) {
|
68
|
t.plan( 3 );
|
69
|
|
70
|
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
|
71
|
|
72
|
var newParams = { layers: 'sooper',
|
73
|
chickpeas: 'image/png'};
|
74
|
|
75
|
layer.mergeNewParams(newParams);
|
76
|
|
77
|
t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
|
78
|
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
|
79
|
|
80
|
newParams.chickpeas = 151;
|
81
|
|
82
|
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hash");
|
83
|
|
84
|
|
85
|
}
|
86
|
|
87
|
function test_06_Layer_HTTPRequest_getFullRequestString (t) {
|
88
|
|
89
|
tParams = { layers: 'basic',
|
90
|
format: 'image/png'};
|
91
|
|
92
|
t.plan( 8 );
|
93
|
|
94
|
// without ?
|
95
|
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
|
96
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
|
97
|
str = layer.getFullRequestString();
|
98
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?layers=basic&format=image/png", "getFullRequestString() works for url sans ?");
|
99
|
|
100
|
|
101
|
// with ?
|
102
|
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?";
|
103
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
|
104
|
str = layer.getFullRequestString();
|
105
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?layers=basic&format=image/png", "getFullRequestString() works for url with ?");
|
106
|
|
107
|
// with ?param1=5
|
108
|
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5";
|
109
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
|
110
|
str = layer.getFullRequestString();
|
111
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&layers=basic&format=image/png", "getFullRequestString() works for url with ?param1=5");
|
112
|
|
113
|
|
114
|
// with ?param1=5&
|
115
|
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&";
|
116
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
|
117
|
str = layer.getFullRequestString();
|
118
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&layers=basic&format=image/png", "getFullRequestString() works for url with ?param1=5&");
|
119
|
|
120
|
// passing in new params
|
121
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null);
|
122
|
str = layer.getFullRequestString( { chicken: 6,
|
123
|
layers:"road" } );
|
124
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&layers=road&format=image/png&chicken=6", "getFullRequestString() works for passing in new params");
|
125
|
|
126
|
// layer with null params
|
127
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, null, null);
|
128
|
str = layer.getFullRequestString();
|
129
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&", "getFullRequestString() works for layer with null params");
|
130
|
|
131
|
// layer with null params passing in new params
|
132
|
layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, null, null);
|
133
|
str = layer.getFullRequestString( { chicken: 6,
|
134
|
layers:"road" } );
|
135
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?param1=5&chicken=6&layers=road", "getFullRequestString() works for layer with null params passing in new params");
|
136
|
|
137
|
// with specified altUrl parameter
|
138
|
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
|
139
|
layer = new OpenLayers.Layer.HTTPRequest(name, "chicken", tParams, null);
|
140
|
str = layer.getFullRequestString(null, tUrl);
|
141
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?layers=basic&format=image/png", "getFullRequestString() works for url sans ?");
|
142
|
|
143
|
}
|
144
|
|
145
|
function test_99_Layer_HTTPRequest_destroy (t) {
|
146
|
t.plan( 6 );
|
147
|
|
148
|
var map = new OpenLayers.Map('map');
|
149
|
|
150
|
layer = new OpenLayers.Layer.HTTPRequest("Test Layer",
|
151
|
"http://www.openlayers.org",
|
152
|
{ foo: 2, bar: 3},
|
153
|
{ opt1: 8, opt2: 9});
|
154
|
|
155
|
map.addLayer(layer);
|
156
|
layer.destroy();
|
157
|
|
158
|
// Ensure Layer.destroy() is called
|
159
|
t.eq( layer.name, null, "layer.name is null after destroy" );
|
160
|
t.eq( layer.div, null, "layer.div is null after destroy" );
|
161
|
t.eq( layer.map, null, "layer.map is null after destroy" );
|
162
|
t.eq( layer.options, null, "layer.options is null after destroy" );
|
163
|
|
164
|
|
165
|
// Specific to HTTPRequest
|
166
|
t.eq( layer.url, null, "layer.url is null after destroy" );
|
167
|
t.eq( layer.params, null, "layer.params is null after destroy" );
|
168
|
}
|
169
|
// -->
|
170
|
</script>
|
171
|
</head>
|
172
|
<body>
|
173
|
<div id="map"></div>
|
174
|
</body>
|
175
|
</html>
|