1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class EmployeeTest extends PHPUnit_Framework_TestCase { |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
public function testEmployee() { |
7
|
|
|
|
8
|
|
|
//execute the contructor and check for the Object type and attributes |
9
|
|
|
$employee = new Employee(); |
10
|
|
|
$this->assertInstanceOf('Employee',$employee); |
11
|
|
|
$this->assertInstanceOf('Person',$employee); |
12
|
|
|
$this->assertInstanceOf('SugarBean',$employee); |
13
|
|
|
|
14
|
|
|
$this->assertAttributeEquals('Employees', 'module_dir', $employee); |
15
|
|
|
$this->assertAttributeEquals('Employee', 'object_name', $employee); |
16
|
|
|
$this->assertAttributeEquals('users', 'table_name', $employee); |
17
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $employee); |
18
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
public function testget_summary_text() { |
23
|
|
|
|
24
|
|
|
error_reporting(E_ERROR | E_PARSE); |
25
|
|
|
|
26
|
|
|
$employee = new Employee(); |
27
|
|
|
|
28
|
|
|
//test without setting name |
29
|
|
|
$this->assertEquals(' ',$employee->get_summary_text()); |
30
|
|
|
|
31
|
|
|
//test with name set |
32
|
|
|
$employee->retrieve(1); |
33
|
|
|
$this->assertEquals('Administrator',$employee->get_summary_text()); |
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testfill_in_additional_list_fields() { |
39
|
|
|
|
40
|
|
|
$employee = new Employee(); |
41
|
|
|
|
42
|
|
|
//execute the method and test if it works and does not throws an exception. |
43
|
|
|
try { |
44
|
|
|
$employee->fill_in_additional_list_fields(); |
45
|
|
|
$this->assertTrue(true); |
46
|
|
|
} |
47
|
|
|
catch (Exception $e) { |
48
|
|
|
$this->fail(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testfill_in_additional_detail_fields() |
54
|
|
|
{ |
55
|
|
|
$employee = new Employee(); |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
//test with a empty employee bean |
59
|
|
|
$employee->fill_in_additional_detail_fields(); |
60
|
|
|
$this->assertEquals("", $employee->reports_to_name); |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
//test with a valid employee bean |
64
|
|
|
$employee->retrieve(1); |
65
|
|
|
$employee->fill_in_additional_detail_fields(); |
66
|
|
|
$this->assertEquals("", $employee->reports_to_name); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testretrieve_employee_id() |
71
|
|
|
{ |
72
|
|
|
$employee = new Employee(); |
73
|
|
|
//$this->assertEquals('1' ,$employee->retrieve_employee_id('admin')); |
74
|
|
|
|
75
|
|
|
$this->markTestSkipped('Bug in query: employee_name parameter is wrongly used as user_name'); |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function testverify_data() |
81
|
|
|
{ |
82
|
|
|
$employee = new Employee(); |
83
|
|
|
$this->assertEquals(true ,$employee->verify_data() ); |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testget_list_view_data(){ |
88
|
|
|
|
89
|
|
|
$employee = new Employee(); |
90
|
|
|
|
91
|
|
|
$expected = array ( |
92
|
|
|
'SUGAR_LOGIN' => '1', |
93
|
|
|
'FULL_NAME' => ' ', |
94
|
|
|
'NAME' => ' ', |
95
|
|
|
'IS_ADMIN' => '0', |
96
|
|
|
'EXTERNAL_AUTH_ONLY' => '0', |
97
|
|
|
'RECEIVE_NOTIFICATIONS' => '1', |
98
|
|
|
'DELETED' => 0, |
99
|
|
|
'PORTAL_ONLY' => '0', |
100
|
|
|
'SHOW_ON_EMPLOYEES' => '1', |
101
|
|
|
'ENCODED_NAME' => ' ', |
102
|
|
|
'EMAIL1' => '', |
103
|
|
|
'EMAIL1_LINK' => '<a href=\'javascript:void(0);\' onclick=\'SUGAR.quickCompose.init({"fullComposeUrl":"contact_id=\\u0026parent_type=Employees\\u0026parent_id=\\u0026parent_name=+\\u0026to_addrs_ids=\\u0026to_addrs_names=\\u0026to_addrs_emails=\\u0026to_email_addrs=+%26nbsp%3B%26lt%3B%26gt%3B\\u0026return_module=Employees\\u0026return_action=ListView\\u0026return_id=","composePackage":{"contact_id":"","parent_type":"Employees","parent_id":"","parent_name":" ","to_addrs_ids":"","to_addrs_names":"","to_addrs_emails":"","to_email_addrs":" \\u003C\\u003E","return_module":"Employees","return_action":"ListView","return_id":""}});\' class=\'\'>', |
104
|
|
|
'MESSENGER_TYPE' => '', |
105
|
|
|
'REPORTS_TO_NAME' => NULL, |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$actual = $employee->get_list_view_data(); |
109
|
|
|
$this->assertSame($expected, $actual); |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testlist_view_parse_additional_sections(){ |
114
|
|
|
|
115
|
|
|
$employee = new Employee(); |
116
|
|
|
|
117
|
|
|
//execute the method and test if it works and does not throws an exception. |
118
|
|
|
try { |
119
|
|
|
$employee->list_view_parse_additional_sections(new Sugar_Smarty(), $xTemplateSection); |
|
|
|
|
120
|
|
|
$this->assertTrue(true); |
121
|
|
|
} |
122
|
|
|
catch (Exception $e) { |
123
|
|
|
$this->fail(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testcreate_export_query() { |
130
|
|
|
|
131
|
|
|
$employee = new Employee(); |
132
|
|
|
|
133
|
|
|
//test with empty string params |
134
|
|
|
$expected = "SELECT id, user_name, first_name, last_name, description, date_entered, date_modified, modified_user_id, created_by, title, department, is_admin, phone_home, phone_mobile, phone_work, phone_other, phone_fax, address_street, address_city, address_state, address_postalcode, address_country, reports_to_id, portal_only, status, receive_notifications, employee_status, messenger_id, messenger_type, is_group FROM users WHERE users.deleted = 0 ORDER BY users.user_name"; |
135
|
|
|
$actual = $employee->create_export_query('',''); |
136
|
|
|
$this->assertSame($expected,$actual); |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
//test with valid string params |
140
|
|
|
$expected = "SELECT id, user_name, first_name, last_name, description, date_entered, date_modified, modified_user_id, created_by, title, department, is_admin, phone_home, phone_mobile, phone_work, phone_other, phone_fax, address_street, address_city, address_state, address_postalcode, address_country, reports_to_id, portal_only, status, receive_notifications, employee_status, messenger_id, messenger_type, is_group FROM users WHERE users.user_name=\"\" AND users.deleted = 0 ORDER BY users.id"; |
141
|
|
|
$actual = $employee->create_export_query('users.id','users.user_name=""'); |
142
|
|
|
$this->assertSame($expected,$actual); |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testpreprocess_fields_on_save() |
147
|
|
|
{ |
148
|
|
|
|
149
|
|
|
$employee = new Employee(); |
150
|
|
|
|
151
|
|
|
//execute the method and test if it works and does not throws an exception. |
152
|
|
|
try |
153
|
|
|
{ |
154
|
|
|
$employee->preprocess_fields_on_save(); |
155
|
|
|
$this->assertTrue(TRUE); |
156
|
|
|
} catch(Exception $e) |
157
|
|
|
{ |
158
|
|
|
$this->fail(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @todo: NEEDS FIXING! |
165
|
|
|
*/ |
166
|
|
|
public function testcreate_new_list_query() |
167
|
|
|
{ |
168
|
|
|
/* |
169
|
|
|
$employee = new Employee(); |
170
|
|
|
|
171
|
|
|
//test with empty string params |
172
|
|
|
$expected = " SELECT users.* , ' ' c_accept_status_fields , ' ' call_id , ' ' securitygroup_noninher_fields , ' ' securitygroup_id , LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as full_name, LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as name , jt2.last_name reports_to_name , jt2.created_by reports_to_name_owner , 'Users' reports_to_name_mod, ' ' m_accept_status_fields , ' ' meeting_id FROM users LEFT JOIN users jt2 ON users.reports_to_id=jt2.id AND jt2.deleted=0\n\n AND jt2.deleted=0 where ( users.portal_only = 0 ) AND users.deleted=0"; |
173
|
|
|
$actual = $employee->create_new_list_query('',''); |
174
|
|
|
$this->assertSame($expected,$actual); |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
//test with valid string params |
178
|
|
|
$expected = " SELECT users.* , ' ' c_accept_status_fields , ' ' call_id , ' ' securitygroup_noninher_fields , ' ' securitygroup_id , LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as full_name, LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,'')))) as name , jt2.last_name reports_to_name , jt2.created_by reports_to_name_owner , 'Users' reports_to_name_mod, ' ' m_accept_status_fields , ' ' meeting_id FROM users LEFT JOIN users jt2 ON users.reports_to_id=jt2.id AND jt2.deleted=0\n\n AND jt2.deleted=0 where (users.user_name=\"\" and users.portal_only = 0 ) AND users.deleted=0"; |
179
|
|
|
$actual = $employee->create_new_list_query('users.id','users.user_name=""'); |
180
|
|
|
$this->assertSame($expected,$actual); |
181
|
|
|
*/ |
182
|
|
|
$this->assertTrue(true, "NEEDS FIXING!"); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testhasCustomFields() |
187
|
|
|
{ |
188
|
|
|
$employee = new Employee(); |
189
|
|
|
$result = $employee->hasCustomFields(); |
190
|
|
|
$this->assertEquals(false,$result); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
?> |
196
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: