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

jjwg_Address_CacheTest::testSaveAndGetAddressCacheInfoAndDeleteAllAddressCache()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 39
rs 8.8571
c 1
b 0
f 1
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
4
class jjwg_Address_CacheTest extends PHPUnit_Framework_TestCase {
5
6
7
    public function testjjwg_Address_Cache() {
8
9
    	error_reporting(E_ERROR | E_PARSE);
10
    	
11
    	//execute the contructor and check for the Object type and  attributes
12
    	$jjwgAddressCache = new jjwg_Address_Cache();
13
    	$this->assertInstanceOf('jjwg_Address_Cache',$jjwgAddressCache);
14
    	$this->assertInstanceOf('Basic',$jjwgAddressCache);
15
    	$this->assertInstanceOf('SugarBean',$jjwgAddressCache);
16
    	
17
    	$this->assertAttributeEquals('jjwg_Address_Cache', 'module_dir', $jjwgAddressCache);
18
    	$this->assertAttributeEquals('jjwg_Address_Cache', 'object_name', $jjwgAddressCache);
19
    	$this->assertAttributeEquals('jjwg_address_cache', 'table_name', $jjwgAddressCache);
20
    	
21
    	$this->assertAttributeEquals(true, 'new_schema', $jjwgAddressCache);
22
    	$this->assertAttributeEquals(true, 'importable', $jjwgAddressCache);
23
    	$this->assertAttributeEquals(true, 'disable_row_level_security', $jjwgAddressCache);
24
    	
25
    }
26
    
27
28
    public function testconfiguration() {
29
30
    	$jjwgAddressCache = new jjwg_Address_Cache();
31
    	$jjwgAddressCache->configuration();
32
33
    	$this->assertInstanceOf('jjwg_Maps',$jjwgAddressCache->jjwg_Maps);
34
    	$this->assertTrue(is_array($jjwgAddressCache->settings));
35
    	$this->assertGreaterThan(0,count($jjwgAddressCache->settings));
36
    	
37
    }
38
39
40
41
    public function testSaveAndGetAddressCacheInfoAndDeleteAllAddressCache() {
42
        
43
    	$jjwgAddressCache = new jjwg_Address_Cache();
44
    	
45
    	
46
    	//test saveAddressCacheInfo() with empty info array
47
    	$ainfo = array();
48
    	$result = $jjwgAddressCache->saveAddressCacheInfo($ainfo);
49
    	$this->assertEquals(false, $result);
50
    	
51
    	
52
    	//test saveAddressCacheInfo() with a valid info array
53
    	$jjwgAddressCache->settings['address_cache_save_enabled'] = 1;
54
    	$ainfo = array( "address"=>"test", "lat"=>"24.861462", "lng"=>"67.009939", "description"=>"test description" );
55
    	$result = $jjwgAddressCache->saveAddressCacheInfo($ainfo);
56
    	$this->assertEquals(true, $result);
57
58
    	
59
    	//test getAddressCacheInfo() with empty info array
60
    	$result = $jjwgAddressCache->getAddressCacheInfo(array());
61
    	$this->assertEquals(false, $result);
62
    	 
63
    	
64
    	//test getAddressCacheInfo() with a valid info array
65
    	$jjwgAddressCache->settings['address_cache_get_enabled'] = 1;
66
    	$ainfo = array( "address"=>"test", "lat"=>"24.861462", "lng"=>"67.009939", "description"=>"test description" );
67
    	$result = $jjwgAddressCache->getAddressCacheInfo($ainfo);
68
    	$this->assertTrue(is_array($result));
69
    
70
    	
71
    	//test deleteAllAddressCache
72
    	$jjwgAddressCache->deleteAllAddressCache();
73
    	
74
    	
75
    	//verify that record cannot be retrieved anynore
76
    	$result = $jjwgAddressCache->getAddressCacheInfo($ainfo);
77
    	$this->assertEquals(false, $result);
78
    	
79
    }
80
81
    public function testis_valid_lng() {
82
		
83
    	$jjwgAddressCache = new jjwg_Address_Cache();
84
    	
85
    	//test with invalid values
86
    	$this->assertEquals(false, $jjwgAddressCache->is_valid_lng('') );
87
    	$this->assertEquals(false, $jjwgAddressCache->is_valid_lng(181) );
88
    	$this->assertEquals(false, $jjwgAddressCache->is_valid_lng(-181) );
89
    	
90
    	//test with valid values
91
    	$this->assertEquals(true, $jjwgAddressCache->is_valid_lng(180) );
92
    	$this->assertEquals(true, $jjwgAddressCache->is_valid_lng(-180) );
93
    }
94
95
96
    public function testis_valid_lat() {
97
98
    	$jjwgAddressCache = new jjwg_Address_Cache();
99
    	 
100
    	//test with invalid values
101
    	$this->assertEquals(false, $jjwgAddressCache->is_valid_lat('') );
102
    	$this->assertEquals(false, $jjwgAddressCache->is_valid_lat(91) );
103
    	$this->assertEquals(false, $jjwgAddressCache->is_valid_lat(-91) );
104
    	
105
    	//test with valid values
106
    	$this->assertEquals(true, $jjwgAddressCache->is_valid_lat(90) );
107
    	$this->assertEquals(true, $jjwgAddressCache->is_valid_lat(-90) );
108
    
109
    }
110
111
}
112