| 1 | from AccessControl import Unauthorized |
|---|
| 2 | from zope.app.tests import ztapi |
|---|
| 3 | from zope.app.annotation import IAttributeAnnotatable |
|---|
| 4 | from zope.interface import directlyProvides |
|---|
| 5 | from zope.interface.verify import verifyClass |
|---|
| 6 | from Testing.ZopeTestCase.PortalTestCase import user_name, user_password |
|---|
| 7 | |
|---|
| 8 | from Products.CMFCore.utils import getToolByName |
|---|
| 9 | |
|---|
| 10 | from Products.geolocation.interfaces.geolocation import IGEOLocated |
|---|
| 11 | |
|---|
| 12 | from Products.qPloneGoogleMaps.adapters.markers import MarkersListing |
|---|
| 13 | from Products.qPloneGoogleMaps.browser.markersview import MarkersView |
|---|
| 14 | from Products.qPloneGoogleMaps.interfaces.markers import IMarkersListing, IMarkersView |
|---|
| 15 | from Products.qPloneGoogleMaps import validator |
|---|
| 16 | from Products.qPloneGoogleMaps.utility import processDesc |
|---|
| 17 | from Products.qPloneGoogleMaps.content import Map, Overlay, Marker |
|---|
| 18 | |
|---|
| 19 | import MapFieldTest |
|---|
| 20 | |
|---|
| 21 | from Products.PloneTestCase import PloneTestCase |
|---|
| 22 | |
|---|
| 23 | PRODUCTS=('geolocation', 'qPloneGoogleMaps') |
|---|
| 24 | |
|---|
| 25 | map(PloneTestCase.installProduct, PRODUCTS) |
|---|
| 26 | PloneTestCase.setupPloneSite(products=PRODUCTS) |
|---|
| 27 | |
|---|
| 28 | PRODUCT = 'qPloneGoogleMaps' |
|---|
| 29 | |
|---|
| 30 | def maps_login(self, role): |
|---|
| 31 | """ Utility method for login under required role """ |
|---|
| 32 | from Testing.ZopeTestCase.PortalTestCase import user_name, user_password |
|---|
| 33 | if role == 'manager': |
|---|
| 34 | self.loginAsPortalOwner() |
|---|
| 35 | elif role == 'member': |
|---|
| 36 | self.login(user_name) |
|---|
| 37 | elif role == 'another_member': |
|---|
| 38 | self.login('another_member') |
|---|
| 39 | elif role == 'anonym': |
|---|
| 40 | self.logout() |
|---|
| 41 | |
|---|
| 42 | # Installation testing stuff |
|---|
| 43 | NEW_PORTAL_TYPES = ['Map', 'Marker', 'Overlay'] |
|---|
| 44 | MAP_API_KEYS = ("http://localhost.com:8888/map|ABQIAAAAPKXXAksH6LF9wD3-iB3Z9hR-_Derz1M-sZYUdeXG3J1uZOMrKxT98efydo7fhYu6kuaFv5ESjlw4mw", ) |
|---|
| 45 | TOPIC_VIEW = 'topic_maps_view' |
|---|
| 46 | MAP_PORTLETS = ['here/portlet_maps/macros/portlet', 'here/portlet_overlays/macros/portlet',] |
|---|
| 47 | PROPERTY_SHEET = 'maps_properties' |
|---|
| 48 | PROPERTY_FIELD = 'map_api_keys' |
|---|
| 49 | GEO_INDEX = 'geoLocation' |
|---|
| 50 | |
|---|
| 51 | # Utils testing stuff |
|---|
| 52 | UNPROCESSED_STRING = """This is "unprocessed" string |
|---|
| 53 | with carriage return and double |
|---|
| 54 | quotes.""" |
|---|
| 55 | PROCESSED_STRING = "This is 'unprocessed' string with carriage return and double quotes." |
|---|
| 56 | |
|---|
| 57 | # Validation testing stuff |
|---|
| 58 | |
|---|
| 59 | # Field and widget testing stuff |
|---|
| 60 | FIELD_VALUE = (3.5, 20.4) |
|---|
| 61 | |
|---|
| 62 | # Functional testing stuff |
|---|
| 63 | NEW_MAP_KEY = "http://nohost/plone|IAAAAPKXXAksH6LF9wD3-iB3Z9hR-_Derz1M-sZYUdeXG3J1uZOMrKxT98efydo7fhYu6kuaFv5ES" |
|---|
| 64 | |
|---|
| 65 | # Map testing stuff |
|---|
| 66 | MAP_VIEW_JAVASCRIPT = """ |
|---|
| 67 | <script type="text/javascript"> |
|---|
| 68 | //<![CDATA[ |
|---|
| 69 | |
|---|
| 70 | function onLoadMap(){ |
|---|
| 71 | if (GBrowserIsCompatible()) { |
|---|
| 72 | |
|---|
| 73 | map1 = new GMap2(document.getElementById('mapView')); |
|---|
| 74 | map1.addControl(new GLargeMapControl()); |
|---|
| 75 | map1.addControl(new GMapTypeControl()); |
|---|
| 76 | map1.addControl(new GOverviewMapControl()); |
|---|
| 77 | |
|---|
| 78 | map1.setCenter(new GLatLng(3.500000, 20.400000), 3, G_HYBRID_MAP); |
|---|
| 79 | var opt = map1.getInfoWindow(), overLays = {}; |
|---|
| 80 | opt.maxWidth = 400; |
|---|
| 81 | |
|---|
| 82 | var icon = new GIcon(); |
|---|
| 83 | icon.shadow = "http://nohost/plone/images/map_shadow.png"; |
|---|
| 84 | icon.iconSize = new GSize(20, 34); |
|---|
| 85 | icon.shadowSize = new GSize(37, 34); |
|---|
| 86 | icon.iconAnchor = new GPoint(9, 34); |
|---|
| 87 | icon.infoWindowAnchor = new GPoint(9, 2); |
|---|
| 88 | |
|---|
| 89 | function addMarker(lat, lng, title, url, content, col){ |
|---|
| 90 | icon.image = "http://nohost/plone/images/"+col+"/map_marker.png"; |
|---|
| 91 | var point = new GLatLng(lat, lng); |
|---|
| 92 | var marker = new GMarker(point, icon) |
|---|
| 93 | map1.addOverlay(marker); |
|---|
| 94 | |
|---|
| 95 | var f = function(){marker.openInfoWindowHtml( |
|---|
| 96 | "<div><h2><a href='"+url+"'>"+title+"</a></h2><p>"+content+"</p></div>" |
|---|
| 97 | , opt);}; |
|---|
| 98 | GEvent.addListener(marker, 'click', f); |
|---|
| 99 | |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | if (typeof(getData) == 'function') { |
|---|
| 107 | var over_obj = getData(); |
|---|
| 108 | if (over_obj) { |
|---|
| 109 | for (var i=0; i < over_obj['boxes'].length; i++) registerEventListener(over_obj['boxes'][i], 'click', |
|---|
| 110 | function (){ |
|---|
| 111 | map1.clearOverlays(); |
|---|
| 112 | var bs = getData(); |
|---|
| 113 | for (id in bs) { |
|---|
| 114 | if (bs[id] == true) { |
|---|
| 115 | for (var j=0; j < overLays[id].length; j++) { |
|---|
| 116 | var opts = overLays[id][j]; |
|---|
| 117 | addMarker(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]); |
|---|
| 118 | }; |
|---|
| 119 | } |
|---|
| 120 | }; |
|---|
| 121 | }); |
|---|
| 122 | } |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | } |
|---|
| 126 | else window.alert("Google maps aren't compatible with current browser or your map api key doesn't match your portal root."); |
|---|
| 127 | }; |
|---|
| 128 | |
|---|
| 129 | registerEventListener(window, 'load', onLoadMap); |
|---|
| 130 | registerEventListener(window, 'unload', GUnload); |
|---|
| 131 | |
|---|
| 132 | //]]> |
|---|
| 133 | </script> |
|---|
| 134 | """ |
|---|
| 135 | |
|---|
| 136 | # Overlay testing stuff |
|---|
| 137 | OVERLAY_COLOR = 'blue' |
|---|
| 138 | |
|---|
| 139 | OVERLAY_VIEW_JAVASCRIPT = """ |
|---|
| 140 | <script type="text/javascript"> |
|---|
| 141 | //<![CDATA[ |
|---|
| 142 | |
|---|
| 143 | function onLoadMap(){ |
|---|
| 144 | if (GBrowserIsCompatible()) { |
|---|
| 145 | |
|---|
| 146 | map1 = new GMap2(document.getElementById('mapView')); |
|---|
| 147 | map1.addControl(new GLargeMapControl()); |
|---|
| 148 | map1.addControl(new GMapTypeControl()); |
|---|
| 149 | map1.addControl(new GOverviewMapControl()); |
|---|
| 150 | |
|---|
| 151 | map1.setCenter(new GLatLng(3.500000, 20.400000), 6, G_HYBRID_MAP); |
|---|
| 152 | var opt = map1.getInfoWindow(), overLays = {}; |
|---|
| 153 | opt.maxWidth = 400; |
|---|
| 154 | |
|---|
| 155 | var icon = new GIcon(); |
|---|
| 156 | icon.shadow = "http://nohost/plone/images/map_shadow.png"; |
|---|
| 157 | icon.iconSize = new GSize(20, 34); |
|---|
| 158 | icon.shadowSize = new GSize(37, 34); |
|---|
| 159 | icon.iconAnchor = new GPoint(9, 34); |
|---|
| 160 | icon.infoWindowAnchor = new GPoint(9, 2); |
|---|
| 161 | |
|---|
| 162 | function addMarker(lat, lng, title, url, content, col){ |
|---|
| 163 | icon.image = "http://nohost/plone/images/"+col+"/map_marker.png"; |
|---|
| 164 | var point = new GLatLng(lat, lng); |
|---|
| 165 | var marker = new GMarker(point, icon) |
|---|
| 166 | map1.addOverlay(marker); |
|---|
| 167 | |
|---|
| 168 | var f = function(){marker.openInfoWindowHtml( |
|---|
| 169 | "<div><h2><a href='"+url+"'>"+title+"</a></h2><p>"+content+"</p></div>" |
|---|
| 170 | , opt);}; |
|---|
| 171 | GEvent.addListener(marker, 'click', f); |
|---|
| 172 | |
|---|
| 173 | }; |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | if (typeof(getData) == 'function') { |
|---|
| 180 | var over_obj = getData(); |
|---|
| 181 | if (over_obj) { |
|---|
| 182 | for (var i=0; i < over_obj['boxes'].length; i++) registerEventListener(over_obj['boxes'][i], 'click', |
|---|
| 183 | function (){ |
|---|
| 184 | map1.clearOverlays(); |
|---|
| 185 | var bs = getData(); |
|---|
| 186 | for (id in bs) { |
|---|
| 187 | if (bs[id] == true) { |
|---|
| 188 | for (var j=0; j < overLays[id].length; j++) { |
|---|
| 189 | var opts = overLays[id][j]; |
|---|
| 190 | addMarker(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]); |
|---|
| 191 | }; |
|---|
| 192 | } |
|---|
| 193 | }; |
|---|
| 194 | }); |
|---|
| 195 | } |
|---|
| 196 | }; |
|---|
| 197 | |
|---|
| 198 | } |
|---|
| 199 | else window.alert("Google maps aren't compatible with current browser or your map api key doesn't match your portal root."); |
|---|
| 200 | }; |
|---|
| 201 | |
|---|
| 202 | registerEventListener(window, 'load', onLoadMap); |
|---|
| 203 | registerEventListener(window, 'unload', GUnload); |
|---|
| 204 | |
|---|
| 205 | //]]> |
|---|
| 206 | </script> |
|---|
| 207 | """ |
|---|
| 208 | |
|---|
| 209 | # Marker testing stuff |
|---|
| 210 | MARKER_VIEW_JAVASCRIPT = """ |
|---|
| 211 | <script type="text/javascript"> |
|---|
| 212 | //<![CDATA[ |
|---|
| 213 | |
|---|
| 214 | function onLoadMap(){ |
|---|
| 215 | if (GBrowserIsCompatible()) { |
|---|
| 216 | |
|---|
| 217 | map1 = new GMap2(document.getElementById('mapView')); |
|---|
| 218 | map1.addControl(new GLargeMapControl()); |
|---|
| 219 | map1.addControl(new GMapTypeControl()); |
|---|
| 220 | map1.addControl(new GOverviewMapControl()); |
|---|
| 221 | |
|---|
| 222 | map1.setCenter(new GLatLng(3.500000, 20.400000), 6, G_HYBRID_MAP); |
|---|
| 223 | var opt = map1.getInfoWindow(), overLays = {}; |
|---|
| 224 | opt.maxWidth = 400; |
|---|
| 225 | |
|---|
| 226 | var icon = new GIcon(); |
|---|
| 227 | icon.shadow = "http://nohost/plone/images/map_shadow.png"; |
|---|
| 228 | icon.iconSize = new GSize(20, 34); |
|---|
| 229 | icon.shadowSize = new GSize(37, 34); |
|---|
| 230 | icon.iconAnchor = new GPoint(9, 34); |
|---|
| 231 | icon.infoWindowAnchor = new GPoint(9, 2); |
|---|
| 232 | |
|---|
| 233 | function addMarker(lat, lng, title, url, content, col){ |
|---|
| 234 | icon.image = "http://nohost/plone/images/"+col+"/map_marker.png"; |
|---|
| 235 | var point = new GLatLng(lat, lng); |
|---|
| 236 | var marker = new GMarker(point, icon) |
|---|
| 237 | map1.addOverlay(marker); |
|---|
| 238 | |
|---|
| 239 | var f = function(){marker.openInfoWindowHtml( |
|---|
| 240 | "<div><h2><a href='"+url+"'>"+title+"</a></h2><p>"+content+"</p></div>" |
|---|
| 241 | , opt);}; |
|---|
| 242 | GEvent.addListener(marker, 'click', f); |
|---|
| 243 | |
|---|
| 244 | }; |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | addMarker(3.500000, 20.400000, "Test Marker", "http://nohost/plone/Members/test_user_1_/test_map/test_marker/view", "Test Marker Description", "default"); |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | if (typeof(getData) == 'function') { |
|---|
| 251 | var over_obj = getData(); |
|---|
| 252 | if (over_obj) { |
|---|
| 253 | for (var i=0; i < over_obj['boxes'].length; i++) registerEventListener(over_obj['boxes'][i], 'click', |
|---|
| 254 | function (){ |
|---|
| 255 | map1.clearOverlays(); |
|---|
| 256 | var bs = getData(); |
|---|
| 257 | for (id in bs) { |
|---|
| 258 | if (bs[id] == true) { |
|---|
| 259 | for (var j=0; j < overLays[id].length; j++) { |
|---|
| 260 | var opts = overLays[id][j]; |
|---|
| 261 | addMarker(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]); |
|---|
| 262 | }; |
|---|
| 263 | } |
|---|
| 264 | }; |
|---|
| 265 | }); |
|---|
| 266 | } |
|---|
| 267 | }; |
|---|
| 268 | |
|---|
| 269 | } |
|---|
| 270 | else window.alert("Google maps aren't compatible with current browser or your map api key doesn't match your portal root."); |
|---|
| 271 | }; |
|---|
| 272 | |
|---|
| 273 | registerEventListener(window, 'load', onLoadMap); |
|---|
| 274 | registerEventListener(window, 'unload', GUnload); |
|---|
| 275 | |
|---|
| 276 | //]]> |
|---|
| 277 | </script> |
|---|
| 278 | """ |
|---|