Added logic to detect concurrent updating of the same fee sheet.
[openemr.git] / gacl / test_suite / run.php
blob1fce6339fc0e745c4cd3515d2ee43dc7237b88f0
1 <?php
2 // require gacl & phpunit
3 require_once(dirname(__FILE__).'/../admin/gacl_admin.inc.php');
4 require_once(dirname(__FILE__).'/phpunit/phpunit.php');
6 /*! class
7 custom test result class for pretty results
8 !*/
9 class gacl_test_result extends TestResult {
11 var $output = '';
12 var $class_name;
14 function report() {
15 /* results table */
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";
19 echo $this->output;
20 echo '</table>'."\n";
22 /* summary */
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';
48 } else {
49 $outcome = ' class="pass">OK';
52 $this->output .= '</td><td'. $outcome .'</td></tr>'."\n";
56 /*! class
57 custom TestCase class to allow control of error formatting
59 can also be used for custom assert functions
60 !*/
61 class gacl_test_case extends TestCase {
63 var $gacl_api;
65 function gacl_test_case($name) {
66 $this->TestCase($name);
67 $this->gacl_api = &$GLOBALS['gacl_api'];
70 function setUp() {
73 function tearDown() {
76 function _formatValue($value, $class='') {
77 if (phpversion() < '4.0.0') {
78 return '<code class="'. $class .'">'. htmlentities((string)$value) .'</code>';
81 switch (TRUE)
83 case is_object($value):
84 if (method_exists($value, 'toString')) {
85 $translateValue = $value->toString();
86 } else {
87 $translateValue = serialize($value);
90 $htmlValue = htmlentities($translateValue);
91 break;
92 case is_array($value):
93 ob_start();
94 print_r($value);
95 $translateValue = ob_get_contents();
96 ob_end_clean();
98 $htmlValue = nl2br(str_replace(' ', '&nbsp; &nbsp; ', htmlentities(rtrim($translateValue))));
99 break;
100 case is_bool($value):
101 $htmlValue = $value ? '<i>true</i>' : '<i>false</i>';
102 break;
103 case phpversion() >= '4.0.4' && is_null($value):
104 $htmlValue = '<i>null</i>';
105 break;
106 default:
107 $htmlValue = htmlentities(strval($value));
110 $htmlValue = '<code class="'. $class . '">' . $htmlValue . '</code>';
111 $htmlValue .= '&nbsp;&nbsp;<span class="typeinfo">';
112 $htmlValue .= 'type:' . gettype($value);
114 if (is_object($value)) {
115 $htmlValue .= ', class:' . get_class($value);
118 $htmlValue .= '</span>';
120 return $htmlValue;
124 /*! class
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">
134 <html>
135 <head>
136 <title><?php echo $title; ?></title>
137 <link rel="stylesheet" href="styles.css" type="text/css" title="GACL Test Suite Styles"/>
138 </head>
139 <body>
140 <h1><?php echo $title; ?></h1>
141 <h2>Running Tests</h2>
142 <div class="indent">
143 <?php
144 // initialise result
145 $result = new gacl_test_result;
147 // run api tests
148 include('unit_tests.php');
150 // run acl tests
151 include('acl_tests.php');
153 echo '
154 </div>
157 // show report
158 $result->report();
160 </body>
161 </html>