-
Notifications
You must be signed in to change notification settings - Fork 0
/
TR_repConcatstats.php
316 lines (286 loc) · 16.6 KB
/
TR_repConcatstats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
class TR_repConcatstats extends TR_Template{
function getSupportedChartsArr() {
return $this->supportedCharts;
}
function getSupportedChartTypesArr() {
return $this->supportedChartTypes;
}
/**
* implementation of the abstract function of the super class
*/
function getReport( $result ) {
# check and set some parameters
# field for calculating the total number; could be set to a field that is included in the field list of the select statement or to rowcount, which will simply count number of rows
if ($this->getArgs()->get("total") == "true") {
$this->getArgs()->set("total", "rowcount");
}
$output = $this->renderPlainHTML( $result );
#returning the output
return $output;
}
function getReportName() {
return "Testing Summary Report";
}
/**
* Create the report header
**/
function getReportHeader() {
return $this->getStandardRunHeader();
}
function getReportFooter() {
#return "<b>Number of test cases in this run: ".$this->getTotal()."</b>";
return "";
}
function getSQL() {
$result = "";
$test_case_run_status = $this->getConnector()->getTable("test_case_run_status");
$products = $this->getConnector()->getTable("products");
$run_ids = explode(", ", $this->getRunID());
$run_counter = 0;
foreach ($run_ids as $run_id) {
$sql = new TR_SQL;
$sql->setConnector($this->getConnector());
$sql->setFrom("test_plans");
$sql->addField("test_plans", "product_id");
$sql->addField("test_case_runs", "run_id", "run_id", "IFNULL($1,$run_id)");
$sql->addField("test_plans", "name", "Test_Plan");
$sql->addField("test_environments", "name", "Environment");
$sql->addField("test_case_runs", "case_id", "status", "IFNULL(COUNT(DISTINCT $1),0)");
$sql->addField("test_case_bugs", "bug_id", "bugs", "IFNULL(GROUP_CONCAT(DISTINCT $1),\"none\")");
$sql->addJoin("Inner", "=", "test_runs", "plan_id", "test_plans", "plan_id");
$sql->addJoin("Inner", "=", "test_environments", "environment_id", "test_runs", "environment_id");
$sql->addJoin("Inner", "=", "test_case_runs", "run_id", "test_runs", "run_id");
$sql->addJoin("Left", "=", "test_case_bugs", "case_run_id", "test_case_runs", "case_run_id");
$sql->addJoin("Inner", "=", "test_case_run_status", "case_run_status_id", "test_case_runs", "case_run_status_id");
$sql->addWhere("test_case_runs", "run_id", "=", $run_id);
$sql->addWhere("test_case_runs", "iscurrent", "=", "1", "AND");
$sql->addWhere("test_case_run_status", "case_run_status_id", "=", "2", "AND");
$sqlPASSED = "select * from (".$sql->toSQL().") as temp_table GROUP BY temp_table.run_id";
#EDITED: The GROUP BY is done outside the first query because, unknown why, the result was an empty table despite the IFNULL statements.
#This resulted in an empty final result if any test run had blocked, passed or failed columns with a value of "0".
$sql = new TR_SQL;
$sql->setConnector($this->getConnector());
$sql->setFrom("test_plans");
$sql->addField("test_plans", "product_id");
$sql->addField("test_case_runs", "run_id", "run_id", "IFNULL($1,$run_id)");
$sql->addField("test_plans", "name", "Test_Plan");
$sql->addField("test_environments", "name", "Environment");
$sql->addField("test_case_runs", "case_id", "status", "IFNULL(COUNT(DISTINCT $1),0)");
$sql->addField("test_case_bugs", "bug_id", "bugs", "IFNULL(GROUP_CONCAT(DISTINCT $1),\"none\")");
$sql->addJoin("Inner", "=", "test_runs", "plan_id", "test_plans", "plan_id");
$sql->addJoin("Inner", "=", "test_environments", "environment_id", "test_runs", "environment_id");
$sql->addJoin("Inner", "=", "test_case_runs", "run_id", "test_runs", "run_id");
$sql->addJoin("Left", "=", "test_case_bugs", "case_run_id", "test_case_runs", "case_run_id");
$sql->addJoin("Inner", "=", "test_case_run_status", "case_run_status_id", "test_case_runs", "case_run_status_id");
$sql->addWhere("test_case_runs", "run_id", "=", $run_id);
$sql->addWhere("test_case_runs", "iscurrent", "=", "1", "AND");
$sql->addWhere("test_case_run_status", "case_run_status_id", "=", "3", "AND");
$sqlFAILED = "select * from (".$sql->toSQL().") as temp_table GROUP BY temp_table.run_id";
$sql = new TR_SQL;
$sql->setConnector($this->getConnector());
$sql->setFrom("test_plans");
$sql->addField("test_plans", "product_id");
$sql->addField("test_case_runs", "run_id", "run_id", "IFNULL($1,$run_id)");
$sql->addField("test_plans", "name", "Test_Plan");
$sql->addField("test_environments", "name", "Environment");
$sql->addField("test_case_runs", "case_id", "status", "IFNULL(COUNT(DISTINCT $1),0)");
$sql->addField("test_case_bugs", "bug_id", "bugs", "IFNULL(GROUP_CONCAT(DISTINCT $1),\"none\")");
$sql->addJoin("Inner", "=", "test_runs", "plan_id", "test_plans", "plan_id");
$sql->addJoin("Inner", "=", "test_environments", "environment_id", "test_runs", "environment_id");
$sql->addJoin("Inner", "=", "test_case_runs", "run_id", "test_runs", "run_id");
$sql->addJoin("Left", "=", "test_case_bugs", "case_run_id", "test_case_runs", "case_run_id");
$sql->addJoin("Inner", "=", "test_case_run_status", "case_run_status_id", "test_case_runs", "case_run_status_id");
$sql->addWhere("test_case_runs", "run_id", "=", $run_id);
$sql->addWhere("test_case_runs", "iscurrent", "=", "1", "AND");
$sql->addWhere("test_case_run_status", "case_run_status_id", "=", "6", "AND");
$sqlBLOCKED ="select * from (".$sql->toSQL().") as temp_table GROUP BY temp_table.run_id";
$sql = new TR_SQL;
$sql->setConnector($this->getConnector());
$sql->setFrom("test_plans");
$sql->addField("test_plans", "product_id");
$sql->addField("test_case_runs", "run_id", "run_id", "IFNULL($1,$run_id)");
$sql->addField("test_plans", "name", "Test_Plan");
$sql->addField("test_environments", "name", "Environment");
$sql->addField("test_case_runs", "case_id", "status", "IFNULL(COUNT(DISTINCT $1),0)");
$sql->addField("test_case_bugs", "bug_id", "bugs", "IFNULL(GROUP_CONCAT(DISTINCT $1),\"none\")");
$sql->addJoin("Inner", "=", "test_runs", "plan_id", "test_plans", "plan_id");
$sql->addJoin("Inner", "=", "test_environments", "environment_id", "test_runs", "environment_id");
$sql->addJoin("Inner", "=", "test_case_runs", "run_id", "test_runs", "run_id");
$sql->addJoin("Left", "=", "test_case_bugs", "case_run_id", "test_case_runs", "case_run_id");
$sql->addJoin("Inner", "=", "test_case_run_status", "case_run_status_id", "test_case_runs", "case_run_status_id");
$sql->addWhere("test_case_runs", "run_id", "=", $run_id);
$sql->addWhere("test_case_runs", "iscurrent", "=", "1", "AND");
$sql->addWhere("test_case_run_status", "case_run_status_id", "=", "1", "AND");
$sqlIDLE ="select * from (".$sql->toSQL().") as temp_table GROUP BY temp_table.run_id";
#EDITED: The below section also treats a "NULL" Test Plan and Environment scenario. This was present in a previous implementation of this report but now it always returns the correct test plan and environment names.
if ($run_counter == 0) {
$result = "SELECT IFNULL(table1.product_id,IFNULL(table2.product_id,IFNULL(table3.product_id,\"NOT READY: $run_id\"))) as product_id,
IFNULL(table1.run_id,IFNULL(table2.run_id,IFNULL(table3.run_id,\"NOT READY\"))) as run_id,
IFNULL(table1.Test_Plan,IFNULL(table2.Test_Plan,IFNULL(table3.Test_Plan,\"NOT READY\"))) AS \"Test_Plan\",
IFNULL(table1.Environment,IFNULL(table2.Environment,IFNULL(table3.Environment,\"NOT READY\"))) AS \"Environment\",
table1.status AS Passed, table1.bugs as \"Other_issues\",
table2.status AS Failed, table2.bugs as \"Failing_bugs\",
table3.status AS Blocked, table3.bugs as \"Blocking_bugs\",
table4.status AS Idle
FROM ($sqlPASSED) AS table1 INNER JOIN ($sqlFAILED) as table2 ON table1.run_id=table2.run_id INNER JOIN ($sqlBLOCKED) as table3 ON table1.run_id=table3.run_id
INNER JOIN ($sqlIDLE) as table4 ON table1.run_id=table4.run_id";
$run_counter++;
}
else {
$result .= " UNION ALL SELECT IFNULL(table1.product_id,IFNULL(table2.product_id,IFNULL(table3.product_id,\"NOT READY: $run_id\"))) as product_id,
IFNULL(table1.run_id,IFNULL(table2.run_id,IFNULL(table3.run_id,\"NOT READY\"))) as run_id,
IFNULL(table1.Test_Plan,IFNULL(table2.Test_Plan,IFNULL(table3.Test_Plan,\"NOT READY\"))) AS \"Test_Plan\",
IFNULL(table1.Environment,IFNULL(table2.Environment,IFNULL(table3.Environment,\"NOT READY\"))) AS \"Environment\",
table1.status AS Passed, table1.bugs as \"Other_issues\",
table2.status AS Failed, table2.bugs as \"Failing_bugs\",
table3.status AS Blocked, table3.bugs as \"Blocking_bugs\",
table4.status AS Idle
FROM ($sqlPASSED) AS table1 INNER JOIN ($sqlFAILED) as table2 ON table1.run_id=table2.run_id INNER JOIN ($sqlBLOCKED) as table3 ON table1.run_id=table3.run_id
INNER JOIN ($sqlIDLE) as table4 ON table1.run_id=table4.run_id";
}
}
return "SELECT GROUP_CONCAT(temp_table.run_id) as \"Test Run\", temp_table.Test_Plan as \"Test Plan\", temp_table.Environment,
IFNULL(FORMAT(AVG(temp_table.Passed*100)/(AVG(temp_table.Passed)+AVG(temp_table.Failed)+AVG(temp_table.Blocked)+AVG(temp_table.Idle)),1),0) AS Passed, GROUP_CONCAT(temp_table.Other_issues) as \"Other issues\",
IFNULL(FORMAT(AVG(temp_table.Failed*100)/(AVG(temp_table.Passed)+AVG(temp_table.Failed)+AVG(temp_table.Blocked)+AVG(temp_table.Idle)),1),0) AS Failed, GROUP_CONCAT(temp_table.Failing_bugs) as \"Failing bugs\",
IFNULL(FORMAT(AVG(temp_table.Blocked*100)/(AVG(temp_table.Passed)+AVG(temp_table.Failed)+AVG(temp_table.Blocked)+AVG(temp_table.Idle)),1),0) AS Blocked, GROUP_CONCAT(temp_table.Blocking_bugs) as \"Blocking bugs\",
IFNULL(FORMAT(100-AVG(temp_table.Idle*100)/(AVG(temp_table.Passed)+AVG(temp_table.Failed)+AVG(temp_table.Blocked)+AVG(temp_table.Idle)),1),0) AS Complete
FROM ($result) as temp_table INNER JOIN $products ON $products.id=temp_table.product_id GROUP BY temp_table.Test_Plan, temp_table.Environment
ORDER BY ($products.classification_id+0) ASC, (temp_table.product_id+0) DESC, temp_table.Environment";
}
function renderCell($type, $colNo, $field_name, $value, $lineNo, $line) {
$output = "";
if ($type=="body") {
switch ($field_name) {
case "Test Run":
$output = "<td align=\"left\">";
if ($value != "none") {
foreach (explode(",",$value) as $each_run) {
$output.="<a href=\"".$this->getArgs()->get("bzserver")."/tr_show_run.cgi?run_id=".$each_run."\">".$each_run."</a> ";
}
} else {
$output .= $value;
}
$output.= "</td>";
break;
case "Other issues":
$output = "<td>";
$here = 0;
foreach (array_unique(explode(",",$value)) as $each_bug) {
if ($each_bug != "none"){
$output.="<a href=\"".$this->getArgs()->get("bzserver")."/show_bug.cgi?id=".$each_bug."\">".$each_bug."</a> ";
$here = 1;
}
} if ($here == 0) { $output .= "none"; }
$output.= "</td>";
break;
case "Failing bugs":
$output = "<td>";
$here = 0;
foreach (array_unique(explode(",",$value)) as $each_bug) {
if ($each_bug != "none"){
$output.="<a href=\"".$this->getArgs()->get("bzserver")."/show_bug.cgi?id=".$each_bug."\">".$each_bug."</a> ";
$here = 1;
}
} if ($here == 0) { $output .= "none"; }
$output.= "</td>";
break;
case "Blocking bugs":
$output.= "<td>";
$here = 0;
foreach (array_unique(explode(",",$value)) as $each_bug) {
if ($each_bug != "none"){
$output.="<a href=\"".$this->getArgs()->get("bzserver")."/show_bug.cgi?id=".$each_bug."\">".$each_bug."</a> ";
$here = 1;
}
} if ($here == 0) { $output .= "none"; }
$output.= "</td>";
break;
case "Complete":
$class = "";
if ($value > "99.9") {
$class = "testopia_TestCase"."PASSED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} else {
$output = "<td style=\"text-align:center\">".$value."%</td>";
}
break;
case "Passed":
$class = "";
if ($value > "90.0") {
$class = "testopia_TestCase"."PASSED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} elseif ($value > "40.0") {
$class = "testopia_TestCase"."PAUSED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} else {
$class = "testopia_TestCase"."FAILED";
$output = "<td class=\"".$class."\">".$value."%</td>";
}
break;
case "Failed":
$class = "";
if ($value > "70.0") {
$class = "testopia_TestCase"."FAILED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} elseif ($value > "30.0") {
$class = "testopia_TestCase"."PAUSED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} else
$output = "<td style=\"text-align:center\">".$value."%</td>";
break;
case "Blocked":
$class = "";
if ($value > "70.0") {
$class = "testopia_TestCase"."FAILED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} elseif ($value > "30.0") {
$class = "testopia_TestCase"."PAUSED";
$output = "<td class=\"".$class."\">".$value."%</td>";
} else
$output = "<td style=\"text-align:center\">".$value."%</td>";
break;
}
}
return $output;
}
function getGoogleChartLink( &$google, $result, $type, $chart ) {
$color = new TR_Colors;
$label="";
$data="";
$href="";
$total=0;
if (!$this->getTotal()) {
$this->calcTotal( $result );
$total=$this->getTotal();
} else {
$total = $this->getTotal();
}
$google->setDataMinRange(0);
foreach ($result as $line) {
$plotData = "";
$i=0;
foreach ($line as $col_value) {
#labels and colors
if ($i==0) {
$label=$col_value;
$google->addColor($color->getColorHTML($col_value, "tcrs"));
}
#data
if ($i==1) {
$label.="(".$col_value.")";
if ($total) {
$label.= "+".round($col_value/$total*100)."%";
}
$google->addLabel($label);
$google->addLegend($label);
$google->addData($col_value);
}
$i++;
}
}
if ($type == "bar") { $google->hideLabels( true ); }
if ($type == "pie" or $type == "pie3") { $google->hideLegend( true ); }
}
}
?>