zen.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * The zen file of ci module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Yanyi Cao <caoyanyi@easycorp.ltd>
  8. * @package ci
  9. * @link https://www.zentao.net
  10. */
  11. class ciZen extends ci
  12. {
  13. /**
  14. * 根据ztf提供数据获取产品ID和构建ID。
  15. * Get productID and jobID by ztf data.
  16. *
  17. * @param array $params
  18. * @param object $post
  19. * @access protected
  20. * @return array
  21. */
  22. protected function getProductIdAndJobID($params, $post)
  23. {
  24. $testType = $post->testType;
  25. $compileID = zget($params, 'compile', 0);
  26. $productID = zget($post, 'productId', 0);
  27. $jobID = 0;
  28. if($compileID)
  29. {
  30. $compile = $this->ci->getCompileByID($compileID);
  31. $jobID = $compile->job;
  32. if(empty($productID)) $productID = $compile->product;
  33. if(!in_array($compile->status, array('success', 'fail', 'create_fail', 'timeout'))) $this->ci->syncCompileStatus($compile);
  34. }
  35. /* Get productID from caseResult when productID is null. */
  36. if(empty($productID) && $testType == 'func')
  37. {
  38. $caseResult = $post->funcResult;
  39. $firstCase = array_shift($caseResult);
  40. $productID = $firstCase->productId;
  41. if(empty($productID) && !empty($firstCase->id))
  42. {
  43. $case = $this->loadModel('testcase')->fetchByID($firstCase->id);
  44. if($case) $productID = $case->product;
  45. }
  46. }
  47. return array($productID, $jobID);
  48. }
  49. /**
  50. * 根据ZTF提供数据解析结果。
  51. * Parse result by ztf data.
  52. *
  53. * @param object $post
  54. * @param int $taskID
  55. * @param int $productID
  56. * @param int $jobID
  57. * @param int $compileID
  58. * @access protected
  59. * @return bool
  60. */
  61. protected function parseZtfResult($post, $taskID, $productID, $jobID, $compileID)
  62. {
  63. $this->loadModel('testtask');
  64. $frame = zget($post, 'testFrame', 'junit');
  65. $testType = $post->testType;
  66. /* Build data from case results. */
  67. if($testType == 'unit')
  68. {
  69. $data = $this->testtask->parseZTFUnitResult($post->unitResult, $frame, $productID, $jobID, $compileID);
  70. }
  71. elseif($testType == 'func')
  72. {
  73. $data = $this->testtask->parseZTFFuncResult($post->funcResult, $frame, $productID, $jobID, $compileID);
  74. }
  75. $this->testtask->importDataOfUnitResult($taskID, $productID, $data['suites'], $data['cases'], $data['results'], $data['suiteNames'], $data['caseTitles'], $testType);
  76. return !dao::isError();
  77. }
  78. }