|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class AOW_WorkFlowTest extends PHPUnit_Framework_TestCase { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
public function testAOW_WorkFlow(){ |
|
7
|
|
|
|
|
8
|
|
|
//execute the contructor and check for the Object type and attributes |
|
9
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
10
|
|
|
$this->assertInstanceOf('AOW_WorkFlow',$aowWorkFlow); |
|
11
|
|
|
$this->assertInstanceOf('Basic',$aowWorkFlow); |
|
12
|
|
|
$this->assertInstanceOf('SugarBean',$aowWorkFlow); |
|
13
|
|
|
|
|
14
|
|
|
$this->assertAttributeEquals('AOW_WorkFlow', 'module_dir', $aowWorkFlow); |
|
15
|
|
|
$this->assertAttributeEquals('AOW_WorkFlow', 'object_name', $aowWorkFlow); |
|
16
|
|
|
$this->assertAttributeEquals('aow_workflow', 'table_name', $aowWorkFlow); |
|
17
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $aowWorkFlow); |
|
18
|
|
|
$this->assertAttributeEquals(true, 'disable_row_level_security', $aowWorkFlow); |
|
19
|
|
|
$this->assertAttributeEquals(false, 'importable', $aowWorkFlow); |
|
20
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testbean_implements(){ |
|
24
|
|
|
|
|
25
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
26
|
|
|
|
|
27
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
28
|
|
|
$this->assertEquals(false, $aowWorkFlow->bean_implements('')); //test with blank value |
|
29
|
|
|
$this->assertEquals(false, $aowWorkFlow->bean_implements('test')); //test with invalid value |
|
30
|
|
|
$this->assertEquals(true, $aowWorkFlow->bean_implements('ACL')); //test with valid value |
|
31
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testsave(){ |
|
35
|
|
|
|
|
36
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
37
|
|
|
|
|
38
|
|
|
$aowWorkFlow->name = "test"; |
|
39
|
|
|
$aowWorkFlow->flow_module = 'test'; |
|
40
|
|
|
|
|
41
|
|
|
$aowWorkFlow->save(); |
|
42
|
|
|
|
|
43
|
|
|
//test for record ID to verify that record is saved |
|
44
|
|
|
$this->assertTrue(isset($aowWorkFlow->id)); |
|
45
|
|
|
$this->assertEquals(36, strlen($aowWorkFlow->id)); |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
//mark the record as deleted and verify that this record cannot be retrieved anymore. |
|
49
|
|
|
$aowWorkFlow->mark_deleted($aowWorkFlow->id); |
|
50
|
|
|
$result = $aowWorkFlow->retrieve($aowWorkFlow->id); |
|
51
|
|
|
$this->assertEquals(null,$result); |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testload_flow_beans(){ |
|
56
|
|
|
|
|
57
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
58
|
|
|
|
|
59
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
60
|
|
|
try { |
|
61
|
|
|
$aowWorkFlow->load_flow_beans(); |
|
62
|
|
|
$this->assertTrue(true); |
|
63
|
|
|
} |
|
64
|
|
|
catch (Exception $e) { |
|
65
|
|
|
$this->fail(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
public function testrun_flows(){ |
|
72
|
|
|
|
|
73
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
74
|
|
|
|
|
75
|
|
|
$result = $aowWorkFlow->run_flows(); |
|
76
|
|
|
$this->assertTrue($result); |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
public function testrun_flow(){ |
|
82
|
|
|
|
|
83
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
84
|
|
|
|
|
85
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
86
|
|
|
try { |
|
87
|
|
|
$aowWorkFlow->run_flow(); |
|
88
|
|
|
$this->assertTrue(true); |
|
89
|
|
|
} |
|
90
|
|
|
catch (Exception $e) { |
|
91
|
|
|
$this->fail(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
public function testrun_bean_flows(){ |
|
98
|
|
|
|
|
99
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
100
|
|
|
|
|
101
|
|
|
//test with different modules. it always returns true |
|
102
|
|
|
|
|
103
|
|
|
$result = $aowWorkFlow->run_bean_flows(new AOS_Quotes()); |
|
104
|
|
|
$this->assertTrue($result); |
|
105
|
|
|
|
|
106
|
|
|
$result = $aowWorkFlow->run_bean_flows(new Call()); |
|
107
|
|
|
$this->assertTrue($result); |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
public function testget_flow_beans(){ |
|
113
|
|
|
|
|
114
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
115
|
|
|
|
|
116
|
|
|
//test for AOS_Quotes. it will return null as no test data is available |
|
117
|
|
|
$aowWorkFlow->flow_module = "AOS_Quotes"; |
|
118
|
|
|
$result = $aowWorkFlow->get_flow_beans(); |
|
119
|
|
|
$this->assertEquals(null,$result); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testbuild_flow_query_join(){ |
|
123
|
|
|
|
|
124
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
125
|
|
|
$query = Array(); |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
//test without type param |
|
129
|
|
|
$result = $aowWorkFlow->build_flow_query_join('aos_products_quotes', new AOS_Quotes(), '', Array()); |
|
130
|
|
|
$this->assertSame(array(), $result); |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
//test with type custom |
|
134
|
|
|
$expected = Array('join' => array('c' => 'LEFT JOIN calls_cstm c ON calls.id = c.id_c ' )); |
|
135
|
|
|
$result = $aowWorkFlow->build_flow_query_join('c', new Call(), 'custom', Array()); |
|
136
|
|
|
$this->assertSame($expected, $result); |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
//test with type relationship |
|
140
|
|
|
$expected = Array ( |
|
141
|
|
|
'join' =>array ("aos_products_quotes" => "LEFT JOIN aos_products_quotes aos_products_quotes ON aos_quotes.id=aos_products_quotes.parent_id AND aos_products_quotes.deleted=0\n\n"), |
|
142
|
|
|
'select' =>array ("aos_products_quotes.id AS 'aos_products_quotes_id'"), |
|
143
|
|
|
); |
|
144
|
|
|
$result = $aowWorkFlow->build_flow_query_join('aos_products_quotes', new AOS_Quotes(), 'relationship', Array()); |
|
145
|
|
|
$this->assertSame($expected, $result); |
|
146
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function testbuild_flow_query_where(){ |
|
150
|
|
|
|
|
151
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
152
|
|
|
|
|
153
|
|
|
//test without presetting required object attributes |
|
154
|
|
|
$expected = Array(); |
|
155
|
|
|
$query = $aowWorkFlow->build_flow_query_where(); |
|
156
|
|
|
$this->assertSame($expected,$query); |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
//test with module required attributes set |
|
161
|
|
|
$aowWorkFlow->id = '1'; |
|
162
|
|
|
$aowWorkFlow->flow_module = "Calls"; |
|
163
|
|
|
$expected = array ( |
|
164
|
|
|
'where' => array ('NOT EXISTS (SELECT * FROM aow_processed WHERE aow_processed.aow_workflow_id=\'1\' AND aow_processed.parent_id=calls.id AND aow_processed.status = \'Complete\' AND aow_processed.deleted = 0)', |
|
165
|
|
|
'calls.deleted = 0 ' ) |
|
166
|
|
|
); |
|
167
|
|
|
$query = $aowWorkFlow->build_flow_query_where(); |
|
168
|
|
|
$this->assertSame($expected,$query); |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
//test with flow_run_on and multiple_runs attributes set |
|
173
|
|
|
$expected = array ( |
|
174
|
|
|
'where' => array ('calls.date_entered > \'\'','calls.deleted = 0 '), |
|
175
|
|
|
); |
|
176
|
|
|
$aowWorkFlow->flow_run_on = 'New_Records'; |
|
177
|
|
|
$aowWorkFlow->multiple_runs = 1; |
|
178
|
|
|
$query = $aowWorkFlow->build_flow_query_where(); |
|
179
|
|
|
$this->assertSame($expected,$query); |
|
180
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function testbuild_query_where(){ |
|
184
|
|
|
|
|
185
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
186
|
|
|
|
|
187
|
|
|
//populate required values |
|
188
|
|
|
$call = new Call(); |
|
189
|
|
|
$aowCondition = new AOW_Condition(); |
|
190
|
|
|
$aowCondition->name = "test"; |
|
191
|
|
|
$aowCondition->module_path = base64_encode(serialize(array(''))); |
|
192
|
|
|
$aowCondition->field = "name"; |
|
193
|
|
|
$aowCondition->value = "testval"; |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
//test with contains operator |
|
198
|
|
|
$aowCondition->operator = "Contains"; |
|
199
|
|
|
$aowCondition->value_type = "Value"; |
|
200
|
|
|
$expected = array( |
|
201
|
|
|
"where"=> array(".name LIKE CONCAT('%', 'testval' ,'%')") |
|
202
|
|
|
); |
|
203
|
|
|
$query = $aowWorkFlow->build_query_where($aowCondition, $call); |
|
204
|
|
|
$this->assertEquals($expected, $query); |
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
//test for starts with operator |
|
209
|
|
|
$aowCondition->operator = "Starts_With"; |
|
210
|
|
|
$aowCondition->value_type = "Value"; |
|
211
|
|
|
|
|
212
|
|
|
$expected = array( |
|
213
|
|
|
"where"=> array(".name LIKE CONCAT('testval' ,'%')") |
|
214
|
|
|
); |
|
215
|
|
|
$query = $aowWorkFlow->build_query_where($aowCondition, $call); |
|
216
|
|
|
$this->assertEquals($expected, $query); |
|
217
|
|
|
|
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
|
|
//test for Equal_To operator |
|
221
|
|
|
$aowCondition->operator = "Equal_To"; |
|
222
|
|
|
$aowCondition->value_type = "Value"; |
|
223
|
|
|
|
|
224
|
|
|
$expected = array( |
|
225
|
|
|
"where"=> array(".name = 'testval'") |
|
226
|
|
|
); |
|
227
|
|
|
$query = $aowWorkFlow->build_query_where($aowCondition, $call); |
|
228
|
|
|
$this->assertEquals($expected, $query); |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
|
|
232
|
|
|
//test with value type Date |
|
233
|
|
|
$aowCondition->operator = "Equal_To"; |
|
234
|
|
|
$aowCondition->value_type = "Date"; |
|
235
|
|
|
|
|
236
|
|
|
$expected = array( |
|
237
|
|
|
"where"=> array('.name = DATE_ADD(calls., INTERVAL )') |
|
238
|
|
|
); |
|
239
|
|
|
|
|
240
|
|
|
$query = $aowWorkFlow->build_query_where($aowCondition, $call); |
|
241
|
|
|
$this->assertEquals($expected, $query); |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
//test with value type Field |
|
246
|
|
|
$aowCondition->operator = "Equal_To"; |
|
247
|
|
|
$aowCondition->value_type = "Field"; |
|
248
|
|
|
|
|
249
|
|
|
$expected = array( |
|
250
|
|
|
"where"=> array('.name = calls.testval') |
|
251
|
|
|
); |
|
252
|
|
|
|
|
253
|
|
|
$query = $aowWorkFlow->build_query_where($aowCondition, $call); |
|
254
|
|
|
$this->assertEquals($expected, $query); |
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function testcheck_valid_bean(){ |
|
260
|
|
|
|
|
261
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
262
|
|
|
$aowWorkFlow->flow_run_on = "New_Records"; |
|
263
|
|
|
|
|
264
|
|
|
$aosQuotes = new AOS_Quotes(); |
|
265
|
|
|
|
|
266
|
|
|
$result = $aowWorkFlow->check_valid_bean($aosQuotes); |
|
267
|
|
|
$this->assertTrue($result); |
|
268
|
|
|
|
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
public function testcompare_condition(){ |
|
272
|
|
|
|
|
273
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
274
|
|
|
|
|
275
|
|
|
//execute the method and verify that it returns valid values for all operators |
|
276
|
|
|
|
|
277
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition(1,1)); |
|
278
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition(1,2,'Not_Equal_To' )); |
|
279
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition(2,1,'Greater_Than' )); |
|
280
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition(1,2,'Less_Than' )); |
|
281
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition(5,4,'Greater_Than_or_Equal_To' )); |
|
282
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition(2,3,'Less_Than_or_Equal_To' )); |
|
283
|
|
|
$this->assertNotFalse($aowWorkFlow->compare_condition('test1','test','Contains' )); |
|
284
|
|
|
$this->assertNotFalse($aowWorkFlow->compare_condition('test1','test','Starts_With' )); |
|
285
|
|
|
$this->assertNotFalse($aowWorkFlow->compare_condition('test1','1','Ends_With' )); |
|
286
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition('','','is_null' )); |
|
287
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition('test2',array('test1','test2'),'One_of' )); |
|
288
|
|
|
$this->assertTrue($aowWorkFlow->compare_condition('test', array('test1','test2'),'Not_One_of' )); |
|
289
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
public function testcheck_in_group(){ |
|
293
|
|
|
|
|
294
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
295
|
|
|
|
|
296
|
|
|
//test with two different modules |
|
297
|
|
|
$this->assertFalse($aowWorkFlow->check_in_group(1, "Users", 1)); |
|
298
|
|
|
$this->assertFalse($aowWorkFlow->check_in_group(1, "Calls", 1)); |
|
299
|
|
|
|
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
|
|
303
|
|
|
public function testrun_actions(){ |
|
304
|
|
|
|
|
305
|
|
|
$aowWorkFlow = new AOW_WorkFlow(); |
|
306
|
|
|
|
|
307
|
|
|
//prepare the required objects and variables |
|
308
|
|
|
$aowWorkFlow->id = 1; |
|
309
|
|
|
|
|
310
|
|
|
$call = new Call(); |
|
311
|
|
|
$call->id = 1; |
|
312
|
|
|
|
|
313
|
|
|
//execute the method and verify if it creates records in processed table |
|
314
|
|
|
$result = $aowWorkFlow->run_actions($call); |
|
|
|
|
|
|
315
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
//test for a entry in AOW_Processed table. |
|
318
|
|
|
$processed = new AOW_Processed(); |
|
319
|
|
|
$processed->retrieve_by_string_fields(array('aow_workflow_id' => 1,'parent_id' => 1)); |
|
320
|
|
|
|
|
321
|
|
|
//test for record ID to verify that record is saved |
|
322
|
|
|
$this->assertTrue(isset($processed->id)); |
|
323
|
|
|
$this->assertEquals(36, strlen($processed->id)); |
|
324
|
|
|
|
|
325
|
|
|
|
|
326
|
|
|
//mark the record as deleted and verify that this record cannot be retrieved anymore. |
|
327
|
|
|
$processed->mark_deleted($processed->id); |
|
328
|
|
|
$result = $processed->retrieve($processed->id); |
|
329
|
|
|
$this->assertEquals(null,$result); |
|
330
|
|
|
|
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
|
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
?> |
|
337
|
|
|
|
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.