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 |
<?php
class MY_Unit_test extends CI_Unit_test{
function summary_report($result = array(),$list = false){
if (count($result) == 0)
{
$result = $this->result();
}
$CI =& get_instance();
$num_passed = 0;
foreach ($result as $res){
if($res['Result'] == $CI->lang->line('ut_passed'))
$num_passed++;
}
$q = '<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">
<tr>
<th style="text-align: left; border-bottom:1px solid #CCC;">Total number of tests</th>
<td style="border-bottom:1px solid #CCC;">' . count($result) . '</td>
</tr>
<tr>
<th style="text-align: left; border-bottom:1px solid #CCC;">Number of passed tests</th>
<td style="border-bottom:1px solid #CCC;">' . $num_passed . '</td>
</tr>
<tr>
<th style="text-align: left; border-bottom:1px solid #CCC;">Whole test suite passed</th>
<td style="border-bottom:1px solid #CCC;">'. ($num_passed == count($result) ? '<span style="color: #0C0;">YES</span>' : '<span style="color: #C00;">NO</span>') . '</td>
</tr>
<tr>
<th style="text-align: left; border-bottom:1px solid #CCC;">Tests:</th>
<td style="border-bottom:1px solid #CCC;"></td>
</tr>';
$CI->load->language('unit_test');
$this->_parse_template();
$r = '';
foreach ($result as $res)
{
$table = '';
foreach ($res as $key => $val)
{
if ($key == $CI->lang->line('ut_result'))
{
if ($val == $CI->lang->line('ut_passed'))
{
$val = '<span style="color: #0C0;">'.$val.'</span>';
}
elseif ($val == $CI->lang->line('ut_failed'))
{
$val = '<span style="color: #C00;">'.$val.'</span>';
}
}
$temp = $this->_template_rows;
$temp = str_replace('{item}', $key, $temp);
$temp = str_replace('{result}', $val, $temp);
$table .= $temp;
}
$r .= str_replace('{rows}', $table, $this->_template);
}
return $q.$r.'</table>';
}
function _default_template()
{
$this->_template = "\n".'<tr><th style="text-align: left; border-bottom:1px solid #CCC;"></th><td style="border-bottom:1px solid #CCC;"></td></tr>';
$this->_template .= '{rows}';
$this->_template .= '';
$this->_template_rows = "\n\t".'<tr>';
$this->_template_rows .= "\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>';
$this->_template_rows .= "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>';
$this->_template_rows .= '</tr>';
}
} |