Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

jjwg_MapsTest::testdefineMapsFormattedAddress()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 40
rs 8.8571
c 1
b 0
f 1
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
3
class jjwg_MapsTest extends PHPUnit_Framework_TestCase{
4
5
6
7
    public function testjjwg_Maps() {
8
9
    	//execute the contructor and check for the Object type and  attributes
10
    	$jjwgMaps = new jjwg_Maps();
11
    	 
12
    	$this->assertInstanceOf('jjwg_Maps',$jjwgMaps);
13
    	$this->assertInstanceOf('Basic',$jjwgMaps);
14
    	$this->assertInstanceOf('SugarBean',$jjwgMaps);
15
    	
16
    	$this->assertAttributeEquals('jjwg_Maps', 'module_dir', $jjwgMaps);
17
    	$this->assertAttributeEquals('jjwg_Maps', 'object_name', $jjwgMaps);
18
    	$this->assertAttributeEquals('jjwg_maps', 'table_name', $jjwgMaps);
19
    	
20
    	$this->assertAttributeEquals(true, 'new_schema', $jjwgMaps);
21
    	$this->assertAttributeEquals(true, 'importable', $jjwgMaps);
22
    	$this->assertAttributeEquals(true, 'disable_row_level_security', $jjwgMaps);
23
    	 	
24
    }
25
26
27
    public function testconfiguration() {
28
29
    	error_reporting(E_ERROR | E_PARSE);
30
    	
31
    	$jjwgMaps = new jjwg_Maps();
32
33
    	//execute the method and test if it works and does not throws an exception.
34
    	try {
35
    		$jjwgMaps->configuration();
36
    		$this->assertTrue(true);
37
    	}
38
    	catch (Exception $e) {
39
    		$this->fail();
40
    	}
41
    	
42
    	
43
    }
44
45
46
    public function testsaveConfiguration() {
47
    	
48
    	$jjwgMaps = new jjwg_Maps();
49
    	
50
    	//test with empty array/default
51
    	$result = $jjwgMaps->saveConfiguration();
52
    	$this->assertEquals(false, $result);
53
    	
54
    	
55
    	//test with data array
56
    	$result = $jjwgMaps->saveConfiguration(array("test"=>1));
57
    	$this->assertEquals(true, $result);
58
    	
59
    }
60
61
62
    public function testupdateGeocodeInfo() {
63
        
64
    	$jjwgMaps = new jjwg_Maps();
65
    	$bean = new Meeting();
66
67
    	//test without bean attributes set
68
    	$result = $jjwgMaps->updateGeocodeInfo($bean);
69
    	$this->assertSame(false, $result);
70
71
    	
72
    	//test with required attributes set
73
    	$bean->id = 1;
74
    	$bean->jjwg_maps_lat_c = "100";
75
    	$bean->jjwg_maps_lng_c = "40";
76
    	
77
    	$result = $jjwgMaps->updateGeocodeInfo($bean);
78
    	
79
    	$this->assertEquals(null, $result);
80
    	$this->assertEquals(100, $bean->jjwg_maps_lat_c);
81
    	$this->assertEquals(40, $bean->jjwg_maps_lng_c);
82
    	$this->assertEquals('', $bean->jjwg_maps_geocode_status_c);
83
    	$this->assertEquals('', $bean->jjwg_maps_address_c);
84
    	
85
    }
86
87
88
    public function testupdateRelatedMeetingsGeocodeInfo() {
89
90
    	$jjwgMaps = new jjwg_Maps();
91
    	$bean = new Account();
92
    	
93
    	//test without setting bean attributes 
94
    	$result = $jjwgMaps->updateRelatedMeetingsGeocodeInfo($bean);
95
    	$this->assertEquals(false, $result);
96
    	
97
    	
98
    	//test with required attributes set
99
    	$bean->id = 1;
100
    	$bean->jjwg_maps_lat_c = "100";
101
    	$bean->jjwg_maps_lng_c = "40";
102
    	
103
    	$result = $jjwgMaps->updateRelatedMeetingsGeocodeInfo($bean);
104
    	$this->assertSame(null, $result);
105
    	$this->assertInstanceOf('jjwg_Address_Cache',$jjwgMaps->jjwg_Address_Cache);
106
    	
107
    }
108
109
110
    public function testupdateMeetingGeocodeInfo() {
111
        
112
    	$jjwgMaps = new jjwg_Maps();
113
    	
114
    	//test with required attributes set
115
    	$bean = new Meeting();
116
    	$bean->id = 1;
117
    	$bean->jjwg_maps_lat_c = "100";
118
    	$bean->jjwg_maps_lng_c = "40";
119
    	
120
    	$result = $jjwgMaps->updateMeetingGeocodeInfo($bean);
121
    	$this->assertSame(null, $result);
122
		
123
    }
124
    
125
126
    public function testupdateGeocodeInfoByAssocQuery() {
127
        
128
    	$jjwgMaps = new jjwg_Maps();
129
    	
130
    	//test with empty parameters
131
    	$result = $jjwgMaps->updateGeocodeInfoByAssocQuery('', array(), array());
132
    	$this->assertSame(false, $result);
133
    	
134
    	
135
    	//test with non empty but invalid parameters
136
    	$result = $jjwgMaps->updateGeocodeInfoByAssocQuery('test', array(), array());
137
    	$this->assertSame(false, $result);
138
    	
139
    	
140
    	//test with non empty valid parameters
141
    	$result = $jjwgMaps->updateGeocodeInfoByAssocQuery('accounts', array('id'=>1), array());
142
    	$this->assertSame(null, $result);
143
    	
144
    }
145
    
146
147
    public function testupdateGeocodeInfoByBeanQuery() {
148
        
149
    	$jjwgMaps = new jjwg_Maps();
150
    	$bean = new Account();
151
    	
152
    	
153
    	//test without setting bean attributes
154
    	$result = $jjwgMaps->updateGeocodeInfoByBeanQuery($bean);
155
    	$this->assertSame(false, $result);
156
    	
157
    	
158
    	//test with required attributes set
159
    	$bean->id = 1;
160
    	$result = $jjwgMaps->updateGeocodeInfoByBeanQuery($bean);
161
    	$this->assertSame(null, $result);
162
    	
163
    }
164
165
166
    public function testdeleteAllGeocodeInfoByBeanQuery() {
167
168
    	$jjwgMaps = new jjwg_Maps();
169
    	$bean = new Call();
170
171
    	
172
    	//test with invalid geocode bean
173
    	$result = $jjwgMaps->deleteAllGeocodeInfoByBeanQuery($bean);
174
    	$this->assertSame(false, $result);
175
176
    	
177
    	//test with invalid geocode bean
178
    	$bean = new Account();
179
    	$result = $jjwgMaps->deleteAllGeocodeInfoByBeanQuery($bean);
180
    	$this->assertSame(null, $result);
181
    	
182
    }
183
184
185
    public function testgetGeocodeAddressesResult() {
186
187
    	$jjwgMaps = new jjwg_Maps();
188
    	
189
    	//test with invalid geocode bean
190
    	$result = $jjwgMaps->getGeocodeAddressesResult("calls");
191
    	$this->assertSame(false, $result);
192
    	
193
    	
194
    	//test with invalid geocode bean
195
    	$result = $jjwgMaps->getGeocodeAddressesResult("accounts");
196
    	$this->assertInstanceOf('mysqli_result',$result);
197
    	
198
    }
199
200
201
    public function testgetGoogleMapsGeocode() {
202
203
    	$jjwgMaps = new jjwg_Maps();
204
    	
205
    	//test with invalid value
206
    	$expected = array (
207
    			'address' => '',
208
    			'status' => 'ZERO_RESULTS',
209
    			'lat' => NULL,
210
    			'lng' => NULL,
211
    	);
212
    	
213
    	$actual = $jjwgMaps->getGoogleMapsGeocode("");
214
    	$this->assertSame($expected,$actual);
215
216
    	
217
    	//test with valid value
218
    	$expected = array (
219
    			'address' => 'washington D.C',
220
    			'status' => 'OK',
221
    			'lat' => 38.90719229999999839719748706556856632232666015625,
222
    			'lng' => -77.0368706999999943718648864887654781341552734375,
223
    	);
224
    	$actual = $jjwgMaps->getGoogleMapsGeocode("washington D.C");
225
    	$this->assertSame($expected,$actual);
226
  
227
    	
228
    	//test with valid value and full array true
229
    	$expected =	
230
    		array (
231
    			'results' =>
232
    			array (
233
    					array (
234
    							'address_components' =>
235
    							array (
236
    									array ( 'long_name' => 'Washington', 'short_name' => 'D.C.', 'types' =>  array ( 'locality', 'political', ),  ),
237
    									array ( 'long_name' => 'District of Columbia', 'short_name' => 'District of Columbia', 'types' =>  array ( 'administrative_area_level_2','political', ), ),
238
    									array ( 'long_name' => 'District of Columbia', 'short_name' => 'DC', 'types' =>  array ( 'administrative_area_level_1', 'political', ),
239
    									),
240
    									array ( 'long_name' => 'United States', 'short_name' => 'US', 'types' => array ( 'country', 'political', ),  ),
241
    							),
242
    							'formatted_address' => 'Washington, DC, USA',
243
    							'geometry' =>
244
    							array (
245
    									'bounds' => array ( 'northeast' =>  array ( 'lat' => 38.9955479999999994333848007954657077789306640625, 'lng' => -76.909392999999994344761944375932216644287109375, ), 'southwest' =>  array ( 'lat' => 38.8031495000000035133780329488217830657958984375, 'lng' => -77.1197399999999930741978459991514682769775390625,  ), ),
246
    									'location' => array ( 'lat' => 38.90719229999999839719748706556856632232666015625, 'lng' => -77.0368706999999943718648864887654781341552734375,),
247
    									'location_type' => 'APPROXIMATE',
248
    									'viewport' => array ( 'northeast' => array ( 'lat' => 38.9955479999999994333848007954657077789306640625, 'lng' => -76.909392999999994344761944375932216644287109375,), 'southwest' => array ( 'lat' => 38.8031495000000035133780329488217830657958984375, 'lng' => -77.1197399999999930741978459991514682769775390625,), ),
249
    							),
250
    							'place_id' => 'ChIJW-T2Wt7Gt4kRKl2I1CJFUsI',
251
    							'types' => array ('locality', 'political'),
252
    					),
253
    			),
254
    			'status' => 'OK',
255
    	);
256
    	
257
    	$actual = $jjwgMaps->getGoogleMapsGeocode("washington D.C",true);
258
    		
259
    	$this->assertSame($expected['results']['geometry'],$actual['results']['geometry']);
260
    	//$this->assertSame($expected,$actual);
261
    	
262
    }
263
264
265
    public function testdefineMapsAddress() {
266
        
267
    	$jjwgMaps = new jjwg_Maps();
268
    	
269
    	
270
    	//test for Account Object type 
271
    	$address = array('id'=>1, 'billing_address_street'=>"addr 1", 'billing_address_city'=>"addr 2", 'billing_address_state'=>"addr 3", 'billing_address_postalcode'=>"addr 4", 'billing_address_country'=>"addr 5");
272
    	$result = $jjwgMaps->defineMapsAddress('Account',$address);
273
    	//var_dump($result);
274
    	$this->assertEquals(array('address' => "addr 1, addr 2, addr 3, addr 4, addr 5"), $result);
275
    	
276
    	
277
    	
278
    	//test for Contact Object type
279
    	$address = array('id'=>1, 'primary_address_street'=>"addr 1", 'primary_address_city'=>"addr 2", 'primary_address_state'=>"addr 3", 'primary_address_postalcode'=>"addr 4", 'primary_address_country'=>"addr 5");
280
    	$result = $jjwgMaps->defineMapsAddress('Contact',$address);
281
    	$this->assertEquals(array('address' => "addr 1, addr 2, addr 3, addr 4, addr 5"), $result);
282
    	
283
    	
284
    	
285
    	//test for Leads Object type
286
    	$address = array('id'=>1, 'primary_address_street'=>"addr 1", 'primary_address_city'=>"addr 2", 'primary_address_state'=>"addr 3", 'primary_address_postalcode'=>"addr 4", 'primary_address_country'=>"addr 5");
287
    	$result = $jjwgMaps->defineMapsAddress('Lead',$address);
288
    	$this->assertEquals(array('address' => "addr 1, addr 2, addr 3, addr 4, addr 5"), $result);
289
    	 
290
    	
291
292
    	//test for Opportunities Object type
293
    	$address = array('id'=>1, 'billing_address_street'=>"addr 1", 'billing_address_city'=>"addr 2", 'billing_address_state'=>"addr 3", 'billing_address_postalcode'=>"addr 4", 'billing_address_country'=>"addr 5");
294
    	$result = $jjwgMaps->defineMapsAddress('Opportunity',$address);
295
    	$this->assertEquals(false, $result);
296
    	
297
 
298
    	
299
    	//test for Case Object type
300
    	$address = array('id'=>1, 'billing_address_street'=>"addr 1", 'billing_address_city'=>"addr 2", 'billing_address_state'=>"addr 3", 'billing_address_postalcode'=>"addr 4", 'billing_address_country'=>"addr 5");
301
    	$result = $jjwgMaps->defineMapsAddress('Case',$address);
302
    	$this->assertEquals(false, $result);
303
    	
304
    	
305
    	//test for Project Object type
306
    	$address = array('id'=>1, 'billing_address_street'=>"addr 1", 'billing_address_city'=>"addr 2", 'billing_address_state'=>"addr 3", 'billing_address_postalcode'=>"addr 4", 'billing_address_country'=>"addr 5");
307
    	$result = $jjwgMaps->defineMapsAddress('Project',$address);
308
    	$this->assertEquals(false, $result);
309
    	 
310
    	
311
312
    	//test for Project Meetings type
313
    	$address = array('id'=>1, 'billing_address_street'=>"addr 1", 'billing_address_city'=>"addr 2", 'billing_address_state'=>"addr 3", 'billing_address_postalcode'=>"addr 4", 'billing_address_country'=>"addr 5");
314
    	$result = $jjwgMaps->defineMapsAddress('Meeting',$address);
315
    	$this->assertEquals(false, $result);
316
    	 
317
    }
318
319
320
    public function testdefineMapsFormattedAddress() {
321
322
    	
323
    	$jjwgMaps = new jjwg_Maps();
324
    	
325
    	$result = $jjwgMaps->defineMapsFormattedAddress(array());
326
    	$this->assertEquals(false, $result);
327
		
328
    	
329
    	//test for type billing  
330
    	$address = array('billing_address_street'=>"addr 1", 'billing_address_city'=>"addr 2", 'billing_address_state'=>"addr 3", 'billing_address_postalcode'=>"addr 4", 'billing_address_country'=>"addr 5");
331
    	$result = $jjwgMaps->defineMapsFormattedAddress($address,'billing');
332
    	$this->assertEquals("addr 1, addr 2, addr 3, addr 4, addr 5", $result);
333
334
    	
335
    	//test for type shipping    	
336
    	$address = array('shipping_address_street'=>"addr 1", 'shipping_address_city'=>"addr 2", 'shipping_address_state'=>"addr 3", 'shipping_address_postalcode'=>"addr 4", 'shipping_address_country'=>"addr 5");
337
    	$result = $jjwgMaps->defineMapsFormattedAddress($address,'shipping');
338
    	$this->assertEquals("addr 1, addr 2, addr 3, addr 4, addr 5", $result);
339
    	 
340
    	
341
    	//test for type primary
342
    	$address = array('primary_address_street'=>"addr 1", 'primary_address_city'=>"addr 2", 'primary_address_state'=>"addr 3", 'primary_address_postalcode'=>"addr 4", 'primary_address_country'=>"addr 5");
343
    	$result = $jjwgMaps->defineMapsFormattedAddress($address,'primary');
344
    	$this->assertEquals("addr 1, addr 2, addr 3, addr 4, addr 5", $result);
345
    	
346
    	
347
    	//test for type alt
348
    	$address = array('alt_address_street'=>"addr 1", 'alt_address_city'=>"addr 2", 'alt_address_state'=>"addr 3", 'alt_address_postalcode'=>"addr 4", 'alt_address_country'=>"addr 5");
349
    	$result = $jjwgMaps->defineMapsFormattedAddress($address,'alt');
350
    	$this->assertEquals("addr 1, addr 2, addr 3, addr 4, addr 5", $result);
351
    	
352
    	
353
    	//test for type address
354
    	$address = array('address_street'=>"addr 1", 'address_city'=>"addr 2", 'address_state'=>"addr 3", 'address_postalcode'=>"addr 4");
355
    	$result = $jjwgMaps->defineMapsFormattedAddress($address,'address');
356
    	$this->assertEquals("addr 1, addr 2, addr 3, addr 4", $result);
357
358
    	
359
    }
360
361
362
    public function testis_valid_lng() {
363
364
    	$jjwgMaps = new jjwg_Maps();
365
    	
366
    	//test with invalid values
367
    	$this->assertEquals(false, $jjwgMaps->is_valid_lng('') );
368
    	$this->assertEquals(false, $jjwgMaps->is_valid_lng(181) );
369
    	$this->assertEquals(false, $jjwgMaps->is_valid_lng(-181) );
370
    	 
371
    	//test with valid values
372
    	$this->assertEquals(true, $jjwgMaps->is_valid_lng(180) );
373
    	$this->assertEquals(true, $jjwgMaps->is_valid_lng(-180) );
374
375
    }
376
377
378
    public function testis_valid_lat() {
379
380
    	$jjwgMaps = new jjwg_Maps();
381
    	
382
    	//test with invalid values
383
    	$this->assertEquals(false, $jjwgMaps->is_valid_lat('') );
384
    	$this->assertEquals(false, $jjwgMaps->is_valid_lat(91) );
385
    	$this->assertEquals(false, $jjwgMaps->is_valid_lat(-91) );
386
    	 
387
    	//test with valid values
388
    	$this->assertEquals(true, $jjwgMaps->is_valid_lat(90) );
389
    	$this->assertEquals(true, $jjwgMaps->is_valid_lat(-90) );
390
    	
391
    }
392
393
394
    public function testlogGeocodeInfo() {
395
396
    	$jjwgMaps = new jjwg_Maps();
397
    	
398
    	$bean = new Meeting();
399
    	$bean->jjwg_maps_lat_c = "100";
400
    	$bean->jjwg_maps_lng_c = "40";
401
    	
402
    	//execute the method and test if it works and does not throws an exception.
403
    	try {
404
    		$jjwgMaps->logGeocodeInfo($bean);
405
    		$this->assertTrue(true);
406
    	}
407
    	catch (Exception $e) {
408
    		$this->fail();
409
    	}
410
    	
411
    	
412
    }
413
414
   
415
    public function testgetProspectLists()
416
    {
417
    	$result = getProspectLists();
418
    	$this->assertTrue(is_array($result));	
419
    }
420
    
421
    
422
}
423
424