|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class CallTest extends PHPUnit_Framework_TestCase |
|
5
|
|
|
{ |
|
6
|
|
|
public function testCall() |
|
7
|
|
|
{ |
|
8
|
|
|
//execute the contructor and check for the Object type and attributes |
|
9
|
|
|
$call = new Call(); |
|
10
|
|
|
$this->assertInstanceOf('Call', $call); |
|
11
|
|
|
$this->assertInstanceOf('SugarBean', $call); |
|
12
|
|
|
|
|
13
|
|
|
$this->assertAttributeEquals('Calls', 'module_dir', $call); |
|
14
|
|
|
$this->assertAttributeEquals('Call', 'object_name', $call); |
|
15
|
|
|
$this->assertAttributeEquals('calls', 'table_name', $call); |
|
16
|
|
|
$this->assertAttributeEquals('calls_users', 'rel_users_table', $call); |
|
17
|
|
|
$this->assertAttributeEquals('calls_contacts', 'rel_contacts_table', $call); |
|
18
|
|
|
$this->assertAttributeEquals('calls_leads', 'rel_leads_table', $call); |
|
19
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $call); |
|
20
|
|
|
$this->assertAttributeEquals(true, 'importable', $call); |
|
21
|
|
|
$this->assertAttributeEquals(false, 'syncing', $call); |
|
22
|
|
|
$this->assertAttributeEquals(true, 'update_vcal', $call); |
|
23
|
|
|
$this->assertAttributeEquals(array(0 => '00', 15 => '15', 30 => '30', 45 => '45'), 'minutes_values', $call); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testACLAccess() |
|
27
|
|
|
{ |
|
28
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
29
|
|
|
|
|
30
|
|
|
$call = new Call(); |
|
31
|
|
|
|
|
32
|
|
|
//test without setting recurring_source attribute |
|
33
|
|
|
$this->assertTrue($call->ACLAccess('')); |
|
34
|
|
|
$this->assertTrue($call->ACLAccess('edit')); |
|
35
|
|
|
|
|
36
|
|
|
//test with recurring_source attribute set |
|
37
|
|
|
$call->recurring_source = 'test'; |
|
38
|
|
|
$this->assertFalse($call->ACLAccess('edit')); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testSaveAndMarkDeleted() |
|
42
|
|
|
{ |
|
43
|
|
|
$call = new Call(); |
|
44
|
|
|
|
|
45
|
|
|
$call->name = 'test'; |
|
46
|
|
|
$call->id = $call->save(); |
|
47
|
|
|
|
|
48
|
|
|
//test for record ID to verify that record is saved |
|
49
|
|
|
$this->assertTrue(isset($call->id)); |
|
50
|
|
|
$this->assertEquals(36, strlen($call->id)); |
|
51
|
|
|
|
|
52
|
|
|
//mark the record as deleted and verify that this record cannot be retrieved anymore. |
|
53
|
|
|
$call->mark_deleted($call->id); |
|
54
|
|
|
$result = $call->retrieve($call->id); |
|
55
|
|
|
$this->assertEquals(null, $result); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testget_contacts() |
|
59
|
|
|
{ |
|
60
|
|
|
$call = new Call(); |
|
61
|
|
|
$call->id = 1; |
|
62
|
|
|
|
|
63
|
|
|
//execute the method and verify if it returns an array |
|
64
|
|
|
$result = $call->get_contacts(); |
|
65
|
|
|
$this->assertTrue(is_array($result)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testget_summary_text() |
|
69
|
|
|
{ |
|
70
|
|
|
$call = new Call(); |
|
71
|
|
|
|
|
72
|
|
|
//test without setting name |
|
73
|
|
|
$this->assertEquals(null, $call->get_summary_text()); |
|
74
|
|
|
|
|
75
|
|
|
//test with name set |
|
76
|
|
|
$call->name = 'test'; |
|
77
|
|
|
$this->assertEquals('test', $call->get_summary_text()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testcreate_list_query() |
|
81
|
|
|
{ |
|
82
|
|
|
$call = new Call(); |
|
83
|
|
|
|
|
84
|
|
|
//test with empty string params |
|
85
|
|
|
$expected = "SELECT \n calls.*,\n users.user_name as assigned_user_name FROM calls \n LEFT JOIN users\n ON calls.assigned_user_id=users.id where calls.deleted=0 ORDER BY calls.name"; |
|
86
|
|
|
$actual = $call->create_list_query('', ''); |
|
87
|
|
|
$this->assertSame($expected, $actual); |
|
88
|
|
|
|
|
89
|
|
|
//test with valid string params |
|
90
|
|
|
$expected = "SELECT \n calls.*,\n users.user_name as assigned_user_name FROM calls \n LEFT JOIN users\n ON calls.assigned_user_id=users.id where users.user_name=\"\" AND calls.deleted=0 ORDER BY calls.name"; |
|
91
|
|
|
$actual = $call->create_list_query('name', 'users.user_name=""'); |
|
92
|
|
|
$this->assertSame($expected, $actual); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testcreate_export_query() |
|
96
|
|
|
{ |
|
97
|
|
|
$call = new Call(); |
|
98
|
|
|
|
|
99
|
|
|
//test with empty string params |
|
100
|
|
|
$expected = 'SELECT calls.*, users.user_name as assigned_user_name FROM calls LEFT JOIN users ON calls.assigned_user_id=users.id where calls.deleted=0 ORDER BY calls.name'; |
|
101
|
|
|
$actual = $call->create_export_query('', ''); |
|
102
|
|
|
$this->assertSame($expected, $actual); |
|
103
|
|
|
//var_dump($actual); |
|
104
|
|
|
|
|
105
|
|
|
//test with empty string params |
|
106
|
|
|
$expected = 'SELECT calls.*, users.user_name as assigned_user_name FROM calls LEFT JOIN users ON calls.assigned_user_id=users.id where users.user_name="" AND calls.deleted=0 ORDER BY calls.name'; |
|
107
|
|
|
$actual = $call->create_export_query('name', 'users.user_name=""'); |
|
108
|
|
|
$this->assertSame($expected, $actual); |
|
109
|
|
|
//var_dump($actual); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function testfill_in_additional_detail_fields() |
|
113
|
|
|
{ |
|
114
|
|
|
$call = new Call(); |
|
115
|
|
|
|
|
116
|
|
|
//execute the method and verify it sets up the intended fields |
|
117
|
|
|
$call->fill_in_additional_detail_fields(); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertEquals('0', $call->duration_hours); |
|
120
|
|
|
$this->assertEquals('15', $call->duration_minutes); |
|
121
|
|
|
$this->assertEquals(-1, $call->reminder_time); |
|
122
|
|
|
$this->assertEquals(false, $call->reminder_checked); |
|
123
|
|
|
$this->assertEquals(-1, $call->email_reminder_time); |
|
124
|
|
|
$this->assertEquals(false, $call->email_reminder_checked); |
|
125
|
|
|
$this->assertEquals('Accounts', $call->parent_type); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testget_list_view_data() |
|
129
|
|
|
{ |
|
130
|
|
|
$call = new Call(); |
|
131
|
|
|
|
|
132
|
|
|
$call->assigned_user_id = 1; |
|
133
|
|
|
$call->created_by = 1; |
|
134
|
|
|
$call->modified_user_id = 1; |
|
135
|
|
|
|
|
136
|
|
|
//execute the method and verify that it retunrs expected results |
|
137
|
|
|
$expected = array( |
|
138
|
|
|
'MODIFIED_USER_ID' => 1, |
|
139
|
|
|
'CREATED_BY' => 1, |
|
140
|
|
|
'DELETED' => 0, |
|
141
|
|
|
'ASSIGNED_USER_ID' => 1, |
|
142
|
|
|
'STATUS' => 'Planned', |
|
143
|
|
|
'REMINDER_TIME' => '-1', |
|
144
|
|
|
'EMAIL_REMINDER_TIME' => '-1', |
|
145
|
|
|
'EMAIL_REMINDER_SENT' => '0', |
|
146
|
|
|
'REPEAT_INTERVAL' => '1', |
|
147
|
|
|
'SET_COMPLETE' => '~' |
|
148
|
|
|
.preg_quote('<a id=\'\' onclick=\'SUGAR.util.closeActivityPanel.show("Calls","","Held","listview","1");\'><img src="themes/SuiteR/images/close_inline.png?v=') |
|
149
|
|
|
.'[\w-]+' |
|
150
|
|
|
.preg_quote('" border=\'0\' alt="Close" /></a>').'~', |
|
151
|
|
|
'DATE_START' => '<font class=\'overdueTask\'></font>', |
|
152
|
|
|
'CONTACT_ID' => null, |
|
153
|
|
|
'CONTACT_NAME' => null, |
|
154
|
|
|
'PARENT_NAME' => '', |
|
155
|
|
|
'REMINDER_CHECKED' => false, |
|
156
|
|
|
'EMAIL_REMINDER_CHECKED' => false, |
|
157
|
|
|
); |
|
158
|
|
|
|
|
159
|
|
|
$actual = $call->get_list_view_data(); |
|
160
|
|
|
foreach ($expected as $expectedKey => $expectedVal) { |
|
161
|
|
|
if ($expectedKey == 'SET_COMPLETE') { |
|
162
|
|
|
$this->assertRegExp($expected[$expectedKey], $actual[$expectedKey]); |
|
163
|
|
|
} else { |
|
164
|
|
|
$this->assertSame($expected[$expectedKey], $actual[$expectedKey]); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
$this->assertEquals('Administrator', $call->assigned_user_name); |
|
169
|
|
|
$this->assertEquals('Administrator', $call->created_by_name); |
|
170
|
|
|
$this->assertEquals('Administrator', $call->modified_by_name); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function testset_notification_body() |
|
174
|
|
|
{ |
|
175
|
|
|
$call = new Call(); |
|
176
|
|
|
|
|
177
|
|
|
//test with attributes preset and verify template variables are set accordingly |
|
178
|
|
|
|
|
179
|
|
|
$call->name = 'test'; |
|
180
|
|
|
$call->duration_hours = '1'; |
|
181
|
|
|
$call->duration_minutes = '10'; |
|
182
|
|
|
$call->status = 'Planned'; |
|
183
|
|
|
$call->description = 'some text'; |
|
184
|
|
|
$call->date_start = '2015-09-01 00:02:03'; |
|
185
|
|
|
$call->current_notify_user = new User(1); |
|
186
|
|
|
$call->current_notify_user->new_assigned_user_name = 'Admin'; |
|
187
|
|
|
|
|
188
|
|
|
$result = $call->set_notification_body(new Sugar_Smarty(), $call); |
|
189
|
|
|
|
|
190
|
|
|
$this->assertEquals($call->name, $result->_tpl_vars['CALL_SUBJECT']); |
|
191
|
|
|
$this->assertEquals($call->current_notify_user->new_assigned_user_name, $result->_tpl_vars['CALL_TO']); |
|
192
|
|
|
$this->assertEquals($call->duration_hours, $result->_tpl_vars['CALL_HOURS']); |
|
193
|
|
|
$this->assertEquals($call->duration_minutes, $result->_tpl_vars['CALL_MINUTES']); |
|
194
|
|
|
$this->assertEquals($call->status, $result->_tpl_vars['CALL_STATUS']); |
|
195
|
|
|
$this->assertEquals('09/01/2015 00:02 UTC(+00:00)', $result->_tpl_vars['CALL_STARTDATE']); |
|
196
|
|
|
$this->assertEquals($call->description, $result->_tpl_vars['CALL_DESCRIPTION']); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function testget_call_users() |
|
200
|
|
|
{ |
|
201
|
|
|
$call = new Call(); |
|
202
|
|
|
$call->id = 1; |
|
203
|
|
|
|
|
204
|
|
|
//execute the method and verify it returns an array |
|
205
|
|
|
$result = $call->get_call_users(); |
|
206
|
|
|
$this->assertTrue(is_array($result)); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function testget_invite_calls() |
|
210
|
|
|
{ |
|
211
|
|
|
$call = new Call(); |
|
212
|
|
|
$user = new User(1); |
|
213
|
|
|
|
|
214
|
|
|
//execute the method and verify it returns an array |
|
215
|
|
|
$result = $call->get_invite_calls($user); |
|
216
|
|
|
$this->assertTrue(is_array($result)); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
public function testset_accept_status() |
|
220
|
|
|
{ |
|
221
|
|
|
$call = new Call(); |
|
222
|
|
|
$call->id = 1; |
|
223
|
|
|
|
|
224
|
|
|
//test for calls Users and delete the created linked records afterwards |
|
225
|
|
|
$user = new User(); |
|
226
|
|
|
$user->id = '1'; |
|
227
|
|
|
|
|
228
|
|
|
$call->set_accept_status($user, 'test'); |
|
229
|
|
|
|
|
230
|
|
|
$call_users = $call->get_linked_beans('users', $call->object_name); |
|
231
|
|
|
$this->assertEquals(1, count($call_users)); |
|
232
|
|
|
|
|
233
|
|
|
$call->delete_linked($call->id); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
public function testget_notification_recipients() |
|
237
|
|
|
{ |
|
238
|
|
|
$call = new Call(); |
|
239
|
|
|
|
|
240
|
|
|
//test without setting any user list |
|
241
|
|
|
$result = $call->get_notification_recipients(); |
|
242
|
|
|
$this->assertTrue(is_array($result)); |
|
243
|
|
|
|
|
244
|
|
|
//test with a user in notofication list set |
|
245
|
|
|
$call->users_arr = array(1); |
|
246
|
|
|
$result = $call->get_notification_recipients(); |
|
247
|
|
|
$this->assertTrue(is_array($result)); |
|
248
|
|
|
$this->assertEquals(1, count($result)); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
public function testbean_implements() |
|
252
|
|
|
{ |
|
253
|
|
|
$call = new Call(); |
|
254
|
|
|
$this->assertEquals(false, $call->bean_implements('')); //test with blank value |
|
255
|
|
|
$this->assertEquals(false, $call->bean_implements('test')); //test with invalid value |
|
256
|
|
|
$this->assertEquals(true, $call->bean_implements('ACL')); //test with valid value |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function testlistviewACLHelper() |
|
260
|
|
|
{ |
|
261
|
|
|
$call = new Call(); |
|
262
|
|
|
$expected = array('MAIN' => 'a', 'PARENT' => 'a', 'CONTACT' => 'a'); |
|
263
|
|
|
$actual = $call->listviewACLHelper(); |
|
264
|
|
|
$this->assertSame($expected, $actual); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
public function testsave_relationship_changes() |
|
268
|
|
|
{ |
|
269
|
|
|
$call = new Call(); |
|
270
|
|
|
|
|
271
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
272
|
|
|
try { |
|
273
|
|
|
$call->save_relationship_changes(true); |
|
274
|
|
|
$this->assertTrue(true); |
|
275
|
|
|
} catch (Exception $e) { |
|
276
|
|
|
$this->fail(); |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
public function testgetDefaultStatus() |
|
281
|
|
|
{ |
|
282
|
|
|
$call = new Call(); |
|
283
|
|
|
$result = $call->getDefaultStatus(); |
|
284
|
|
|
$this->assertEquals('Planned', $result); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|