testsuites.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * The testsuites entry point of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class testsuitesEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $productID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($productID = 0)
  22. {
  23. if(empty($productID)) $productID = $this->param('product', 0);
  24. if(empty($productID)) return $this->sendError(400, 'Need product id.');
  25. $control = $this->loadController('testsuite', 'browse');
  26. $control->browse($productID, 'all', $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1));
  27. $data = $this->getData();
  28. if(isset($data->status) and $data->status == 'success')
  29. {
  30. $suites = $data->data->suites;
  31. $pager = $data->data->pager;
  32. $result = array();
  33. foreach($suites as $suite)
  34. {
  35. $result[] = $this->format($suite, 'addedBy:user,addedDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool');
  36. }
  37. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testsuites' => $result));
  38. }
  39. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  40. return $this->sendError(400, 'error');
  41. }
  42. /**
  43. * POST method.
  44. *
  45. * @param int $productID
  46. * @access public
  47. * @return string
  48. */
  49. public function post($productID = 0)
  50. {
  51. if(!$productID) $productID = $this->param('product');
  52. if(!$productID and isset($this->requestBody->product)) $productID = $this->requestBody->product;
  53. if(!$productID) return $this->sendError(400, 'Need product id.');
  54. $control = $this->loadController('testsuite', 'create');
  55. $fields = 'name,type';
  56. $this->batchSetPost($fields);
  57. $this->setPost('product', $productID);
  58. $this->setPost('desc', $this->request('desc', ''));
  59. $this->setPost('type', $this->request('type', 'private'));
  60. $this->requireFields('name');
  61. $control->create($productID);
  62. $data = $this->getData();
  63. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  64. if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
  65. $suite = $this->loadModel('testsuite')->getByID($data->id);
  66. return $this->send(200, $this->format($suite, 'addedBy:user,addedDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool'));
  67. }
  68. }