|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class AOR_ReportTest extends PHPUnit_Framework_TestCase { |
|
5
|
|
|
|
|
6
|
|
|
public function testAOR_Report(){ |
|
7
|
|
|
|
|
8
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
9
|
|
|
|
|
10
|
|
|
//execute the contructor and check for the Object type and attributes |
|
11
|
|
|
$aor_Report = new AOR_Report(); |
|
12
|
|
|
$this->assertInstanceOf('AOR_Report',$aor_Report); |
|
13
|
|
|
$this->assertInstanceOf('Basic',$aor_Report); |
|
14
|
|
|
$this->assertInstanceOf('SugarBean',$aor_Report); |
|
15
|
|
|
|
|
16
|
|
|
$this->assertAttributeEquals('AOR_Reports', 'module_dir', $aor_Report); |
|
17
|
|
|
$this->assertAttributeEquals('AOR_Report', 'object_name', $aor_Report); |
|
18
|
|
|
$this->assertAttributeEquals('aor_reports', 'table_name', $aor_Report); |
|
19
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $aor_Report); |
|
20
|
|
|
$this->assertAttributeEquals(true, 'disable_row_level_security', $aor_Report); |
|
21
|
|
|
$this->assertAttributeEquals(true, 'importable', $aor_Report); |
|
22
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testbean_implements(){ |
|
26
|
|
|
|
|
27
|
|
|
$aor_Report = new AOR_Report(); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals(false, $aor_Report->bean_implements('')); //test with blank value |
|
30
|
|
|
$this->assertEquals(false, $aor_Report->bean_implements('test')); //test with invalid value |
|
31
|
|
|
$this->assertEquals(true, $aor_Report->bean_implements('ACL')); //test with valid value |
|
32
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testsave(){ |
|
36
|
|
|
|
|
37
|
|
|
$aor_Report = new AOR_Report(); |
|
38
|
|
|
|
|
39
|
|
|
//populate value for aor_fields related/child object |
|
40
|
|
|
$_POST['aor_fields_field'][] = 'test_field'; |
|
41
|
|
|
$_POST['aor_fields_name'][] = 'test'; |
|
42
|
|
|
$_POST['aor_fields_module_path'][] = 'test_path'; |
|
43
|
|
|
$_POST['aor_fields_display'][] = '1'; |
|
44
|
|
|
$_POST['aor_fields_link'][] = '1'; |
|
45
|
|
|
$_POST['aor_fields_label'][] = 'test_label'; |
|
46
|
|
|
$_POST['aor_fields_field_function'][] = 'test_function'; |
|
47
|
|
|
$_POST['aor_fields_total'][] = 'total'; |
|
48
|
|
|
$_POST['aor_fields_group_by'][] = '1'; |
|
49
|
|
|
$_POST['aor_fields_group_order'][] = 'desc'; |
|
50
|
|
|
$_POST['aor_fields_group_display'][] = '1'; |
|
51
|
|
|
|
|
52
|
|
|
//populate values for aor_chart related/child object |
|
53
|
|
|
$_POST['aor_chart_id'] = array('test'=>''); |
|
54
|
|
|
$_POST['aor_chart_title'] = array('test'=>'test'); |
|
55
|
|
|
$_POST['aor_chart_type'] = array('test'=>'bar'); |
|
56
|
|
|
$_POST['aor_chart_x_field'] = array('test'=>'1'); |
|
57
|
|
|
$_POST['aor_chart_y_field'] = array('test'=>'2'); |
|
58
|
|
|
|
|
59
|
|
|
//populate aor_Report object values |
|
60
|
|
|
$aor_Report->name = "test"; |
|
61
|
|
|
$aor_Report->description = "test text"; |
|
62
|
|
|
|
|
63
|
|
|
$aor_Report->save(); |
|
64
|
|
|
|
|
65
|
|
|
//test for record ID to verify that record is saved |
|
66
|
|
|
$this->assertTrue(isset($aor_Report->id)); |
|
67
|
|
|
$this->assertEquals(36, strlen($aor_Report->id)); |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
//mark the record as deleted for cleanup |
|
71
|
|
|
$aor_Report->mark_deleted($aor_Report->id); |
|
72
|
|
|
|
|
73
|
|
|
unset($aor_Report); |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
public function testload_report_beans(){ |
|
79
|
|
|
|
|
80
|
|
|
$aor_Report = new AOR_Report(); |
|
81
|
|
|
|
|
82
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
83
|
|
|
try { |
|
84
|
|
|
$aor_Report->load_report_beans(); |
|
85
|
|
|
$this->assertTrue(true); |
|
86
|
|
|
} |
|
87
|
|
|
catch (Exception $e) { |
|
88
|
|
|
$this->fail(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
public function testgetReportFields(){ |
|
95
|
|
|
|
|
96
|
|
|
//execute the method and verify that it returns an array |
|
97
|
|
|
$aor_Report = new AOR_Report(); |
|
98
|
|
|
$result = $aor_Report->getReportFields(); |
|
99
|
|
|
$this->assertTrue(is_array($result)); |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
public function testbuild_report_chart(){ |
|
105
|
|
|
|
|
106
|
|
|
$aor_Report = new AOR_Report(); |
|
107
|
|
|
$aor_Report->report_module = "Accounts"; |
|
108
|
|
|
|
|
109
|
|
|
//execute the method and verify that it returns chart display script. strings returned vary due to included chart id. |
|
110
|
|
|
$expected = '<script src="modules/AOR_Charts/lib/pChart/imagemap.js"></script>'; |
|
111
|
|
|
$result = $aor_Report->build_report_chart(); |
|
112
|
|
|
$this->assertStringStartsWith($expected, $result); |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
public function testbuild_group_report(){ |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
$aor_Report = new AOR_Report(); |
|
121
|
|
|
$aor_Report->report_module = "Accounts"; |
|
122
|
|
|
$aor_Report->id = "1"; |
|
123
|
|
|
|
|
124
|
|
|
//execute the method without any parameters and verify it returns html string |
|
125
|
|
|
$html1 = $aor_Report->build_group_report(); |
|
126
|
|
|
$this->assertGreaterThan(0,strlen($html1)); |
|
127
|
|
|
|
|
128
|
|
|
//execute the method wit offset parameter and verify it returns html string |
|
129
|
|
|
$html2 = $aor_Report->build_group_report(1); |
|
130
|
|
|
$this->assertGreaterThan(0,strlen($html2)); |
|
131
|
|
|
|
|
132
|
|
|
//execute the method with both parameters and verify it returns html string |
|
133
|
|
|
$html3 = $aor_Report->build_group_report(0,false); |
|
134
|
|
|
$this->assertGreaterThan(0,strlen($html3)); |
|
135
|
|
|
|
|
136
|
|
|
//verify that all three html strings are different. |
|
137
|
|
|
$this->assertNotEquals($html1,$html2); |
|
138
|
|
|
$this->assertNotEquals($html1,$html3); |
|
139
|
|
|
$this->assertNotEquals($html2,$html3); |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
public function testbuild_report_html(){ |
|
146
|
|
|
|
|
147
|
|
|
$aor_Report = new AOR_Report(); |
|
148
|
|
|
$aor_Report->report_module = "Accounts"; |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
//execute the method without any parameters and verify it returns html string |
|
152
|
|
|
$html1 = $aor_Report->build_report_html(); |
|
153
|
|
|
$this->assertGreaterThan(0,strlen($html1)); |
|
154
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
//execute the method with both parameters and verify it returns html string |
|
157
|
|
|
$html2 = $aor_Report->build_report_html(0,false); |
|
158
|
|
|
$this->assertGreaterThan(0,strlen($html2)); |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
//execute the method with group and identifier parameters and verify it returns html string |
|
162
|
|
|
$html3 = $aor_Report->build_report_html(1,false,'grouptest','testidentifier'); |
|
163
|
|
|
$this->assertGreaterThan(0,strlen($html3)); |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
//verify that group and identifier exist in the strings |
|
167
|
|
|
$this->assertNotFalse(strpos($html3,'grouptest')); |
|
168
|
|
|
$this->assertNotFalse(strpos($html3,'testidentifier')); |
|
169
|
|
|
|
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function testgetTotalHTML(){ |
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
//execute the method with required data preset and verify it returns expected result |
|
176
|
|
|
$fields =Array('label'=>Array('display'=>1 , 'total'=> 'SUM','label'=>'total')); |
|
177
|
|
|
$totals = Array('label'=> array(10,20,30)); |
|
178
|
|
|
$expected = "<tbody><tr><th>total Sum</th></tr><tr><td>60</td></tr></tbody>"; |
|
179
|
|
|
|
|
180
|
|
|
$aor_Report = new AOR_Report(); |
|
181
|
|
|
$actual = $aor_Report->getTotalHTML($fields,$totals); |
|
182
|
|
|
|
|
183
|
|
|
$this->assertSame($expected, $actual); |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function testcalculateTotal(){ |
|
188
|
|
|
|
|
189
|
|
|
//execute the method with data preset and verify it returns expected result |
|
190
|
|
|
$totals = Array(10,20,30); |
|
191
|
|
|
|
|
192
|
|
|
$aor_Report = new AOR_Report(); |
|
193
|
|
|
|
|
194
|
|
|
$this->assertEquals('', $aor_Report->calculateTotal('', $totals)); |
|
195
|
|
|
$this->assertEquals(60, $aor_Report->calculateTotal('SUM', $totals)); |
|
196
|
|
|
$this->assertEquals(3, $aor_Report->calculateTotal('COUNT', $totals)); |
|
197
|
|
|
$this->assertEquals(20 , $aor_Report->calculateTotal('AVG', $totals)); |
|
198
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
public function testbuild_report_csv(){ |
|
203
|
|
|
|
|
204
|
|
|
//this method uses exit so it cannot be tested |
|
205
|
|
|
|
|
206
|
|
|
/*$aor_Report = new AOR_Report(); |
|
207
|
|
|
$aor_Report->report_module = "Accounts"; |
|
208
|
|
|
$aor_Report->build_report_csv(); |
|
209
|
|
|
*/ |
|
210
|
|
|
|
|
211
|
|
|
$this->markTestIncomplete('Can Not be implemented'); |
|
212
|
|
|
|
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
public function testbuild_report_query(){ |
|
218
|
|
|
|
|
219
|
|
|
$aor_Report = new AOR_Report(); |
|
220
|
|
|
$aor_Report->report_module = "Accounts"; |
|
221
|
|
|
|
|
222
|
|
|
//execute the method without any parameters and verify that it returns a non empty string |
|
223
|
|
|
$actual = $aor_Report->build_report_query(); |
|
224
|
|
|
$this->assertGreaterThan(0, strlen($actual)); |
|
225
|
|
|
|
|
226
|
|
|
//execute the method with parameter and verify that it returns a non empty string |
|
227
|
|
|
$actual = $aor_Report->build_report_query('name'); |
|
228
|
|
|
$this->assertGreaterThan(0, strlen($actual)); |
|
229
|
|
|
|
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
public function testbuild_report_query_select(){ |
|
233
|
|
|
|
|
234
|
|
|
$aor_Report = new AOR_Report(); |
|
235
|
|
|
$aor_Report->report_module = "Accounts"; |
|
236
|
|
|
$query_array = array(); |
|
237
|
|
|
|
|
238
|
|
|
//execute the method with parameters and verify that it returns an array. |
|
239
|
|
|
$actual = $aor_Report->build_report_query_select($query_array, 'name'); |
|
240
|
|
|
$this->assertTrue(is_array($actual)); |
|
241
|
|
|
|
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
public function testbuild_report_query_join( ){ |
|
246
|
|
|
|
|
247
|
|
|
$aor_Report = new AOR_Report(); |
|
248
|
|
|
$aor_Report->report_module = "Accounts"; |
|
249
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
//test with type custom and verify that it retunrs expected results |
|
252
|
|
|
$expected = array ('join' => array ('accounts_contacts' => 'LEFT JOIN `accounts_cstm` `contacts` ON `accounts`.id = `contacts`.id_c ')); |
|
253
|
|
|
$actual = $aor_Report->build_report_query_join('contacts', 'accounts_contacts', 'accounts', new Account() , 'custom', array() ); |
|
254
|
|
|
$this->assertSame($expected ,$actual); |
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
//test with type relationship and verify that it retunrs expected results |
|
258
|
|
|
$expected = array ('join' =>array ('accounts_contacts' => "LEFT JOIN accounts_contacts `accounts|accounts_contacts` ON `accounts`.id=`accounts|accounts_contacts`.account_id AND `accounts|accounts_contacts`.deleted=0\n\nLEFT JOIN contacts `accounts_contacts` ON `accounts_contacts`.id=`accounts|accounts_contacts`.contact_id AND `accounts_contacts`.deleted=0\n"), |
|
259
|
|
|
'select' =>array ('`accounts_contacts`.id AS \'accounts_contacts_id\'')); |
|
260
|
|
|
$actual = $aor_Report->build_report_query_join('contacts', 'accounts_contacts', 'accounts', new Account() , 'relationship', array() ); |
|
261
|
|
|
$this->assertSame($expected , $actual); |
|
262
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function testbuild_report_access_query(){ |
|
266
|
|
|
|
|
267
|
|
|
$aor_Report = new AOR_Report(); |
|
268
|
|
|
|
|
269
|
|
|
//test without alias and verify that it retunrs expected results |
|
270
|
|
|
$result = $aor_Report->build_report_access_query(new AOR_Report(), ''); |
|
271
|
|
|
$this->assertEquals("",$result); |
|
272
|
|
|
|
|
273
|
|
|
//test with alias and verify that it retunrs expected results |
|
274
|
|
|
$result = $aor_Report->build_report_access_query(new AOR_Report(), 'rep'); |
|
275
|
|
|
$this->assertEquals("",$result); |
|
276
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
public function testbuild_report_query_where(){ |
|
281
|
|
|
|
|
282
|
|
|
$aor_Report = new AOR_Report(); |
|
283
|
|
|
$aor_Report->report_module = "Accounts"; |
|
284
|
|
|
|
|
285
|
|
|
//execute the method and verify that it retunrs expected results |
|
286
|
|
|
$expected = Array ('where' => array ('accounts.deleted = 0 ')); |
|
287
|
|
|
$actual = $aor_Report->build_report_query_where(); |
|
288
|
|
|
$this->assertSame($expected , $actual); |
|
289
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
} |
|
293
|
|
|
|