PageRenderTime 22ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/include/phpgacl/test_suite/run.php

https://github.com/radicaldesigns/amp
PHP | 161 lines | 114 code | 29 blank | 18 comment | 12 complexity | 5eb647da2f4bbed9e795a559e4c485f1 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. // require gacl & phpunit
  3. require_once(dirname(__FILE__).'/../admin/gacl_admin.inc.php');
  4. require_once(dirname(__FILE__).'/phpunit/phpunit.php');
  5. /*! class
  6. custom test result class for pretty results
  7. !*/
  8. class gacl_test_result extends TestResult {
  9. var $output = '';
  10. var $class_name;
  11. function report() {
  12. /* results table */
  13. echo '<h2>Test Results</h2>' . "\n";
  14. echo '<table cellspacing="1" cellpadding="1" border="1" class="details">'."\n";
  15. echo '<tr><th>Function</th><th width="10%">Success?</th></tr>'."\n";
  16. echo $this->output;
  17. echo '</table>'."\n";
  18. /* summary */
  19. $nRun = $this->countTests();
  20. $nFailures = $this->countFailures();
  21. echo '<h2>Summary</h2>'."\n";
  22. printf('<div class="indent"><p>%s test%s run<br />', $nRun, ($nRun == 1) ? '' : 's');
  23. printf("%s failure%s.</p></div>\n", $nFailures, ($nFailures == 1) ? '' : 's');
  24. }
  25. function _startTest($test) {
  26. }
  27. function _endTest($test) {
  28. if ( $test->classname() != $this->class_name ) {
  29. $this->class_name = $test->classname();
  30. $this->output .= '<tr><td colspan="2" class="class_name">'. $test->classname() .'</td></tr>'."\n";
  31. }
  32. $this->output .= '<tr><td class="function">'. $test->name();
  33. if ($test->failed()) {
  34. $this->output .= "<ul>\n";
  35. foreach ($test->getExceptions() as $exception) {
  36. $this->output .= '<li>'. $exception->getMessage() ."</li>\n";
  37. }
  38. $this->output .= "</ul>\n";
  39. $outcome = ' class="fail">FAIL';
  40. } else {
  41. $outcome = ' class="pass">OK';
  42. }
  43. $this->output .= '</td><td'. $outcome .'</td></tr>'."\n";
  44. }
  45. }
  46. /*! class
  47. custom TestCase class to allow control of error formatting
  48. can also be used for custom assert functions
  49. !*/
  50. class gacl_test_case extends TestCase {
  51. var $gacl_api;
  52. function gacl_test_case($name) {
  53. $this->TestCase($name);
  54. $this->gacl_api = &$GLOBALS['gacl_api'];
  55. }
  56. function setUp() {
  57. }
  58. function tearDown() {
  59. }
  60. function _formatValue($value, $class='') {
  61. if (phpversion() < '4.0.0') {
  62. return '<code class="'. $class .'">'. htmlentities((string)$value) .'</code>';
  63. }
  64. switch (TRUE)
  65. {
  66. case is_object($value):
  67. if (method_exists($value, 'toString')) {
  68. $translateValue = $value->toString();
  69. } else {
  70. $translateValue = serialize($value);
  71. }
  72. $htmlValue = htmlentities($translateValue);
  73. break;
  74. case is_array($value):
  75. ob_start();
  76. print_r($value);
  77. $translateValue = ob_get_contents();
  78. ob_end_clean();
  79. $htmlValue = nl2br(str_replace(' ', '&nbsp; &nbsp; ', htmlentities(rtrim($translateValue))));
  80. break;
  81. case is_bool($value):
  82. $htmlValue = $value ? '<i>true</i>' : '<i>false</i>';
  83. break;
  84. case phpversion() >= '4.0.4' && is_null($value):
  85. $htmlValue = '<i>null</i>';
  86. break;
  87. default:
  88. $htmlValue = htmlentities(strval($value));
  89. }
  90. $htmlValue = '<code class="'. $class . '">' . $htmlValue . '</code>';
  91. $htmlValue .= '&nbsp;&nbsp;<span class="typeinfo">';
  92. $htmlValue .= 'type:' . gettype($value);
  93. if (is_object($value)) {
  94. $htmlValue .= ', class:' . get_class($value);
  95. }
  96. $htmlValue .= '</span>';
  97. return $htmlValue;
  98. }
  99. }
  100. /*! class
  101. custom TestSuite class for future expansion
  102. !*/
  103. class gacl_test_suite extends TestSuite {
  104. }
  105. $title = 'phpGACL Test Suite';
  106. ?>
  107. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  108. <html>
  109. <head>
  110. <title><?php echo $title; ?></title>
  111. <link rel="stylesheet" href="styles.css" type="text/css" title="GACL Test Suite Styles"/>
  112. </head>
  113. <body>
  114. <h1><?php echo $title; ?></h1>
  115. <h2>Running Tests</h2>
  116. <div class="indent">
  117. <?php
  118. // initialise result
  119. $result = new gacl_test_result;
  120. // run api tests
  121. include('unit_tests.php');
  122. // run acl tests
  123. include('acl_tests.php');
  124. echo '
  125. </div>
  126. ';
  127. // show report
  128. $result->report();
  129. ?>
  130. </body>
  131. </html>