test.php
3.8 KB
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
<?php
$GLOBALS['kt_test'] = true;
require_once(dirname(__FILE__) . '/../config/dmsDefaults.php');
require_once('simpletest/autorun.php');
//require_once('simpletest/unit_tester.php');
//require_once('simpletest/mock_objects.php');
//require_once('simpletest/reporter.php');
class KTUnitTestCase extends UnitTestCase {
function assertExpectedResults($aExpected, $aReceived) {
if ($aReceived == $aExpected) {
$this->pass('Expected results received');
return;
}
$iLen = count($aExpected);
for ($c = 0; $c < $iLen; $c++) {
if ($aReceived[$c] != $aExpected[$c]) {
$this->fail(sprintf("Failure. Expected %s, but got %s\n", $aExpected[$c], $aReceived[$c]));
}
}
}
function assertEntity($oEntity, $sClass) {
if (is_a($oEntity, $sClass)) {
return $this->pass(sprintf('Object is a %s', $sClass));
}
return $this->fail(sprintf('Object is not a %s', $sClass));
}
function assertNotError($oObject) {
if(PEAR::isError($oObject)) {
return $this->fail(sprintf('Object is a PEAR Error: '.$oObject->getMessage() ));
}
return $this->pass(sprintf('Object is not a PEAR Error'));
}
function assertError($oObject) {
if(PEAR::isError($oObject)) {
return $this->pass(sprintf('Object is a PEAR Error: '.$oObject->getMessage() ));
}
return $this->fail(sprintf('Object is not a PEAR Error'));
}
function assertGroup($oGroup) {
return $this->assertEntity($oGroup, 'Group');
}
}
/**
* Extends the HTML reporter to display more information
*
*/
class KTHtmlReporter extends HtmlReporter {
/**
* Display the passed tests
*
* @param string $message Display a custom message for the test
*/
function paintPass($message) {
parent::paintPass($message);
print "<span class=\"pass\">Pass</span>: ";
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
print implode("->", $breadcrumb);
print "->$message<br />\n";
}
/**
* Display the start of each method
*
* @param string $test_name
*/
function paintMethodStart($test_name) {
parent::paintMethodStart($test_name);
print "<br /><span class=\"method\"><b>Method start:</b> $test_name</span><br />";
}
/**
* Display the start of each test case
*
* @param string $test_case
* @param int $size
*/
function paintGroupStart($test_case, $size) {
parent::paintGroupStart($test_case, $size);
print "<br /><div class=\"group\"><b>Test Case:</b> $test_case</div>";
}
/**
* Paints the CSS. Add additional styles here.
* @return string CSS code as text.
* @access protected
*/
function _getCss() {
return ".fail { background-color: inherit; color: red; }" .
".pass { background-color: inherit; color: green; }" .
" pre { background-color: lightgray; color: inherit; }" .
".group { background-color: lightblue; padding: 4px; }" .
".method { background-color: inherit; }";
}
}
/**
* Extends the text (CLI) reporter to display more information
*
*/
class KTTextReporter extends TextReporter {
/**
* Display the start of each test case
*
* @param string $test_case
* @param int $size
*/
function paintGroupStart($test_case, $size) {
parent::paintGroupStart($test_case, $size);
print "\nTest Case: $test_case\n";
}
/**
* Display the start of each method
*
* @param string $test_name
*/
function paintMethodStart($test_name) {
parent::paintMethodStart($test_name);
print "Method: $test_name\n";
}
}