source: products/qPloneGoogleMaps/tags/0.1.0/tests/commonTestingStuff.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 15 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1from AccessControl import Unauthorized
2from zope.app.tests import ztapi
3from zope.app.annotation import IAttributeAnnotatable
4from zope.interface import directlyProvides
5from zope.interface.verify import verifyClass
6from Testing.ZopeTestCase.PortalTestCase import user_name, user_password
7
8from Products.CMFCore.utils import getToolByName
9
10from Products.geolocation.interfaces.geolocation import IGEOLocated
11
12from Products.qPloneGoogleMaps.adapters.markers import MarkersListing
13from Products.qPloneGoogleMaps.browser.markersview import MarkersView
14from Products.qPloneGoogleMaps.interfaces.markers import IMarkersListing, IMarkersView
15from Products.qPloneGoogleMaps import validator
16from Products.qPloneGoogleMaps.utility import processDesc
17from Products.qPloneGoogleMaps.content import Map, Overlay, Marker
18
19import MapFieldTest
20
21from Products.PloneTestCase import PloneTestCase
22
23PRODUCTS=('geolocation', 'qPloneGoogleMaps')
24
25map(PloneTestCase.installProduct, PRODUCTS)
26PloneTestCase.setupPloneSite(products=PRODUCTS)
27
28PRODUCT = 'qPloneGoogleMaps'
29
30def 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
43NEW_PORTAL_TYPES = ['Map', 'Marker', 'Overlay']
44MAP_API_KEYS = ("http://localhost.com:8888/map|ABQIAAAAPKXXAksH6LF9wD3-iB3Z9hR-_Derz1M-sZYUdeXG3J1uZOMrKxT98efydo7fhYu6kuaFv5ESjlw4mw", )
45TOPIC_VIEW = 'topic_maps_view'
46MAP_PORTLETS = ['here/portlet_maps/macros/portlet', 'here/portlet_overlays/macros/portlet',]
47PROPERTY_SHEET = 'maps_properties'
48PROPERTY_FIELD = 'map_api_keys'
49GEO_INDEX = 'geoLocation'
50
51# Utils testing stuff
52UNPROCESSED_STRING = """This is "unprocessed" string
53with carriage return and double
54quotes."""
55PROCESSED_STRING = "This is 'unprocessed' string with carriage return and double quotes."
56
57# Validation testing stuff
58
59# Field and widget testing stuff
60FIELD_VALUE = (3.5, 20.4)
61
62# Functional testing stuff
63NEW_MAP_KEY = "http://nohost/plone|IAAAAPKXXAksH6LF9wD3-iB3Z9hR-_Derz1M-sZYUdeXG3J1uZOMrKxT98efydo7fhYu6kuaFv5ES"
64
65# Map testing stuff
66MAP_VIEW_JAVASCRIPT = """
67<script type="text/javascript">
68//<![CDATA[
69
70function onLoadMap(){
71  if (GBrowserIsCompatible()) {
72
73    map1 = new GMap2(document.getElementById('mapView'));
74    map1.addControl(new GLargeMapControl());
75map1.addControl(new GMapTypeControl());
76map1.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
129registerEventListener(window, 'load', onLoadMap);
130registerEventListener(window, 'unload', GUnload);
131
132//]]>
133</script>
134"""
135
136# Overlay testing stuff
137OVERLAY_COLOR = 'blue'
138
139OVERLAY_VIEW_JAVASCRIPT = """
140<script type="text/javascript">
141//<![CDATA[
142
143function onLoadMap(){
144  if (GBrowserIsCompatible()) {
145
146    map1 = new GMap2(document.getElementById('mapView'));
147    map1.addControl(new GLargeMapControl());
148map1.addControl(new GMapTypeControl());
149map1.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
202registerEventListener(window, 'load', onLoadMap);
203registerEventListener(window, 'unload', GUnload);
204
205//]]>
206</script>
207"""
208
209# Marker testing stuff
210MARKER_VIEW_JAVASCRIPT = """
211<script type="text/javascript">
212//<![CDATA[
213
214function onLoadMap(){
215  if (GBrowserIsCompatible()) {
216
217    map1 = new GMap2(document.getElementById('mapView'));
218    map1.addControl(new GLargeMapControl());
219map1.addControl(new GMapTypeControl());
220map1.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
273registerEventListener(window, 'load', onLoadMap);
274registerEventListener(window, 'unload', GUnload);
275
276//]]>
277</script>
278"""
Note: See TracBrowser for help on using the repository browser.