google4r-maps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,187 @@
1
+ # Project: google4r/maps
2
+ # File: /test/test_geocoder.rb
3
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
4
+ # Copyright: (c) 2007 by Manuel Holtgrewe
5
+ # License: MIT License as follows:
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
12
+ # persons to whom the Software is furnished to do so, subject to the
13
+ # following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included
16
+ # in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
24
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
27
+
28
+ require 'google4r/maps'
29
+
30
+ require 'test/key'
31
+
32
+ # Runs tests for the Google4R::Maps::Geocoder class. You have to provide a file named
33
+ # "key.rb" in the test directory which defines the constant GOOGLE_MAPS_KEY.
34
+ # This value will be used as the key for the "real" tests against the Google
35
+ # servers.
36
+ class GeocoderTest < Test::Unit::TestCase
37
+ def setup
38
+ @test_adress = "Janitell Rd, Colorado Springs, CO"
39
+
40
+ @valid_query_result = %q{{"name":"Janitell Rd, Colorado Springs, CO","Status":{"code":200,"request":"geocode"},"Placemark":[{"address":"Janitell Rd, Colorado Springs, CO 80906, USA","AddressDetails":{"Country":{"CountryNameCode":"US","AdministrativeArea":{"AdministrativeAreaName":"CO","SubAdministrativeArea":{"SubAdministrativeAreaName":"El Paso","Locality":{"LocalityName":"Colorado Springs","Thoroughfare":{"ThoroughfareName":"Janitell Rd"},"PostalCode":{"PostalCodeNumber":"80906"}}}}},"Accuracy": 6},"Point":{"coordinates":[-104.790060,38.795330,0]}},{"address":"Janitell Rd, Stratmoor, CO 80906, USA","AddressDetails":{"Country":{"CountryNameCode":"US","AdministrativeArea":{"AdministrativeAreaName":"CO","SubAdministrativeArea":{"SubAdministrativeAreaName":"El Paso","Locality":{"LocalityName":"Stratmoor","Thoroughfare":{"ThoroughfareName":"Janitell Rd"},"PostalCode":{"PostalCodeNumber":"80906"}}}}},"Accuracy": 6},"Point":{"coordinates":[-104.790390,38.789840,0]}},{"address":"Janitell Rd, CO 80906, USA","AddressDetails":{"Country":{"CountryNameCode":"US","AdministrativeArea":{"AdministrativeAreaName":"CO","SubAdministrativeArea":{"SubAdministrativeAreaName":"El Paso","Thoroughfare":{"ThoroughfareName":"Janitell Rd"},"PostalCode":{"PostalCodeNumber":"80906"}}}},"Accuracy": 6},"Point":{"coordinates":[-104.794390,38.803230,0]}}]}}
41
+
42
+ @valid_parsed_result =
43
+ {"Status"=>{"code"=>200, "request"=>"geocode"},
44
+ "name"=>"Janitell Rd, Colorado Springs, CO",
45
+ "Placemark"=>
46
+ [{"AddressDetails"=>
47
+ {"Country"=>
48
+ {"AdministrativeArea"=>
49
+ {"SubAdministrativeArea"=>
50
+ {"Locality"=>
51
+ {"LocalityName"=>"Colorado Springs",
52
+ "Thoroughfare"=>{"ThoroughfareName"=>"Janitell Rd"},
53
+ "PostalCode"=>{"PostalCodeNumber"=>"80906"}},
54
+ "SubAdministrativeAreaName"=>"El Paso"},
55
+ "AdministrativeAreaName"=>"CO"},
56
+ "CountryNameCode"=>"US"},
57
+ "Accuracy"=>6},
58
+ "Point"=>{"coordinates"=>[-104.79006, 38.79533, 0]},
59
+ "address"=>"Janitell Rd, Colorado Springs, CO 80906, USA"},
60
+ {"AddressDetails"=>
61
+ {"Country"=>
62
+ {"AdministrativeArea"=>
63
+ {"SubAdministrativeArea"=>
64
+ {"Locality"=>
65
+ {"LocalityName"=>"Stratmoor",
66
+ "Thoroughfare"=>{"ThoroughfareName"=>"Janitell Rd"},
67
+ "PostalCode"=>{"PostalCodeNumber"=>"80906"}},
68
+ "SubAdministrativeAreaName"=>"El Paso"},
69
+ "AdministrativeAreaName"=>"CO"},
70
+ "CountryNameCode"=>"US"},
71
+ "Accuracy"=>6},
72
+ "Point"=>{"coordinates"=>[-104.79039, 38.78984, 0]},
73
+ "address"=>"Janitell Rd, Stratmoor, CO 80906, USA"},
74
+ {"AddressDetails"=>
75
+ {"Country"=>
76
+ {"AdministrativeArea"=>
77
+ {"SubAdministrativeArea"=>
78
+ {"Thoroughfare"=>{"ThoroughfareName"=>"Janitell Rd"},
79
+ "PostalCode"=>{"PostalCodeNumber"=>"80906"},
80
+ "SubAdministrativeAreaName"=>"El Paso"},
81
+ "AdministrativeAreaName"=>"CO"},
82
+ "CountryNameCode"=>"US"},
83
+ "Accuracy"=>6},
84
+ "Point"=>{"coordinates"=>[-104.79439, 38.80323, 0]},
85
+ "address"=>"Janitell Rd, CO 80906, USA"}]}
86
+
87
+ @empty_result =
88
+ {
89
+ "Status" => { "code" => :number, "request" => "request" },
90
+ "Placemark" => []
91
+ }
92
+
93
+ @invalid_key_result = %q{{"name":"Janitell Rd, Colorado Springs, CO","Status":{"code":610,"request":"geocode"}}}
94
+ end
95
+
96
+ def teardown
97
+ end
98
+
99
+
100
+ def test_query_performs_correct_query_without_client
101
+ # required parameters
102
+ query = 'query'
103
+ key = 'key'
104
+
105
+ # setup stubs & mocks
106
+ url = URI.escape(Google4R::Maps::Geocoder::GET_URL % [ @test_adress, 'json', key ])
107
+ fake_response = stub()
108
+ fake_response.stubs(:body).times(1).with().returns(@valid_query_result)
109
+ Net::HTTP.stubs(:get_response).returns(fake_response).times(1).with(URI.parse(url))
110
+
111
+ # perform query
112
+ geocoder = Google4R::Maps::Geocoder.new(key)
113
+ geocoder.query(@test_adress)
114
+ end
115
+
116
+ def test_query_performs_correct_query_with_client
117
+ # required parameters
118
+ query = 'query'
119
+ key = 'key'
120
+
121
+ # setup stubs & mocks
122
+ url = URI.escape(Google4R::Maps::Geocoder::GET_URL % [ @test_adress, 'json', key ])
123
+ fake_response = stub()
124
+ fake_response.stubs(:body).times(1).with().returns(@valid_query_result)
125
+ Net::HTTP.stubs(:get_response).returns(fake_response).times(1).with(URI.parse(url + '&client=-client-id-'))
126
+
127
+ # perform query
128
+ geocoder = Google4R::Maps::Geocoder.new(key, '-client-id-')
129
+ geocoder.query(@test_adress)
130
+ end
131
+
132
+ def test_query_without_key_raises_exception
133
+ coder = Google4R::Maps::Geocoder.new(nil)
134
+
135
+ assert_raises(Google4R::Maps::KeyException) { coder.query("") }
136
+ end
137
+
138
+ def test_query_with_invalid_key_raises_exception
139
+ coder = Google4R::Maps::Geocoder.new("Invalid Google Maps Key")
140
+
141
+ assert_raises(Google4R::Maps::KeyException) do
142
+ coder.query(@test_adress)
143
+ end
144
+ end
145
+
146
+ # Make sure that querying with a broken network connection works, i.e. Google's server
147
+ # is not accessible.
148
+ def test_query_with_broken_network_connection
149
+ Net::HTTP.stubs(:get_response).raises(Net::HTTPRequestTimeOut)
150
+
151
+ coder = Google4R::Maps::Geocoder.new(GOOGLE_MAPS_KEY)
152
+
153
+ assert_raises(Google4R::Maps::ConnectionException) do
154
+ coder.query(@test_adress)
155
+ end
156
+ end
157
+
158
+ def test_query_returns_nil_if_no_result_has_been_returned_and_no_fatal_problem_occured
159
+ fake_response = mock('fake response')
160
+ fake_response.stubs(:body).returns('')
161
+ Net::HTTP.stubs(:get_response).returns(fake_response)
162
+
163
+ [ Google4R::Maps::Geocoder::G_GEO_MISSING_ADDRESS,
164
+ Google4R::Maps::Geocoder::G_GEO_UNKNOWN_ADDRESS,
165
+ Google4R::Maps::Geocoder::G_UNAVAILABLE_ADDRESS
166
+ ].each do |code|
167
+ empty_result = @empty_result.dup
168
+ empty_result["Status"]["code"] = code
169
+
170
+ YAML.stubs(:load).returns(empty_result)
171
+
172
+ coder = Google4R::Maps::Geocoder.new(GOOGLE_MAPS_KEY)
173
+
174
+ assert_nil coder.query(@test_adress)
175
+ assert_equal code, coder.last_status_code
176
+ end
177
+ end
178
+
179
+ def test_do_query
180
+ coder = Google4R::Maps::Geocoder.new(GOOGLE_MAPS_KEY)
181
+ coder.query @test_adress
182
+
183
+ assert_equal 200, coder.last_status_code
184
+
185
+ # no assertion, just make sure that querying works
186
+ end
187
+ end
@@ -0,0 +1,93 @@
1
+ # Project: google4r/maps
2
+ # File: /test/maps_test.rb
3
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
4
+ # Copyright: (c) 2007 by Manuel Holtgrewe
5
+ # License: MIT License as follows:
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
12
+ # persons to whom the Software is furnished to do so, subject to the
13
+ # following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included
16
+ # in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
24
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
27
+
28
+ require 'google4r/maps'
29
+
30
+ # Runs tests for the Google4R::Maps::GIcon class.
31
+ class GIconClass < Test::Unit::TestCase
32
+ def test_creator_should_work_correctly
33
+ icon = Google4R::Maps::GIcon.new
34
+ assert_equal false, icon.copy
35
+
36
+ icon = Google4R::Maps::GIcon.new(true)
37
+ assert_equal true, icon.copy
38
+ end
39
+
40
+ def test_to_js_should_work_correctly_with_default_values
41
+ expected = %Q{function() {
42
+ var icon = new GIcon();
43
+
44
+ return icon;
45
+ }}
46
+
47
+ icon = Google4R::Maps::GIcon.new
48
+ assert_equal expected, icon.to_js
49
+ end
50
+
51
+ def test_to_js_should_work_with_copy_icon_and_default_values
52
+ expected = %Q{function() {
53
+ var icon = new GIcon(G_DEFAULT_ICON);
54
+
55
+ return icon;
56
+ }}
57
+
58
+ icon = Google4R::Maps::GIcon.new(true)
59
+ assert_equal expected, icon.to_js
60
+ end
61
+
62
+ def test_to_js_should_work_correctly_with_all_values_set
63
+ expected = %Q{function() {
64
+ var icon = new GIcon();
65
+ icon.image = "image";
66
+ icon.shadow = "shadow";
67
+ icon.printImage = "print image";
68
+ icon.printShadow = "print shadow";
69
+ icon.transparent = "transparent";
70
+ icon.iconSize = new GSize(1, 2);
71
+ icon.shadowSize = new GSize(3, 4);
72
+ icon.iconAnchor = new GPoint(5, 6);
73
+ icon.infoWindowAnchor = new GPoint(7, 8);
74
+ icon.imageMap = [ 10, 11, 12, 13, 14, 15 ];
75
+
76
+ return icon;
77
+ }}
78
+
79
+ icon = Google4R::Maps::GIcon.new
80
+ icon.image = 'image'
81
+ icon.shadow = 'shadow'
82
+ icon.print_image = 'print image'
83
+ icon.print_shadow = 'print shadow'
84
+ icon.transparent = 'transparent'
85
+ icon.icon_size = [ 1, 2 ]
86
+ icon.shadow_size = [ 3, 4 ]
87
+ icon.icon_anchor = [ 5, 6 ]
88
+ icon.info_window_anchor = [ 7, 8 ]
89
+ icon.image_map = [ [10,11], [12,13], [14,15] ]
90
+
91
+ assert_equal expected, icon.to_js
92
+ end
93
+ end
@@ -0,0 +1,304 @@
1
+ # Project: google4r/maps
2
+ # File: /test/gmap_test.rb
3
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
4
+ # Copyright: (c) 2007 by Manuel Holtgrewe
5
+ # License: MIT License as follows:
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
12
+ # persons to whom the Software is furnished to do so, subject to the
13
+ # following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included
16
+ # in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
24
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
27
+
28
+ require 'google4r/maps'
29
+
30
+ # Runs tests for the Google4R::Maps::GMap2 class.
31
+ class GMap2Test < Test::Unit::TestCase
32
+ def test_attributes_are_correctly_set_in_creator
33
+ map = Google4R::Maps::GMap2.new("var name", "dom id")
34
+
35
+ assert_equal "dom id", map.div_id
36
+ assert_equal "var name", map.name
37
+
38
+ assert_equal [], map.icons
39
+ assert_equal [], map.markers
40
+ assert_equal [ :large_map, :scale, :map_type ], map.controls
41
+ assert_equal :normal, map.map_type
42
+ assert_equal true, map.dragging_enabled
43
+ assert_equal true, map.info_window_enabled
44
+ assert_equal false, map.double_click_zoom_enabled
45
+ assert_equal :auto, map.center
46
+ assert_equal :auto, map.zoom
47
+ assert_equal nil, map.onload_js
48
+ end
49
+
50
+ def test_create_marker_works
51
+ map = Google4R::Maps::GMap2.new("var name", "dom id")
52
+
53
+ i = map.markers.length
54
+ maybe_marker = map.create_marker([1,2])
55
+
56
+ assert_kind_of Google4R::Maps::GMarker, maybe_marker
57
+ assert_equal [1, 2], maybe_marker.point
58
+ assert map.markers.include?(maybe_marker)
59
+ assert_equal i+1, map.markers.length
60
+ end
61
+
62
+ def test_create_icon_works
63
+ map = Google4R::Maps::GMap2.new("var name", "dom id")
64
+
65
+ i = map.icons.length
66
+ maybe_icon = map.create_icon()
67
+
68
+ assert_kind_of Google4R::Maps::GIcon, maybe_icon
69
+ assert_equal false, maybe_icon.copy
70
+ assert map.icons.include?(maybe_icon)
71
+ assert_equal i+1, map.icons.length
72
+ end
73
+
74
+ def test_to_html_works_correctly_with_default_values
75
+ Google4R::Maps::GMap2.any_instance.stubs(:to_js).returns("<gmap 2 js>")
76
+
77
+ map = Google4R::Maps::GMap2.new("var name", "dom id")
78
+
79
+ expected = %Q{<div id="dom id"></div>
80
+ <script type="text/javascript" charset="utf-8">
81
+ //<![CDATA[
82
+ /* Create a variable to hold the GMap2 instance and the icons in. */
83
+ var var name;
84
+ var var name_icons;
85
+
86
+ function var name_loader() {
87
+ <gmap 2 js>
88
+ }
89
+
90
+ if (window.addEventListener) { /* not MSIE */
91
+ window.addEventListener('load', function() { var name_loader(); }, false);
92
+ } else { /* MSIE */
93
+ window.attachEvent('onload', function() { var name_loader(); }, false);
94
+ }
95
+
96
+ /* Optional Javascript */
97
+ if (window.addEventListener) { /* not MSIE */
98
+ window.addEventListener('unload', function() { GUnload(); }, false);
99
+ } else { /* MSIE */
100
+ window.attachEvent('onunload', function() { GUnload(); }, false);
101
+ }
102
+ // ]]>
103
+ </script>}
104
+
105
+ assert_equal expected, map.to_html
106
+ end
107
+
108
+ def test_to_html_works_correctly_with_no_gunload_handler
109
+ Google4R::Maps::GMap2.any_instance.stubs(:to_js).returns("<gmap 2 js>")
110
+
111
+ map = Google4R::Maps::GMap2.new("var name", "dom id")
112
+ map.options[:register_gunload] = false
113
+
114
+ expected = %Q{<div id="dom id"></div>
115
+ <script type="text/javascript" charset="utf-8">
116
+ //<![CDATA[
117
+ /* Create a variable to hold the GMap2 instance and the icons in. */
118
+ var var name;
119
+ var var name_icons;
120
+
121
+ function var name_loader() {
122
+ <gmap 2 js>
123
+ }
124
+
125
+ if (window.addEventListener) { /* not MSIE */
126
+ window.addEventListener('load', function() { var name_loader(); }, false);
127
+ } else { /* MSIE */
128
+ window.attachEvent('onload', function() { var name_loader(); }, false);
129
+ }
130
+
131
+ /* Optional Javascript */
132
+ // ]]>
133
+ </script>}
134
+
135
+ assert_equal expected, map.to_html
136
+ end
137
+
138
+
139
+ def test_to_js_works_correctly_with_default_values_and_without_icons_or_markers
140
+ map = Google4R::Maps::GMap2.new("var_name", "dom id")
141
+
142
+ expected = %Q{/* Create GMap2 instance. */
143
+ var_name = new GMap2(document.getElementById("dom id"), { });
144
+ var_name.setCenter(new GLatLng(0, 0), #{Google4R::Maps::GMap2::DEFAULT_ZOOM});
145
+
146
+ /* Set map options. */
147
+ var_name.setMapType(G_NORMAL_MAP);
148
+ var_name.enableDragging();
149
+ var_name.enableInfoWindow();
150
+ var_name.disableDoubleClickZoom();
151
+ var_name.disableContinuousZoom();
152
+
153
+ /* Add controls to the map. */
154
+ var_name.addControl(new GLargeMapControl());
155
+ var_name.addControl(new GScaleControl());
156
+ var_name.addControl(new GMapTypeControl());
157
+
158
+ /* Create global variable holding all icons. */
159
+ var_name_icons = new Array();
160
+
161
+ /* Add markers to the map. */
162
+
163
+ /* User supplied Javascript */
164
+ }
165
+
166
+ assert_equal expected, map.to_js
167
+ end
168
+
169
+ def test_to_js_works_correctly_with_default_values
170
+ map = Google4R::Maps::GMap2.new("var_name", "dom id")
171
+
172
+ map.icons << mock()
173
+ map.icons.last.stubs(:to_js).returns('<mock icon #1 js>')
174
+ map.icons << mock()
175
+ map.icons.last.stubs(:to_js).returns('<mock icon #2 js>')
176
+ map.markers << mock()
177
+ map.markers.last.stubs(:point).returns([ 10, 10 ])
178
+ map.markers.last.stubs(:icon).returns(map.icons[1])
179
+ map.markers.last.stubs(:to_js).returns('<mock marker #1 js>')
180
+ map.markers << mock()
181
+ map.markers.last.stubs(:point).returns([ 20, 20 ])
182
+ map.markers.last.stubs(:icon).returns(map.icons[0])
183
+ map.markers.last.stubs(:to_js).returns('<mock marker #2 js>')
184
+ map.markers << mock()
185
+ map.markers.last.stubs(:point).returns([ 10, 10 ])
186
+ map.markers.last.stubs(:icon).returns(nil)
187
+ map.markers.last.stubs(:to_js).returns('<mock marker #3 js>')
188
+
189
+ expected = %Q{/* Create GMap2 instance. */
190
+ var_name = new GMap2(document.getElementById("dom id"), { });
191
+ var_name.setCenter(new GLatLng(15, 15), var_name.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(10, 10), new GLatLng(20, 20))));
192
+
193
+ /* Set map options. */
194
+ var_name.setMapType(G_NORMAL_MAP);
195
+ var_name.enableDragging();
196
+ var_name.enableInfoWindow();
197
+ var_name.disableDoubleClickZoom();
198
+ var_name.disableContinuousZoom();
199
+
200
+ /* Add controls to the map. */
201
+ var_name.addControl(new GLargeMapControl());
202
+ var_name.addControl(new GScaleControl());
203
+ var_name.addControl(new GMapTypeControl());
204
+
205
+ /* Create global variable holding all icons. */
206
+ var_name_icons = new Array();
207
+ var_name_icons.push(<mock icon #1 js>());
208
+ var_name_icons.push(<mock icon #2 js>());
209
+
210
+ /* Add markers to the map. */
211
+ var_name.addOverlay(<mock marker #1 js>(var_name_icons[1]));
212
+ var_name.addOverlay(<mock marker #2 js>(var_name_icons[0]));
213
+ var_name.addOverlay(<mock marker #3 js>());
214
+
215
+ /* User supplied Javascript */
216
+ }
217
+
218
+ assert_equal expected, map.to_js
219
+ end
220
+
221
+ def test_to_js_works_correctly_with_changed_values
222
+ map = Google4R::Maps::GMap2.new("var_name", "dom id")
223
+ map.center = [-122.083739, 37.423021 ]
224
+ map.continuous_zoom_enabled = true
225
+ map.controls = [ :small_map, :small_zoom ]
226
+ map.div_id = "other dom id"
227
+ map.double_click_zoom_enabled = true
228
+ map.draggable_cursor = 'draggable cursor'
229
+ map.dragging_cursor = 'dragging cursor'
230
+ map.dragging_enabled = false
231
+ map.info_window_enabled = false
232
+ map.map_type = :hybrid
233
+ map.name = "other_var_name"
234
+ map.size = [ 100, 200 ]
235
+ map.zoom = 10
236
+
237
+ map.icons << mock()
238
+ map.icons.last.stubs(:to_js).returns('<mock icon #1 js>')
239
+ map.icons << mock()
240
+ map.icons.last.stubs(:to_js).returns('<mock icon #2 js>')
241
+ map.markers << mock()
242
+ map.markers.last.stubs(:icon).returns(map.icons[1])
243
+ map.markers.last.stubs(:to_js).returns('<mock marker #1 js>')
244
+ map.markers << mock()
245
+ map.markers.last.stubs(:icon).returns(map.icons[0])
246
+ map.markers.last.stubs(:to_js).returns('<mock marker #2 js>')
247
+ map.markers << mock()
248
+ map.markers.last.stubs(:icon).returns(nil)
249
+ map.markers.last.stubs(:to_js).returns('<mock marker #3 js>')
250
+
251
+ expected = %Q{/* Create GMap2 instance. */
252
+ other_var_name = new GMap2(document.getElementById("other dom id"), { draggableCursor: "draggable cursor", draggingCursor: "dragging cursor", size: new GSize(100, 200) });
253
+ other_var_name.setCenter(new GLatLng(#{map.center[0]}, #{map.center[1]}), #{map.zoom});
254
+
255
+ /* Set map options. */
256
+ other_var_name.setMapType(G_HYBRID_MAP);
257
+ other_var_name.disableDragging();
258
+ other_var_name.disableInfoWindow();
259
+ other_var_name.enableDoubleClickZoom();
260
+ other_var_name.enableContinuousZoom();
261
+
262
+ /* Add controls to the map. */
263
+ other_var_name.addControl(new GSmallMapControl());
264
+ other_var_name.addControl(new GSmallZoomControl());
265
+
266
+ /* Create global variable holding all icons. */
267
+ other_var_name_icons = new Array();
268
+ other_var_name_icons.push(<mock icon #1 js>());
269
+ other_var_name_icons.push(<mock icon #2 js>());
270
+
271
+ /* Add markers to the map. */
272
+ other_var_name.addOverlay(<mock marker #1 js>(other_var_name_icons[1]));
273
+ other_var_name.addOverlay(<mock marker #2 js>(other_var_name_icons[0]));
274
+ other_var_name.addOverlay(<mock marker #3 js>());
275
+
276
+ /* User supplied Javascript */
277
+ }
278
+
279
+ assert_equal expected, map.to_js
280
+ end
281
+
282
+ def test_center_auto_works_correctly
283
+ map = Google4R::Maps::GMap2.new("var_name", "dom id")
284
+ map.center = :auto
285
+
286
+ map.create_marker([10, 10])
287
+ map.create_marker([20, 20])
288
+
289
+ result = map.to_js
290
+ assert_not_nil result.index("var_name.setCenter(new GLatLng(15, 15)"), "result is #{result.inspect}"
291
+ end
292
+
293
+ def test_zoom_auto_works_correctly
294
+ map = Google4R::Maps::GMap2.new("var_name", "dom id")
295
+ map.center = [ 0, 0 ]
296
+ map.zoom = :auto
297
+
298
+ map.create_marker([10, 10])
299
+ map.create_marker([20, 20])
300
+
301
+ result = map.to_js
302
+ assert_not_nil result.index("var_name.setCenter(new GLatLng(0, 0), var_name.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(10, 10), new GLatLng(20, 20))))"), "result is #{result.inspect}"
303
+ end
304
+ end