|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once 'modules/AOR_Charts/lib/pChart/pChart.php'; |
|
4
|
|
|
class AOR_ChartTest extends PHPUnit_Framework_TestCase { |
|
5
|
|
|
|
|
6
|
|
|
public function testAOR_Chart(){ |
|
7
|
|
|
|
|
8
|
|
|
//execute the contructor and check for the Object type and attributes |
|
9
|
|
|
$aorChart = new AOR_Chart(); |
|
10
|
|
|
$this->assertInstanceOf('AOR_Chart',$aorChart); |
|
11
|
|
|
$this->assertInstanceOf('Basic',$aorChart); |
|
12
|
|
|
$this->assertInstanceOf('SugarBean',$aorChart); |
|
13
|
|
|
|
|
14
|
|
|
$this->assertAttributeEquals('AOR_Charts', 'module_dir', $aorChart); |
|
15
|
|
|
$this->assertAttributeEquals('AOR_Chart', 'object_name', $aorChart); |
|
16
|
|
|
$this->assertAttributeEquals('aor_charts', 'table_name', $aorChart); |
|
17
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $aorChart); |
|
18
|
|
|
$this->assertAttributeEquals(true, 'disable_row_level_security', $aorChart); |
|
19
|
|
|
$this->assertAttributeEquals(true, 'importable', $aorChart); |
|
20
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testsave_lines(){ |
|
24
|
|
|
|
|
25
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
26
|
|
|
|
|
27
|
|
|
$aorChart = new AOR_Chart(); |
|
28
|
|
|
|
|
29
|
|
|
//preset the required data |
|
30
|
|
|
$post = array(); |
|
31
|
|
|
$post['chartid'] = array('test'=>''); |
|
32
|
|
|
$post['charttitle'] = array('test'=>'test'); |
|
33
|
|
|
$post['charttype'] = array('test'=>'bar'); |
|
34
|
|
|
$post['chartx_field'] = array('test'=>'1'); |
|
35
|
|
|
$post['charty_field'] = array('test'=>'2'); |
|
36
|
|
|
|
|
37
|
|
|
$postKey = "chart"; |
|
38
|
|
|
|
|
39
|
|
|
$bean = new AOR_Report(); |
|
40
|
|
|
|
|
41
|
|
|
//execute the method and test if it works and does not throws an exception. |
|
42
|
|
|
try { |
|
43
|
|
|
$result = $aorChart->save_lines($post, $bean, $postKey); |
|
44
|
|
|
$this->assertTrue(true); |
|
45
|
|
|
} |
|
46
|
|
|
catch (Exception $e) { |
|
47
|
|
|
$this->fail(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function testbuildChartImageBar(){ |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$aorChart = new AOR_Chart(); |
|
58
|
|
|
|
|
59
|
|
|
$chartData = new pData(); |
|
60
|
|
|
$chartData->addPoints(10,'data'); |
|
61
|
|
|
$chartData->addPoints(10,'Labels'); |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
//execute with recordImageMap true and verify that the chartPicture is changed |
|
65
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
66
|
|
|
$aorChart->buildChartImageBar($chartPicture,true); |
|
67
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
//execute with recordImageMap false and verify that the chartPicture is changed |
|
71
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
72
|
|
|
$aorChart->buildChartImageBar($chartPicture,false); |
|
73
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
74
|
|
|
|
|
75
|
|
|
unset($chartData); |
|
76
|
|
|
unset($chartPicture); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testbuildChartImagePie(){ |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$aorChart = new AOR_Chart(); |
|
83
|
|
|
|
|
84
|
|
|
$chartData = new pData(); |
|
85
|
|
|
$chartData->addPoints(10,'data'); |
|
86
|
|
|
$chartData->addPoints(10,'Labels'); |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
//execute with recordImageMap false and verify that the chartPicture is changed |
|
90
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
91
|
|
|
$aorChart->buildChartImagePie($chartPicture,$chartData,array(array('x'=>10), array('x'=>20)),700, 700, 'x',false); |
|
92
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
//execute with recordImageMap true and verify that the chartPicture is changed |
|
96
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
97
|
|
|
$aorChart->buildChartImagePie($chartPicture,$chartData,array(array('x'=>10), array('x'=>20)),700, 700, 'x',true); |
|
98
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
99
|
|
|
|
|
100
|
|
|
unset($chartData); |
|
101
|
|
|
unset($chartPicture); |
|
102
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testbuildChartImageLine(){ |
|
106
|
|
|
|
|
107
|
|
|
$aorChart = new AOR_Chart(); |
|
108
|
|
|
|
|
109
|
|
|
$chartData = new pData(); |
|
110
|
|
|
$chartData->addPoints(10,'data'); |
|
111
|
|
|
$chartData->addPoints(10,'Labels'); |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
//execute with recordImageMap true and verify that the chartPicture is changed |
|
115
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
116
|
|
|
$aorChart->buildChartImageLine($chartPicture,true); |
|
117
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
118
|
|
|
|
|
119
|
|
|
//execute with recordImageMap false and verify that the chartPicture is changed |
|
120
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
121
|
|
|
$aorChart->buildChartImageLine($chartPicture,false); |
|
122
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
unset($chartData); |
|
126
|
|
|
unset($chartPicture); |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testbuildChartImageRadar(){ |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
$aorChart = new AOR_Chart(); |
|
134
|
|
|
|
|
135
|
|
|
//preset the required objects and properties |
|
136
|
|
|
$chartData = new pData(); |
|
137
|
|
|
$chartData->loadPalette("modules/AOR_Charts/lib/pChart/palettes/navy.color", TRUE); |
|
138
|
|
|
$chartData->addPoints(10,'data'); |
|
139
|
|
|
$chartData->addPoints('10','Labels'); |
|
140
|
|
|
$chartData->addPoints(120,'data'); |
|
141
|
|
|
$chartData->addPoints('120','Labels'); |
|
142
|
|
|
|
|
143
|
|
|
$chartData->setSerieDescription("Months","Month"); |
|
144
|
|
|
$chartData->setAbscissa("Labels"); |
|
145
|
|
|
|
|
146
|
|
|
$imageWidth = 700; |
|
147
|
|
|
$imageHeight = 700; |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
//execute with recordImageMap true and verify that the chartPicture is changed |
|
151
|
|
|
$chartPicture = new pImage($imageWidth,$imageHeight,$chartData); |
|
152
|
|
|
$chartPicture->setGraphArea(60,60,$imageWidth-60,$imageHeight-100); |
|
153
|
|
|
$aorChart->buildChartImageRadar($chartPicture,$chartData,true); |
|
154
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
//execute with recordImageMap false and verify that the chartPicture is changed |
|
159
|
|
|
$chartPicture = new pImage(700,700,$chartData); |
|
160
|
|
|
$chartPicture->setGraphArea(60,60,$imageWidth-60,$imageHeight-100); |
|
161
|
|
|
$aorChart->buildChartImageRadar($chartPicture,$chartData,false); |
|
162
|
|
|
$this->assertNotEquals($chartPicture, new pImage(700,700,$chartData) ); |
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
unset($chartData); |
|
166
|
|
|
unset($chartPicture); |
|
167
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function testbuildChartImage(){ |
|
171
|
|
|
|
|
172
|
|
|
$this->markTestSkipped("Skipping testing chart image"); |
|
173
|
|
|
|
|
174
|
|
|
global $current_user; |
|
175
|
|
|
|
|
176
|
|
|
$current_user->id = "1"; |
|
177
|
|
|
|
|
178
|
|
|
$aorChart = new AOR_Chart(); |
|
179
|
|
|
|
|
180
|
|
|
//preset the required objects and properties |
|
181
|
|
|
|
|
182
|
|
|
$aorChart->x_field = 'x'; |
|
183
|
|
|
$aorChart->y_field = 'y'; |
|
184
|
|
|
|
|
185
|
|
|
$fields = Array(); |
|
186
|
|
|
$fields['x'] = json_decode('{"label": "x"}'); |
|
187
|
|
|
$fields['y'] = json_decode('{"label": "y"}'); |
|
188
|
|
|
|
|
189
|
|
|
$reportData = array(array('xx'=>10,'yy'=>10), array('xx'=>20, 'yy'=>20)); |
|
190
|
|
|
|
|
191
|
|
|
//execute the method and verify it returns expected results |
|
192
|
|
|
$aorChart->type = 'bar'; |
|
193
|
|
|
$result = $aorChart->buildChartImage($reportData, $fields); |
|
194
|
|
|
$this->assertEquals('data:image/png;base64,',$result); |
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
//execute the method and verify it returns expected results |
|
198
|
|
|
$aorChart->type = 'Line'; |
|
199
|
|
|
$result = $aorChart->buildChartImage($reportData, $fields); |
|
200
|
|
|
$this->assertEquals('',$result); |
|
201
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
//execute the method and verify it returns expected results |
|
204
|
|
|
$aorChart->type = 'pie'; |
|
205
|
|
|
$result = $aorChart->buildChartImage($reportData, $fields); |
|
206
|
|
|
$this->assertEquals('data:image/png;base64,',$result); |
|
207
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
//execute the method and verify it returns expected results |
|
210
|
|
|
$aorChart->type = 'radar'; |
|
211
|
|
|
$result = $aorChart->buildChartImage($reportData, $fields,true); |
|
212
|
|
|
$this->assertEquals('data:image/png;base64,',$result); |
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function testbuildChartHTML(){ |
|
218
|
|
|
$this->markTestSkipped("Skipping testing chart HTML"); |
|
219
|
|
|
$aorChart = new AOR_Chart(); |
|
220
|
|
|
|
|
221
|
|
|
//preset the required objects and properties |
|
222
|
|
|
$aorChart->x_field = 'x'; |
|
223
|
|
|
$aorChart->y_field = 'y'; |
|
224
|
|
|
|
|
225
|
|
|
$fields = Array(); |
|
226
|
|
|
$fields['x'] = json_decode('{"label": "x"}'); |
|
227
|
|
|
$fields['y'] = json_decode('{"label": "y"}'); |
|
228
|
|
|
|
|
229
|
|
|
$reportData = array(array('xx'=>10,'yy'=>10), array('xx'=>20, 'yy'=>20)); |
|
230
|
|
|
|
|
231
|
|
|
$aorChart->type = 'bar'; |
|
232
|
|
|
|
|
233
|
|
|
//test with type CHART_TYPE_PCHART and verify it returns expected results |
|
234
|
|
|
$expected = "<img id='_img' src='data:image/png;base64,'><script>\nSUGAR.util.doWhen(\"typeof addImage != 'undefined'\", function(){\n addImage('_img','_img_map','index.php?module=AOR_Charts&action=getImageMap&to_pdf=1&imageMapId=0');\n});\n</script>"; |
|
235
|
|
|
$result = $aorChart->buildChartHTML($reportData, $fields); |
|
236
|
|
|
$this->assertSame($expected, $result); |
|
237
|
|
|
|
|
238
|
|
|
//test with type CHART_TYPE_CHARTJS verify it returns expected results |
|
239
|
|
|
$expected = "<h3></h3><canvas id='chart' width='400' height='400'></canvas> <script>\n \$(document).ready(function(){\n SUGAR.util.doWhen(\"typeof Chart != 'undefined'\", function(){\n var data = {\"labels\":[\"10 [a]\",\"20 [e]\"],\"datasets\":[{\"fillColor\":\"rgba(151,187,205,0.2)\",\"strokeColor\":\"rgba(151,187,205,1)\",\"pointColor\":\"rgba(151,187,205,1)\",\"pointStrokeColor\":\"#fff\",\"pointHighlightFill\":\"#fff\",\"pointHighlightStroke\":\"rgba(151,187,205,1)4\",\"data\":[10,20]}]};\n var ctx = document.getElementById(\"chart\").getContext(\"2d\");\n console.log('Creating new chart');\n var config = [];\n var chart = new Chart(ctx).Bar(data, config);\n var legend = chart.generateLegend();\n $('#chart').after(legend);\n });\n });\n </script>" ; |
|
240
|
|
|
$result = $aorChart->buildChartHTML($reportData, $fields,0, AOR_Report::CHART_TYPE_CHARTJS); |
|
241
|
|
|
$this->assertSame($expected, $result); |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
} |
|
249
|
|
|
|