report.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. error_reporting(E_ERROR|E_WARNING);
  3. //经常碰到傲游和IE6同时完成的情况,如何处理比较合适?
  4. //TODO add php info in xml
  5. if (substr_count($_POST['config'], "browser") == 0) {
  6. echo "report only create if browser is set\n\r<br />";
  7. return;
  8. }
  9. function match($fileName, $matcher )
  10. {
  11. if ( $matcher == '*' )
  12. return true;
  13. $len = strlen( $matcher );
  14. $as = explode( ';' , $matcher );
  15. if ( sizeof( $as ) > 1 ) {
  16. //这里把或的逻辑改成与
  17. foreach ( $as as $matcher1 ) {
  18. if ( match($fileName, $matcher1 ) )
  19. return true;
  20. }
  21. return false;
  22. }
  23. $ms = explode( ',' , $matcher );
  24. if ( sizeof( $ms ) > 1 ) {
  25. //这里把或的逻辑改成与
  26. foreach ( $ms as $matcher1 ) {
  27. if ( !match($fileName, $matcher1 ) )
  28. return false;
  29. }
  30. return true;
  31. }
  32. /**
  33. * 处理反向选择分支
  34. */
  35. if ( substr( $matcher , 0 , 1 ) == '!' ) {
  36. $m = substr( $matcher , 1 );
  37. if ( substr( $fileName , 0 , strlen( $m ) ) == $m )
  38. return false;
  39. return true;
  40. }
  41. if ( $len > strlen( $fileName ) ) {
  42. return false;
  43. }
  44. return substr( $fileName , 0 , $len ) == $matcher;
  45. }
  46. function report()
  47. {
  48. /**
  49. * for junit report
  50. */
  51. $dom = new DOMDocument('1.0', 'utf-8');
  52. $suite = $dom->appendChild($dom->createElement('testsuite'));
  53. $cfg = preg_split('/[&=]/', $_POST['config']);
  54. $config = array();
  55. for ($i = 0; $i < sizeof($cfg); $i += 2) {
  56. // echo "{$cfg[$i]} {$cfg[$i+1]}\r\n<br />";
  57. $config[$cfg[$i]] = $cfg[$i + 1];
  58. $p = $suite->appendChild($dom->createElement("property"));
  59. $p->setAttribute('name', $cfg[$i]);
  60. $p->setAttribute('value', $cfg[$i + 1]);
  61. }
  62. $suite->setAttribute("name", $config['browser']);
  63. $errors = 0;
  64. $failures = 0;
  65. $tests = 0;
  66. $time = 0;
  67. $filter = $config['filterRun'];
  68. foreach ($_POST as $key => $value) {
  69. if ($key == 'config')
  70. continue;
  71. echo $key.' ';
  72. $info = explode(";", $value);
  73. if ($filter!='' && (!match($key,$filter))){
  74. continue;
  75. }
  76. //errornum + ',' + allnum + ','+ kissPerc || 0 + ',' + wb.kissstart + ','+ wb.kissend;
  77. $casetime = ($info[4] - $info[3]) / 1000;
  78. $time += $casetime;
  79. $tests++;
  80. $failure = (int)($info[0]);
  81. $case = $suite->appendChild($dom->createElement('testcase'));
  82. $case->setAttribute("name", str_replace('_','.',$key));
  83. $case->setAttribute("time", $casetime);
  84. $case->setAttribute("cov", $info[2]);
  85. $case->setAttribute('failNumber', $info[0]);
  86. $case->setAttribute('totalNumber', $info[1]);
  87. $case->setAttribute('recordCovForBrowser',$info[5]);
  88. $case->setAttribute('browserInfo', $config['browser']);
  89. $case->setAttribute('hostInfo', Config::$BROWSERS[$config['browser']][0]);
  90. // covHtml( $config[ 'browser' ] . '/' . $key , $info[ 2 ] );
  91. if ($failure > 0) {
  92. $failures++;
  93. $failinfo = $case->appendChild($dom->createElement('failure'));
  94. $failinfo->setAttribute('type', 'junit.framework.AssertionFailedError');
  95. //FROM php.net, You cannot simply overwrite $textContent, to replace the text content of a DOMNode, as the missing readonly flag suggests.
  96. $kiss = join(".", split("/", $key));
  97. // $failinfo->appendChild( new DOMText( $value ) );
  98. $failinfo->appendChild(new DOMText("<a href=\"http://10.48.31.90:8089/ueditor/_test/tools/br/run.php?case=$kiss\">run</a>"));
  99. }
  100. //TODO add more case info in xml
  101. }
  102. $suite->setAttribute('time', $time);
  103. $suite->setAttribute('failures', $failures);
  104. $suite->setAttribute('tests', $tests);
  105. // $dirName = "report_{$config['filter']}";
  106. $dirName = str_replace('/','_',"report_{$config['filter']}");
  107. if (!is_dir($dirName))
  108. mkdir($dirName);
  109. $dom->save($dirName."/{$config['browser']}.xml");
  110. }
  111. include 'config.php';
  112. $config;
  113. $configs = preg_split('/[&=]/', $_POST['config']);
  114. for ($j = 0; $j < sizeof($configs); $j += 2) {
  115. // echo "{$cfg[$i]} {$cfg[$i+1]}\r\n<br />";
  116. // if(strcmp($configs[$j],'browserSet')==0){
  117. $config[$configs[$j]] = $configs[$j + 1];
  118. // }
  119. }
  120. report();
  121. $dom = new DOMDocument('1.0', 'utf-8');
  122. $testsuites = $dom->appendChild($dom->createElement('testsuites'));
  123. $dirName = str_replace('/','_',"report_{$config['filter']}");
  124. foreach (Config::getBrowserSet($configBrowserSet) as $key => $value) {
  125. $file = $dirName."/$key.xml";
  126. if (!file_exists($file)) {
  127. echo "wait for report : $file\r\n<br />";
  128. return;
  129. }
  130. // Config::StopOne($key);
  131. $xmlDoc = new DOMDocument('1.0', 'utf-8');
  132. $xmlDoc->load($file);
  133. $xmlDom = $xmlDoc->documentElement;
  134. //echo $xmlDom->nodeName;
  135. $testsuites->appendChild($dom->importNode($xmlDom, true));
  136. }
  137. $dom->save("report.xml");
  138. $browserNum = count(Config::getBrowserSet($configBrowserSet));
  139. require_once 'record.php';
  140. record();
  141. Config::StopAll();
  142. ?>