|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class MergeRecordTest extends PHPUnit_Framework_TestCase { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
public function testMergeRecord() { |
|
7
|
|
|
|
|
8
|
|
|
//execute the contructor and check for the Object type and attributes |
|
9
|
|
|
$mergeRecord = new MergeRecord(); |
|
10
|
|
|
|
|
11
|
|
|
$this->assertInstanceOf('MergeRecord',$mergeRecord); |
|
12
|
|
|
$this->assertInstanceOf('SugarBean',$mergeRecord); |
|
13
|
|
|
|
|
14
|
|
|
$this->assertAttributeEquals('MergeRecords', 'module_dir', $mergeRecord); |
|
15
|
|
|
$this->assertAttributeEquals('MergeRecord', 'object_name', $mergeRecord); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $mergeRecord); |
|
18
|
|
|
$this->assertAttributeEquals(true, 'acl_display_only', $mergeRecord); |
|
19
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testsave() { |
|
23
|
|
|
|
|
24
|
|
|
$mergeRecord = new MergeRecord(); |
|
|
|
|
|
|
25
|
|
|
//$mergeRecord->save(); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$this->markTestIncomplete('method has no implementation'); |
|
28
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testretrieve() { |
|
32
|
|
|
|
|
33
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
34
|
|
|
global $db; |
|
35
|
|
|
unset ($db->database); |
|
36
|
|
|
$db->checkConnection(); |
|
37
|
|
|
|
|
38
|
|
|
$mergeRecord = new MergeRecord(); |
|
39
|
|
|
|
|
40
|
|
|
//preset variables required |
|
41
|
|
|
$mergeRecord->merge_bean = "Users"; |
|
42
|
|
|
$_REQUEST['action'] = 'Step2'; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$mergeRecord->retrieve("1"); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertTrue(isset($mergeRecord->merge_bean->id)); |
|
48
|
|
|
$this->assertEquals(1, $mergeRecord->merge_bean->id); |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testload_merge_bean() { |
|
53
|
|
|
|
|
54
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
55
|
|
|
global $db; |
|
56
|
|
|
unset ($db->database); |
|
57
|
|
|
$db->checkConnection(); |
|
58
|
|
|
|
|
59
|
|
|
$mergeRecord = new MergeRecord(); |
|
60
|
|
|
|
|
61
|
|
|
//test without merge_id |
|
62
|
|
|
$mergeRecord->load_merge_bean("Contacts"); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertAttributeEquals('Contacts', 'merge_module', $mergeRecord); |
|
65
|
|
|
$this->assertAttributeEquals('Contact', 'merge_bean_class', $mergeRecord); |
|
66
|
|
|
$this->assertAttributeEquals('modules/Contacts/Contact.php', 'merge_bean_file_path', $mergeRecord); |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
//test with merge_id |
|
70
|
|
|
$mergeRecord->load_merge_bean("Users", false, 1); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertAttributeEquals('Users', 'merge_module', $mergeRecord); |
|
73
|
|
|
$this->assertAttributeEquals('User', 'merge_bean_class', $mergeRecord); |
|
74
|
|
|
$this->assertAttributeEquals('modules/Users/User.php', 'merge_bean_file_path', $mergeRecord); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertInstanceOf('User',$mergeRecord->merge_bean); |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
public function testload_merge_bean2() { |
|
83
|
|
|
|
|
84
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
85
|
|
|
global $db; |
|
86
|
|
|
unset ($db->database); |
|
87
|
|
|
$db->checkConnection(); |
|
88
|
|
|
|
|
89
|
|
|
$mergeRecord = new MergeRecord(); |
|
90
|
|
|
|
|
91
|
|
|
//test without merge_id |
|
92
|
|
|
$mergeRecord->load_merge_bean2("Contacts"); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertAttributeEquals('Contacts', 'merge_module2', $mergeRecord); |
|
95
|
|
|
$this->assertAttributeEquals('Contact', 'merge_bean_class2', $mergeRecord); |
|
96
|
|
|
$this->assertAttributeEquals('modules/Contacts/Contact.php', 'merge_bean_file_path2', $mergeRecord); |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
//test with merge_id |
|
100
|
|
|
$mergeRecord->load_merge_bean2("Users", false, 1); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertAttributeEquals('Users', 'merge_module2', $mergeRecord); |
|
103
|
|
|
$this->assertAttributeEquals('User', 'merge_bean_class2', $mergeRecord); |
|
104
|
|
|
$this->assertAttributeEquals('modules/Users/User.php', 'merge_bean_file_path2', $mergeRecord); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertInstanceOf('User',$mergeRecord->merge_bean2); |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testfill_in_additional_list_fields() { |
|
111
|
|
|
|
|
112
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
113
|
|
|
global $db; |
|
114
|
|
|
unset ($db->database); |
|
115
|
|
|
$db->checkConnection(); |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
$mergeRecord = new MergeRecord(); |
|
119
|
|
|
|
|
120
|
|
|
$mergeRecord->load_merge_bean("Users", false, 1); |
|
121
|
|
|
|
|
122
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
123
|
|
|
try { |
|
124
|
|
|
$mergeRecord->fill_in_additional_list_fields(); |
|
125
|
|
|
$this->assertTrue(true); |
|
126
|
|
|
} |
|
127
|
|
|
catch (Exception $e) { |
|
128
|
|
|
$this->fail(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function testfill_in_additional_detail_fields() { |
|
134
|
|
|
|
|
135
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
136
|
|
|
global $db; |
|
137
|
|
|
unset ($db->database); |
|
138
|
|
|
$db->checkConnection(); |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
$mergeRecord = new MergeRecord(); |
|
142
|
|
|
|
|
143
|
|
|
$mergeRecord->load_merge_bean("Users", false, 1); |
|
144
|
|
|
|
|
145
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
146
|
|
|
try { |
|
147
|
|
|
$mergeRecord->fill_in_additional_detail_fields(); |
|
148
|
|
|
$this->assertTrue(true); |
|
149
|
|
|
} |
|
150
|
|
|
catch (Exception $e) { |
|
151
|
|
|
$this->fail(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function testget_summary_text() { |
|
158
|
|
|
|
|
159
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
160
|
|
|
global $db; |
|
161
|
|
|
unset ($db->database); |
|
162
|
|
|
$db->checkConnection(); |
|
163
|
|
|
|
|
164
|
|
|
$mergeRecord = new MergeRecord(); |
|
165
|
|
|
|
|
166
|
|
|
$mergeRecord->load_merge_bean("Users"); |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
//test without setting name |
|
170
|
|
|
$this->assertEquals(Null,$mergeRecord->get_summary_text()); |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
//test with name set |
|
174
|
|
|
$mergeRecord->merge_bean->name = "test"; |
|
175
|
|
|
$this->assertEquals('test',$mergeRecord->get_summary_text()); |
|
176
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function testget_list_view_data() { |
|
180
|
|
|
|
|
181
|
|
|
$mergeRecord = new MergeRecord(); |
|
182
|
|
|
|
|
183
|
|
|
$mergeRecord->load_merge_bean("Users"); |
|
184
|
|
|
|
|
185
|
|
|
$result = $mergeRecord->get_list_view_data(); |
|
186
|
|
|
|
|
187
|
|
|
$this->assertTrue(is_array($result)); |
|
188
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
public function testbuild_generic_where_clause() { |
|
192
|
|
|
|
|
193
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
194
|
|
|
global $db; |
|
195
|
|
|
unset ($db->database); |
|
196
|
|
|
$db->checkConnection(); |
|
197
|
|
|
|
|
198
|
|
|
$mergeRecord = new MergeRecord(); |
|
199
|
|
|
|
|
200
|
|
|
$mergeRecord->load_merge_bean("Contacts"); |
|
201
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
//test with string |
|
204
|
|
|
$expected = "contacts.last_name like 'test%' or contacts.first_name like 'test%' or accounts.name like 'test%' or contacts.assistant like 'test%' or ea.email_address like 'test%'"; |
|
205
|
|
|
$actual = $mergeRecord->build_generic_where_clause('test'); |
|
206
|
|
|
$this->assertSame($expected,$actual); |
|
207
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
//test with number |
|
210
|
|
|
$expected = "contacts.last_name like '1%' or contacts.first_name like '1%' or accounts.name like '1%' or contacts.assistant like '1%' or ea.email_address like '1%' or contacts.phone_home like '%1%' or contacts.phone_mobile like '%1%' or contacts.phone_work like '%1%' or contacts.phone_other like '%1%' or contacts.phone_fax like '%1%' or contacts.assistant_phone like '%1%'"; |
|
211
|
|
|
$actual = $mergeRecord->build_generic_where_clause(1); |
|
212
|
|
|
$this->assertSame($expected,$actual); |
|
213
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
public function testbean_implements() { |
|
218
|
|
|
|
|
219
|
|
|
$mergeRecord = new MergeRecord(); |
|
220
|
|
|
|
|
221
|
|
|
$this->assertEquals(false, $mergeRecord->bean_implements('')); //test with blank value |
|
222
|
|
|
$this->assertEquals(false, $mergeRecord->bean_implements('test')); //test with invalid value |
|
223
|
|
|
$this->assertEquals(true, $mergeRecord->bean_implements('ACL')); //test with valid value |
|
224
|
|
|
|
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
public function testACLAccess(){ |
|
228
|
|
|
|
|
229
|
|
|
$mergeRecord = new MergeRecord(); |
|
230
|
|
|
|
|
231
|
|
|
//test without loading merge bean |
|
232
|
|
|
$this->assertEquals(true, $mergeRecord->ACLAccess('')); //test with valid value |
|
233
|
|
|
|
|
234
|
|
|
|
|
235
|
|
|
//test with merge bean loaded |
|
236
|
|
|
$mergeRecord->load_merge_bean("Meetings"); |
|
237
|
|
|
|
|
238
|
|
|
$this->assertEquals(true,$mergeRecord->ACLAccess('edit')); |
|
239
|
|
|
$this->assertEquals(true,$mergeRecord->ACLAccess('save')); |
|
240
|
|
|
$this->assertEquals(true,$mergeRecord->ACLAccess('editview')); |
|
241
|
|
|
$this->assertEquals(true,$mergeRecord->ACLAccess('delete')); |
|
242
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function testpopulate_search_params() { |
|
246
|
|
|
|
|
247
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
248
|
|
|
global $db; |
|
249
|
|
|
unset ($db->database); |
|
250
|
|
|
$db->checkConnection(); |
|
251
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
$mergeRecord = new MergeRecord(); |
|
254
|
|
|
|
|
255
|
|
|
$mergeRecord->load_merge_bean("Meetings"); |
|
256
|
|
|
|
|
257
|
|
|
$expected = array ( |
|
258
|
|
|
'id' => array ( 'name' => 'id', 'vname' => 'LBL_ID', 'type' => 'id', 'required' => true, 'reportable' => true, 'comment' => 'Unique identifier', 'inline_edit' => false, 'value' => '1', 'search_type' => 'Exact'), |
|
259
|
|
|
'name' => array ( 'name' => 'name','vname' => 'LBL_SUBJECT','required' => true, 'type' => 'name', 'dbType' => 'varchar', 'unified_search' => true, 'full_text_search' => array ('boost' => 3), 'len' => '50','comment' => 'Meeting name', 'importable' => 'required', 'value' => 'test', 'search_type' => 'Exact' ) |
|
260
|
|
|
); |
|
261
|
|
|
|
|
262
|
|
|
$mergeRecord->populate_search_params(array('nameSearchField'=>'test','idSearchField'=>'1')); |
|
263
|
|
|
|
|
264
|
|
|
$this->assertSame($expected, $mergeRecord->field_search_params); |
|
265
|
|
|
|
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
public function testget_inputs_for_search_params() |
|
269
|
|
|
{ |
|
270
|
|
|
|
|
271
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
272
|
|
|
|
|
273
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
274
|
|
|
global $db; |
|
275
|
|
|
unset ($db->database); |
|
276
|
|
|
$db->checkConnection(); |
|
277
|
|
|
|
|
278
|
|
|
|
|
279
|
|
|
$mergeRecord = new MergeRecord(); |
|
280
|
|
|
|
|
281
|
|
|
$mergeRecord->load_merge_bean("Meetings"); |
|
282
|
|
|
|
|
283
|
|
|
$expected = "<input type='hidden' name='idSearchField' value='1' />\n<input type='hidden' name='idSearchType' value='' />\n<input type='hidden' name='nameSearchField' value='test' />\n<input type='hidden' name='nameSearchType' value='' />\n"; |
|
284
|
|
|
|
|
285
|
|
|
$result = $mergeRecord->get_inputs_for_search_params(array('nameSearchField'=>'test','idSearchField'=>'1')); |
|
286
|
|
|
|
|
287
|
|
|
$this->assertSame($expected, $result); |
|
288
|
|
|
|
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
public function testemail_addresses_query() { |
|
292
|
|
|
|
|
293
|
|
|
$mergeRecord = new MergeRecord(); |
|
294
|
|
|
|
|
295
|
|
|
$expected = "accounts.id IN (SELECT ear.bean_id FROM email_addresses ea\n LEFT JOIN email_addr_bean_rel ear ON ea.id = ear.email_address_id \n WHERE ear.bean_module = 'Accounts'\n AND ear.bean_id != '1' \n AND ear.deleted = 0"; |
|
296
|
|
|
|
|
297
|
|
|
$result = $mergeRecord->email_addresses_query("accounts", "Accounts", 1); |
|
298
|
|
|
|
|
299
|
|
|
$this->assertSame($expected, $result); |
|
300
|
|
|
|
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
public function testrelease_name_query() { |
|
304
|
|
|
|
|
305
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
306
|
|
|
global $db; |
|
307
|
|
|
unset ($db->database); |
|
308
|
|
|
$db->checkConnection(); |
|
309
|
|
|
|
|
310
|
|
|
$mergeRecord = new MergeRecord(); |
|
311
|
|
|
|
|
312
|
|
|
//test with type = like |
|
313
|
|
|
$result = $mergeRecord->release_name_query("like", "test"); |
|
314
|
|
|
$this->assertSame(null, $result); |
|
315
|
|
|
|
|
316
|
|
|
//test with type = start |
|
317
|
|
|
$result = $mergeRecord->release_name_query("start", "test"); |
|
318
|
|
|
$this->assertSame(null, $result); |
|
319
|
|
|
|
|
320
|
|
|
|
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
public function testcreate_where_statement() { |
|
324
|
|
|
|
|
325
|
|
|
//unset and reconnect Db to resolve mysqli fetch exeception |
|
326
|
|
|
global $db; |
|
327
|
|
|
unset ($db->database); |
|
328
|
|
|
$db->checkConnection(); |
|
329
|
|
|
|
|
330
|
|
|
$mergeRecord = new MergeRecord(); |
|
331
|
|
|
|
|
332
|
|
|
$mergeRecord->load_merge_bean("Contacts"); |
|
333
|
|
|
$mergeRecord->populate_search_params(array('nameSearchField'=>'test','idSearchField'=>'1')); |
|
334
|
|
|
|
|
335
|
|
|
$expected = array( "contacts.id='1'", "contacts.name='test'", "contacts.id !=''" ); |
|
336
|
|
|
|
|
337
|
|
|
$actual = $mergeRecord->create_where_statement(); |
|
338
|
|
|
|
|
339
|
|
|
$this->assertSame( $expected, $actual); |
|
340
|
|
|
|
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
|
|
344
|
|
|
public function testgenerate_where_statement() { |
|
345
|
|
|
|
|
346
|
|
|
$mergeRecord = new MergeRecord(); |
|
347
|
|
|
|
|
348
|
|
|
$clauses = array( "contacts.id='1'", "contacts.name='test'", "contacts.id !=''" ); |
|
349
|
|
|
$expected = "contacts.id='1' AND contacts.name='test' AND contacts.id !=''"; |
|
350
|
|
|
|
|
351
|
|
|
$actual = $mergeRecord->generate_where_statement($clauses); |
|
352
|
|
|
|
|
353
|
|
|
$this->assertSame( $expected, $actual); |
|
354
|
|
|
|
|
355
|
|
|
//error_reporting(E_ALL); |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
} |
|
359
|
|
|
?> |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.