]> projects.mako.cc - selectricity-live/blob - vendor/plugins/ym4r_gm/test/gm_test.rb
fix security issue
[selectricity-live] / vendor / plugins / ym4r_gm / test / gm_test.rb
1 $:.unshift(File.dirname(__FILE__) + '/../lib')
2
3 require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
4
5
6 require 'ym4r_gm'
7 require 'test/unit'
8
9 include Ym4r::GmPlugin
10
11 class TestGoogleMaps< Test::Unit::TestCase
12   def test_javascriptify_method
13     assert_equal("addOverlayToHello",MappingObject::javascriptify_method("add_overlay_to_hello"))
14   end
15
16   def test_javascriptify_variable_mapping_object
17     map = GMap.new("div")
18     assert_equal(map.to_javascript,MappingObject::javascriptify_variable(map))
19   end
20
21   def test_javascriptify_variable_numeric
22     assert_equal("123.4",MappingObject::javascriptify_variable(123.4))
23   end
24
25   def test_javascriptify_variable_array
26     map = GMap.new("div")
27     assert_equal("[123.4,#{map.to_javascript},[123.4,#{map.to_javascript}]]",MappingObject::javascriptify_variable([123.4,map,[123.4,map]]))
28   end
29
30   def test_javascriptify_variable_hash
31     map = GMap.new("div")
32     test_str = MappingObject::javascriptify_variable("hello" => map, "chopotopoto" => [123.55,map])
33     assert("{hello : #{map.to_javascript},chopotopoto : [123.55,#{map.to_javascript}]}" == test_str || "{chopotopoto : [123.55,#{map.to_javascript}],hello : #{map.to_javascript}}" == test_str)
34   end
35
36   def test_method_call_on_mapping_object
37     map = GMap.new("div","map")
38     assert_equal("map.addHello(123.4);",map.add_hello(123.4).to_s)
39   end
40
41   def test_nested_calls_on_mapping_object
42     gmap = GMap.new("div","map")
43     assert_equal("map.addHello(map.hoYoYo(123.4),map);",gmap.add_hello(gmap.ho_yo_yo(123.4),gmap).to_s)
44   end
45   
46   def test_declare_variable_latlng
47     point = GLatLng.new([123.4,123.6])
48     assert_equal("var point = new GLatLng(123.4,123.6);",point.declare("point"))
49     assert_equal("point",point.variable)
50   end
51
52   def test_array_indexing
53     obj = Variable.new("obj")
54     assert_equal("obj[0]",obj[0].variable)
55   end
56
57   def test_google_maps_geocoding
58     
59
60     placemarks = Geocoding.get("Rue Clovis Paris")
61     assert_equal(Geocoding::GEO_SUCCESS,placemarks.status)
62     assert_equal(1,placemarks.length)
63     placemark = placemarks[0]
64     assert_equal("FR",placemark.country_code)
65     assert_equal("Paris",placemark.locality)
66     assert_equal("75005",placemark.postal_code)
67     
68     #test iwht multiple placemarks
69     placemarks = Geocoding.get('hoogstraat, nl')
70     assert_equal(Geocoding::GEO_SUCCESS,placemarks.status)
71     assert(placemarks.length > 1)
72     assert(placemarks[0].latitude != placemarks[1].latitude )
73     
74
75   end
76
77   
78 end
79

Benjamin Mako Hill || Want to submit a patch?