2 // require gacl & phpunit
3 require_once(dirname(__FILE__
).'/../admin/gacl_admin.inc.php');
4 require_once(dirname(__FILE__
).'/phpunit/phpunit.php');
7 custom test result class for pretty results
9 class gacl_test_result
extends TestResult
{
16 echo '<h2>Test Results</h2>' . "\n";
17 echo '<table cellspacing="1" cellpadding="1" border="1" class="details">'."\n";
18 echo '<tr><th>Function</th><th width="10%">Success?</th></tr>'."\n";
23 $nRun = $this->countTests();
24 $nFailures = $this->countFailures();
25 echo '<h2>Summary</h2>'."\n";
26 printf('<div class="indent"><p>%s test%s run<br />', $nRun, ($nRun == 1) ?
'' : 's');
27 printf("%s failure%s.</p></div>\n", $nFailures, ($nFailures == 1) ?
'' : 's');
30 function _startTest($test) {
33 function _endTest($test) {
34 if ( $test->classname() != $this->class_name
) {
35 $this->class_name
= $test->classname();
36 $this->output
.= '<tr><td colspan="2" class="class_name">'. $test->classname() .'</td></tr>'."\n";
39 $this->output
.= '<tr><td class="function">'. $test->name();
40 if ($test->failed()) {
41 $this->output
.= "<ul>\n";
42 foreach ($test->getExceptions() as $exception) {
43 $this->output
.= '<li>'. $exception->getMessage() ."</li>\n";
45 $this->output
.= "</ul>\n";
47 $outcome = ' class="fail">FAIL';
49 $outcome = ' class="pass">OK';
52 $this->output
.= '</td><td'. $outcome .'</td></tr>'."\n";
57 custom TestCase class to allow control of error formatting
59 can also be used for custom assert functions
61 class gacl_test_case
extends TestCase
{
65 function gacl_test_case($name) {
66 $this->TestCase($name);
67 $this->gacl_api
= &$GLOBALS['gacl_api'];
76 function _formatValue($value, $class='') {
77 if (phpversion() < '4.0.0') {
78 return '<code class="'. $class .'">'. htmlentities((string)$value) .'</code>';
83 case is_object($value):
84 if (method_exists($value, 'toString')) {
85 $translateValue = $value->toString();
87 $translateValue = serialize($value);
90 $htmlValue = htmlentities($translateValue);
92 case is_array($value):
95 $translateValue = ob_get_contents();
98 $htmlValue = nl2br(str_replace(' ', ' ', htmlentities(rtrim($translateValue))));
100 case is_bool($value):
101 $htmlValue = $value ?
'<i>true</i>' : '<i>false</i>';
103 case phpversion() >= '4.0.4' && is_null($value):
104 $htmlValue = '<i>null</i>';
107 $htmlValue = htmlentities(strval($value));
110 $htmlValue = '<code class="'. $class . '">' . $htmlValue . '</code>';
111 $htmlValue .= ' <span class="typeinfo">';
112 $htmlValue .= 'type:' . gettype($value);
114 if (is_object($value)) {
115 $htmlValue .= ', class:' . get_class($value);
118 $htmlValue .= '</span>';
125 custom TestSuite class for future expansion
127 class gacl_test_suite
extends TestSuite
{
131 $title = 'phpGACL Test Suite';
133 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
136 <title
><?php
echo $title; ?
></title
>
137 <link rel
="stylesheet" href
="styles.css" type
="text/css" title
="GACL Test Suite Styles"/>
140 <h1
><?php
echo $title; ?
></h1
>
141 <h2
>Running Tests
</h2
>
145 $result = new gacl_test_result
;
148 include('unit_tests.php');
151 include('acl_tests.php');