Completed
Push — CI ( ee6bd7...0f01dd )
by Adam
22:32
created

EAPMTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 169
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 169
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testEAPM() 0 18 1
A testbean_implements() 0 9 1
A testgetLoginInfo() 0 14 1
A testcreate_new_list_query() 0 16 1
B testsaveAndMarkDeletedAndValidated() 0 35 1
A testfill_in_additional_detail_fields() 0 14 2
A testfill_in_additional_list_fields() 0 14 2
A testsave_cleanup() 0 12 1
A testdelete_user_accounts() 0 14 2
A testgetEAPMExternalApiDropDown() 0 6 1
1
<?PHP
2
3
class EAPMTest extends PHPUnit_Framework_TestCase{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
	
6
	public function testEAPM() {
7
	
8
		//execute the contructor and check for the Object type and  attributes
9
		$eapm = new EAPM();
10
		$this->assertInstanceOf('EAPM',$eapm);
11
		$this->assertInstanceOf('Basic',$eapm);
12
		$this->assertInstanceOf('SugarBean',$eapm);
13
			
14
		$this->assertAttributeEquals('EAPM', 'module_dir', $eapm);
15
		$this->assertAttributeEquals('EAPM', 'object_name', $eapm);
16
		$this->assertAttributeEquals('eapm', 'table_name', $eapm);
17
		$this->assertAttributeEquals(true, 'new_schema', $eapm);
18
		$this->assertAttributeEquals(false, 'importable', $eapm);
19
		$this->assertAttributeEquals(false, 'validated', $eapm);
20
		$this->assertAttributeEquals(true, 'disable_row_level_security', $eapm);
21
	
22
	
23
	}
24
	
25
	public function testbean_implements()
26
	{
27
		error_reporting(E_ERROR | E_PARSE);
28
		
29
		$eapm = new EAPM();
30
		$this->assertEquals(false, $eapm->bean_implements('')); //test with blank value
31
		$this->assertEquals(false, $eapm->bean_implements('test')); //test with invalid value
32
		$this->assertEquals(true, $eapm->bean_implements('ACL')); //test with valid value
33
	}
34
35
	public function testgetLoginInfo()
36
	{
37
		$eapm = new EAPM();
38
		
39
		//test with default value/false
40
		$result = $eapm->getLoginInfo('');
41
		$this->assertEquals(null,$result);
42
		
43
		
44
		//test with true
45
		$result = $eapm->getLoginInfo('',true);
46
		$this->assertEquals(null,$result);
47
		
48
	}
49
50
	public function testcreate_new_list_query() 
51
	{
52
		$eapm = new EAPM();
53
		
54
		//test with empty string params
55
		$expected = " SELECT  eapm.*  , jt0.user_name modified_by_name , jt0.created_by modified_by_name_owner  , 'Users' modified_by_name_mod , jt1.user_name created_by_name , jt1.created_by created_by_name_owner  , 'Users' created_by_name_mod , jt2.user_name assigned_user_name , jt2.created_by assigned_user_name_owner  , 'Users' assigned_user_name_mod FROM eapm   LEFT JOIN  users jt0 ON eapm.modified_user_id=jt0.id AND jt0.deleted=0\n\n AND jt0.deleted=0  LEFT JOIN  users jt1 ON eapm.created_by=jt1.id AND jt1.deleted=0\n\n AND jt1.deleted=0  LEFT JOIN  users jt2 ON eapm.assigned_user_id=jt2.id AND jt2.deleted=0\n\n AND jt2.deleted=0 where ( eapm.assigned_user_id ='' ) AND eapm.deleted=0";
56
		$actual = $eapm->create_new_list_query('','');
57
		$this->assertSame($expected,$actual);
58
		
59
		
60
		//test with valid string params
61
		$expected = " SELECT  eapm.*  , jt0.user_name modified_by_name , jt0.created_by modified_by_name_owner  , 'Users' modified_by_name_mod , jt1.user_name created_by_name , jt1.created_by created_by_name_owner  , 'Users' created_by_name_mod , jt2.user_name assigned_user_name , jt2.created_by assigned_user_name_owner  , 'Users' assigned_user_name_mod FROM eapm   LEFT JOIN  users jt0 ON eapm.modified_user_id=jt0.id AND jt0.deleted=0\n\n AND jt0.deleted=0  LEFT JOIN  users jt1 ON eapm.created_by=jt1.id AND jt1.deleted=0\n\n AND jt1.deleted=0  LEFT JOIN  users jt2 ON eapm.assigned_user_id=jt2.id AND jt2.deleted=0\n\n AND jt2.deleted=0 where (eapm.name=\"\" AND  eapm.assigned_user_id ='' ) AND eapm.deleted=0";
62
		$actual = $eapm->create_new_list_query('eapm.id','eapm.name=""');
63
		$this->assertSame($expected,$actual);
64
		
65
	}
66
67
	public function testsaveAndMarkDeletedAndValidated() {
68
69
		$eapm = new EAPM();
70
		
71
		$eapm->name = "test";
72
		$eapm->url ="test_url";
73
		$eapm->application = "webex";
74
75
		//test validated method initially
76
		$this->assertEquals(false, $eapm->validated());
77
		
78
		
79
		$eapm->save();
80
		
81
		//test for record ID to verify that record is saved
82
		$this->assertTrue(isset($eapm->id));
83
		$this->assertEquals(36, strlen($eapm->id));
84
		
85
		
86
		//test validated method finally after save
87
		$this->assertEquals(null, $eapm->validated());
88
		
89
		
90
		//retrieve back to test if validated attribute is updated in db
91
		$eapmValidated = $eapm->retrieve($eapm->id);
0 ignored issues
show
Unused Code introduced by
$eapmValidated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92
		//$this->assertEquals(1, $eapmValidated->validated);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
93
		$this->markTestSkipped('Validated column never gets updated in Db ');
94
		
95
		
96
		//mark the record as deleted and verify that this record cannot be retrieved anymore.
97
		$eapm->mark_deleted($eapm->id);
98
		$result = $eapm->retrieve($eapm->id);
99
		$this->assertEquals(null,$result);
100
		
101
	}
102
103
104
	public function testfill_in_additional_detail_fields()
105
	{
106
		$eapm = new EAPM();
107
		
108
		//execute the method and test if it works and does not throws an exception.
109
		try {
110
			$eapm->fill_in_additional_detail_fields();
111
			$this->assertTrue(true);
112
		}
113
		catch (Exception $e) {
114
			$this->fail();
115
		}
116
117
	}
118
119
	public function testfill_in_additional_list_fields()
120
	{
121
		$eapm = new EAPM();
122
		
123
		//execute the method and test if it works and does not throws an exception.
124
		try {
125
			$eapm->fill_in_additional_list_fields();
126
			$this->assertTrue(true);
127
		}
128
		catch (Exception $e) {
129
			$this->fail();
130
		}
131
132
	}
133
134
	public function testsave_cleanup()
135
	{
136
		$eapm = new EAPM();
137
		
138
		//execute the method and verify attributes are set accordingly
139
		$eapm->save_cleanup();
140
		
141
		$this->assertEquals("", $eapm->oauth_token );
142
		$this->assertEquals("", $eapm->oauth_secret );
143
		$this->assertEquals("", $eapm->api_data );
144
145
	}
146
147
148
	public function testdelete_user_accounts(){
149
		
150
		$eapm = new EAPM();
151
		
152
		//execute the method and test if it works and does not throws an exception.
153
		try {
154
			$eapm->delete_user_accounts(1);
155
			$this->assertTrue(true);
156
		}
157
		catch (Exception $e) {
158
			$this->fail();
159
		}
160
		
161
	}
162
163
	
164
	public function testgetEAPMExternalApiDropDown() {
165
	
166
		$result = getEAPMExternalApiDropDown();
167
		$this->assertEquals(array(""=>""),$result);
168
		
169
	}
170
	
171
}
172
173
174
175