AutomatedTestCaseGroupController.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class AutomatedTestCaseGroupController
  19. {
  20. // 返回json类型
  21. private $returnJson = array(
  22. 'type' => 'automated_test_case_group'
  23. );
  24. // 用户ID
  25. private $user_id;
  26. /**
  27. * Checkout login status
  28. * 验证登录状态
  29. */
  30. public function __construct()
  31. {
  32. // identity authentication
  33. // 身份验证
  34. $server = new GuestModule;
  35. if (!$server->checkLogin()) {
  36. $this->returnJson['statusCode'] = '120005';
  37. exitOutput($this->returnJson);
  38. } else {
  39. $this->user_id = $_SESSION['userID'];
  40. }
  41. }
  42. /**
  43. * 添加用例分组
  44. */
  45. public function addGroup()
  46. {
  47. $project_id = securelyInput('projectID');
  48. // 分组组名
  49. $name_length = mb_strlen(quickInput('groupName'), 'utf8');
  50. $group_name = securelyInput('groupName');
  51. // 父分组ID
  52. $parent_group_id = securelyInput('parentGroupID', NULL);
  53. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  54. $this->returnJson['statusCode'] = '850005';
  55. } elseif ($name_length < 1 || $name_length > 32) {
  56. // 分组名称格式非法
  57. $this->returnJson['statusCode'] = '850001';
  58. } elseif (!preg_match('/^[0-9]{1,11}$/', $parent_group_id) && $parent_group_id != NULL) {
  59. // 分组ID格式不合法
  60. $this->returnJson['statusCode'] = '850002';
  61. } else {
  62. // 检查权限
  63. $project_module = new ProjectModule();
  64. $user_type = $project_module->getUserType($project_id);
  65. if ($user_type < 0 || $user_type > 2) {
  66. $this->returnJson['statusCode'] = '120007';
  67. } else {
  68. $service = new AutomatedTestCaseGroupModule();
  69. $result = $service->addGroup($project_id, $this->user_id, $group_name, $parent_group_id);
  70. // 验证结果
  71. if ($result) {
  72. // 添加项目用例分组成功
  73. $this->returnJson['statusCode'] = '000000';
  74. $this->returnJson['groupID'] = $result;
  75. } else {
  76. // 添加项目用例分组失败
  77. $this->returnJson['statusCode'] = '850000';
  78. }
  79. }
  80. }
  81. exitOutput($this->returnJson);
  82. }
  83. /**
  84. * 删除用例分组
  85. */
  86. public function deleteGroup()
  87. {
  88. // 分组ID
  89. $group_id = securelyInput('groupID');
  90. // 验证分组ID是否合法
  91. if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  92. // 分组ID格式不合法
  93. $this->returnJson['statusCode'] = '850003';
  94. } else {
  95. // 分组ID格式合法
  96. $service = new AutomatedTestCaseGroupModule();
  97. $user_type = $service->getUserType($group_id);
  98. if ($user_type < 0 || $user_type > 2) {
  99. $this->returnJson['statusCode'] = '120007';
  100. } else {
  101. $result = $service->deleteGroup($this->user_id, $group_id);
  102. // 验证结果
  103. if ($result) {
  104. // 删除项目用例分组成功
  105. $this->returnJson['statusCode'] = '000000';
  106. } else {
  107. // 删除用例分组失败
  108. $this->returnJson['statusCode'] = '850000';
  109. }
  110. }
  111. }
  112. exitOutput($this->returnJson);
  113. }
  114. /**
  115. * 获取用例分组列表
  116. */
  117. public function getGroupList()
  118. {
  119. $project_id = securelyInput('projectID');
  120. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  121. $this->returnJson['statusCode'] = '850005';
  122. } else {
  123. $service = new AutomatedTestCaseGroupModule();
  124. // 获取分组列表
  125. $result = $service->getGroupList($project_id, $this->user_id);
  126. // 验证结果
  127. if ($result) {
  128. // 获取用例分组成功
  129. $this->returnJson['statusCode'] = '000000';
  130. $this->returnJson = array_merge($this->returnJson, $result);
  131. } else {
  132. // 获取用例分组失败
  133. $this->returnJson['statusCode'] = '850000';
  134. }
  135. }
  136. exitOutput($this->returnJson);
  137. }
  138. /**
  139. * 修改用例分组
  140. */
  141. public function editGroup()
  142. {
  143. // 分组组名长度
  144. $name_length = mb_strlen(quickInput('groupName'), 'utf8');
  145. // 分组ID
  146. $group_id = securelyInput('groupID');
  147. // 分组组名
  148. $group_name = securelyInput('groupName');
  149. // 父分组ID
  150. $parent_group_id = securelyInput('parentGroupID', NULL);
  151. // 判断分组ID和组名格式是否合法
  152. if ($name_length < 1 && $name_length > 32) {
  153. $this->returnJson['statusCode'] = '850001';
  154. } elseif (!preg_match('/^[0-9]{1,11}$/', $parent_group_id) && $parent_group_id != NULL) {
  155. // 父分组ID格式不合法
  156. $this->returnJson['statusCode'] = '850002';
  157. } elseif (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  158. // 分组ID格式不合法
  159. $this->returnJson['statusCode'] = '850003';
  160. } else {
  161. // 检查权限
  162. $service = new AutomatedTestCaseGroupModule();
  163. $user_type = $service->getUserType($group_id);
  164. if ($user_type < 0 || $user_type > 2) {
  165. $this->returnJson['statusCode'] = '120007';
  166. } else {
  167. $result = $service->editGroup($this->user_id, $group_id, $group_name, $parent_group_id);
  168. if ($result) {
  169. // 修改用例分组成功
  170. $this->returnJson['statusCode'] = '000000';
  171. } else {
  172. // 修改用例分组失败
  173. $this->returnJson['statusCode'] = '850000';
  174. }
  175. }
  176. }
  177. exitOutput($this->returnJson);
  178. }
  179. /**
  180. * 分组排序
  181. */
  182. public function sortGroup()
  183. {
  184. // 排序json字符串
  185. $order_list = quickInput('orderList');
  186. $project_id = securelyInput('projectID');
  187. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  188. $this->returnJson['statusCode'] = '850005';
  189. } // 判断排序格式是否合法
  190. elseif (empty($order_list)) {
  191. // 排序格式非法
  192. $this->returnJson['statusCode'] = '850004';
  193. } else {
  194. // 检查权限
  195. $project_module = new ProjectModule();
  196. $user_type = $project_module->getUserType($project_id);
  197. if ($user_type < 0 || $user_type > 2) {
  198. $this->returnJson['statusCode'] = '120007';
  199. } else {
  200. $service = new AutomatedTestCaseGroupModule();
  201. $result = $service->sortGroup($project_id, $order_list, $this->user_id);
  202. // 验证结果
  203. if ($result) {
  204. $this->returnJson['statusCode'] = '000000';
  205. } else {
  206. $this->returnJson['statusCode'] = '850000';
  207. }
  208. }
  209. }
  210. exitOutput($this->returnJson);
  211. }
  212. /**
  213. * 导出测试用例分组数据
  214. */
  215. public function exportGroup()
  216. {
  217. // 分组ID
  218. $group_id = securelyInput('groupID');
  219. if (!preg_match('/^[1-9][0-9]{0,10}$/', $group_id)) {
  220. // 分组ID格式不合法
  221. $this->returnJson['statusCode'] = '850003';
  222. } else {
  223. $server = new AutomatedTestCaseGroupModule();
  224. $user_type = $server->getUserType($group_id);
  225. if ($user_type < 0 || $user_type > 2) {
  226. $this->returnJson['statusCode'] = '120007';
  227. } else {
  228. $result = $server->exportTestCaseGroup($group_id, $this->user_id);
  229. if ($result) {
  230. $this->returnJson['statusCode'] = '000000';
  231. $this->returnJson['fileName'] = $result;
  232. } else {
  233. $this->returnJson['statusCode'] = '850000';
  234. }
  235. }
  236. }
  237. exitOutput($this->returnJson);
  238. }
  239. public function importGroup()
  240. {
  241. $json = quickInput('data');
  242. $project_id = securelyInput('projectID');
  243. $data = json_decode($json, TRUE);
  244. if (!preg_match('/^[1-9][0-9]{0,10}$/', $project_id)) {
  245. $this->returnJson['statusCode'] = '850005';
  246. } //判断导入数据是否为空
  247. elseif (empty($data)) {
  248. $this->returnJson['statusCode'] = '850005';
  249. } else {
  250. // 检查权限
  251. $project_module = new ProjectModule();
  252. $user_type = $project_module->getUserType($project_id);
  253. if ($user_type < 0 || $user_type > 2) {
  254. $this->returnJson['statusCode'] = '120007';
  255. } else {
  256. $server = new AutomatedTestCaseGroupModule();
  257. $result = $server->importTestCaseGroup($project_id, $this->user_id, $data);
  258. if ($result) {
  259. $this->returnJson['statusCode'] = '000000';
  260. } else {
  261. $this->returnJson['statusCode'] = '850000';
  262. }
  263. }
  264. }
  265. exitOutput($this->returnJson);
  266. }
  267. }