PageRenderTime 75ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/test/tools/br/geneHTML.php

https://github.com/BlackZhang/Magic
PHP | 124 lines | 71 code | 7 blank | 46 comment | 2 complexity | 81e3909e1e85dcdf919cd3050f04a07f MD5 | raw file
  1. <?php
  2. /**
  3. * 使用注意事项:一般情况下不会所产生的测试结果表格内容不会有问题,
  4. * 问题的引入是没有对每次添加的数据做浏览器判断,在正常情况下浏览器的顺序恒定不变的
  5. * 当不同浏览器运行的测试内容不同的情况下,如ie8下采用filter=baidu.fx,
  6. * 而chrome下采用filter=baidu.fx.collaplse
  7. * 在添加浏览器的时候按照顺序会先添加chrome,再添加ie8
  8. * 那么当chrome下用例只有baidu.fx.collapse的时候,
  9. * 由于他会默认先找到的浏览器为chrome,那么与它相邻的ie8的baidu.fx.current的内容会左移到chrome下。
  10. * 这个跟存储数据的格式有关系:caseList
  11. * / \
  12. * baidu.fx.collapse baidu.fx.current
  13. * / \ / \
  14. * chrome ie8 null ie8
  15. * / | \ / | \ (supposed / | \
  16. * fail total hostInfo to be chrome) fail total hostInfo
  17. *
  18. *
  19. *
  20. * 不直接使用<style type ="text/css">来设置css是因为有的邮件客户端会过滤这样的信息
  21. *
  22. * ***/
  23. function geneHTML($caseList, $name=''){
  24. date_default_timezone_set('PRC');
  25. $url = (isset ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $_SERVER['PHP_SELF'];
  26. $html = "<!DOCTYPE><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
  27. <style>td, th {border: 1px solid white;}</style></head><body><div>
  28. <h2 align='center'>自动化用例测试结果".date('Y-m-d H:i:s')."</h2>
  29. <a href='http://$url/../../../../../report/ui/$name' style='font:normal bolder 12pt Arial' title='效果应该比邮件好'>网页版</a>
  30. <table cellspacing='0' style='border: 1px solid black; color: #fff; background-color: #0d3349; text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; text-align: center;'>
  31. <thead><tr><th rowspan='2'>用例名称</th><th rowspan='2'>总覆盖率</th>".getThBrowser($caseList).
  32. "</tr></thead>".getTrCase($caseList).
  33. "</table></div>"._srcOnlyList()."</body></html>";
  34. return $html;
  35. }
  36. /**
  37. * 创建遗漏用例列表
  38. * FIXME: 需要过滤package类型,考虑使用js名称同名目录存在进行过滤或者白名单
  39. */
  40. function _srcOnlyList(){
  41. require 'case.class.php';
  42. $list = Kiss::listSrcOnly(false);
  43. $len = sizeof($list);
  44. $flag="<table cellspacing='0' style='border: 1px solid black; "
  45. ."color: #fff; background-color: #0d3349; "
  46. ."text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; "
  47. ."text-align: center;'><thead><tr><th>遗漏列表:总计$len,未过滤无需用例的package类型</th></tr><tr><td>";
  48. $flag.=implode("</td></tr><tr><td>", $list);
  49. $flag.="</tr></table>";
  50. return $flag;
  51. }
  52. /**
  53. *
  54. * 根据实际浏览器书目确认生成表头
  55. * @param unknown_type $caseList
  56. */
  57. function getThBrowser($caseList){
  58. //创建浏览器相关单元格
  59. $thBrowser = '';
  60. $count = 0;
  61. foreach ($caseList as $casename => $casedetail) {
  62. //每一个用例
  63. foreach ($casedetail as $b => $info) {
  64. $thBrowser .= "<th colspan='3'>$b</th>";
  65. $count++;
  66. }
  67. $thBrowser .="</tr><tr>";
  68. break;//遍历一次就知道所有浏览器的信息
  69. }
  70. for($index = 0; $index < $count; $index++) {
  71. $thBrowser .= "<td>cov</td><td>fail</td><td>total</td>";
  72. }
  73. return $thBrowser;
  74. }
  75. /**
  76. *
  77. * 根据执行结果生成单元格信息
  78. * @param unknown_type $caseList
  79. */
  80. function getTrCase($caseList){
  81. //创建case名对应的单元格
  82. $trCase = '';
  83. require_once 'config.php';
  84. $numBro = count(Config::$BROWSERS);
  85. foreach ($caseList as $casename => $caseDetail) {
  86. //每一个用例
  87. $cnurl = implode('.', explode('_', $casename));
  88. $trCase .= "<tr><td><a href='http://{$_SERVER['HTTP_HOST']}/{$_SERVER['PHP_SELF']}/../run.php?case=$cnurl'>运行</a>$casename</td>";
  89. $totalCov = calTotalCov($caseDetail,$numBro);
  90. $trCase .= "<td title='所有覆盖率的均值'>$totalCov</td>";
  91. foreach ($caseDetail as $br => $infos) {
  92. //$b为browser名字,$info为详细信息
  93. $fail = $infos['fail'];
  94. $total = $infos['total'];
  95. $cov = $infos['cov'];
  96. $color = $fail == 0 ? '#5E740B' : '#710909';
  97. $trCase .= "<td style='background-color:$color'>$cov%</td><td style='background-color:$color'>$fail</td><td style='background-color:$color'>$total</td>";
  98. }
  99. $trCase .= "</tr>";
  100. }
  101. return $trCase;
  102. }
  103. /**
  104. *
  105. * 计算总覆盖率信息
  106. * @param unknown_type $caseDetail
  107. * @param unknown_type $brcount
  108. */
  109. function calTotalCov($caseDetail,$brcount){
  110. $totalCov = 0;
  111. foreach ($caseDetail as $infos){
  112. $totalCov += $infos['cov'];
  113. }
  114. $aveCov = ceil($totalCov/$brcount);/*php默认原函数ceil,小数取整*/
  115. return $aveCov.'%';
  116. }
  117. ?>