zen.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. class caselibZen extends caselib
  3. {
  4. /**
  5. * 设置用例库状态。
  6. * Save lib state.
  7. *
  8. * @param int $libID
  9. * @param array $libraries
  10. * @access public
  11. * @return int
  12. */
  13. public function saveLibState($libID = 0, $libraries = array())
  14. {
  15. if(empty($libraries)) return 0;
  16. if($libID > 0) $this->session->set('caseLib', (int)$libID);
  17. if($libID == 0 && $this->cookie->lastCaseLib) $this->session->set('caseLib', $this->cookie->lastCaseLib);
  18. if($libID == 0 && !$this->session->caseLib) $this->session->set('caseLib', key($libraries));
  19. if(!isset($libraries[$this->session->caseLib])) $this->session->set('caseLib', key($libraries));
  20. return $this->session->caseLib;
  21. }
  22. /**
  23. * 为浏览用例库的用例设置 session 和 cookie。
  24. * Set session and cookie for browse.
  25. *
  26. * @param int $libID
  27. * @param string $browseType
  28. * @param int $param
  29. * @access public
  30. * @return void
  31. */
  32. public function setBrowseSessionAndCookie($libID = 0, $browseType = 'all', $param = 0)
  33. {
  34. /* Save session. */
  35. $this->session->set('caseList', $this->app->getURI(true), 'qa');
  36. $this->session->set('caselibList', $this->app->getURI(true), 'qa');
  37. if($browseType != 'bymodule') $this->session->set('libBrowseType', $browseType);
  38. /* Save cookie. */
  39. helper::setcookie('preCaseLibID', (string)$libID, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true);
  40. if($this->cookie->preCaseLibID != $libID)
  41. {
  42. $_COOKIE['libCaseModule'] = 0;
  43. helper::setcookie('libCaseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, true);
  44. }
  45. if($browseType == 'bymodule') helper::setcookie('libCaseModule', (string)$param, 0, $this->config->webRoot, '', $this->config->cookieSecure, true);
  46. }
  47. /**
  48. * 构建查询表单。
  49. * Build search form.
  50. *
  51. * @param int $libID
  52. * @param array $libraries
  53. * @param int $queryID
  54. * @param string $actionURL
  55. * @access public
  56. * @return void
  57. */
  58. public function buildSearchForm($libID, $libraries, $queryID, $actionURL)
  59. {
  60. /* Set lib for search. */
  61. $this->config->testcase->search['fields']['lib'] = $this->lang->testcase->lib;
  62. $this->config->testcase->search['params']['lib']['values'] = array('' => '', $libID => $libraries[$libID], 'all' => $this->lang->caselib->all);
  63. $this->config->testcase->search['params']['lib']['operator'] = '=';
  64. $this->config->testcase->search['params']['lib']['control'] = 'select';
  65. $this->config->testcase->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($libID, 'caselib');
  66. /* Unset fields for search. */
  67. if(!$this->config->testcase->needReview) unset($this->config->testcase->search['params']['status']['values']['wait']);
  68. unset($this->config->testcase->search['fields']['product']);
  69. unset($this->config->testcase->search['params']['product']);
  70. unset($this->config->testcase->search['fields']['branch']);
  71. unset($this->config->testcase->search['params']['branch']);
  72. unset($this->config->testcase->search['fields']['scene']);
  73. unset($this->config->testcase->search['params']['scene']);
  74. unset($this->config->testcase->search['fields']['lastRunner']);
  75. unset($this->config->testcase->search['params']['lastRunner']);
  76. unset($this->config->testcase->search['fields']['lastRunResult']);
  77. unset($this->config->testcase->search['params']['lastRunResult']);
  78. unset($this->config->testcase->search['fields']['lastRunDate']);
  79. unset($this->config->testcase->search['params']['lastRunDate']);
  80. /* Set search params. */
  81. $this->config->testcase->search['module'] = 'caselib';
  82. $this->config->testcase->search['actionURL'] = $actionURL;
  83. $this->config->testcase->search['queryID'] = $queryID;
  84. $this->loadModel('search')->setSearchParams($this->config->testcase->search);
  85. }
  86. /**
  87. * 为创建用例分配用例变量。
  88. * Assign case params for creating case.
  89. *
  90. * @param int $param
  91. * @access public
  92. * @return void
  93. */
  94. public function assignCaseParamsForCreateCase($param)
  95. {
  96. $caseTitle = '';
  97. $type = 'feature';
  98. $stage = '';
  99. $pri = 3;
  100. $precondition = '';
  101. $keywords = '';
  102. $steps = array();
  103. $this->loadModel('testcase');
  104. if($param)
  105. {
  106. $testcase = $this->testcase->getById($param);
  107. $type = $testcase->type ? $testcase->type : 'feature';
  108. $stage = $testcase->stage;
  109. $pri = $testcase->pri;
  110. $caseTitle = $testcase->title;
  111. $precondition = $testcase->precondition;
  112. $keywords = $testcase->keywords;
  113. $steps = $testcase->steps;
  114. }
  115. $this->view->caseTitle = $caseTitle;
  116. $this->view->type = $type;
  117. $this->view->stage = $stage;
  118. $this->view->pri = $pri;
  119. $this->view->precondition = $precondition;
  120. $this->view->keywords = $keywords;
  121. $this->view->steps = $this->testcase->appendSteps($steps);
  122. }
  123. /**
  124. * 为批量创建用例提前处理用例数据。
  125. * Prepare cases for batch creating cases.
  126. *
  127. * @param int $libID
  128. * @access public
  129. * @return array
  130. */
  131. public function prepareCasesForBathcCreate($libID)
  132. {
  133. $this->loadModel('common');
  134. $this->loadModel('testcase');
  135. unset($this->config->testcase->form->batchCreate['review']);
  136. $now = helper::now();
  137. $account = $this->app->user->account;
  138. $forceNotReview = $this->loadModel('testcase')->forceNotReview();
  139. $testcases = form::batchData($this->config->testcase->form->batchCreate)->get();
  140. foreach($testcases as $i => $testcase)
  141. {
  142. $testcase->lib = $libID;
  143. $testcase->project = 0;
  144. $testcase->openedBy = $account;
  145. $testcase->openedDate = $now;
  146. $testcase->status = $forceNotReview ? 'normal' : 'wait';
  147. $testcase->version = 1;
  148. $testcase->steps = array();
  149. $testcase->expects = array();
  150. $testcase->stepType = array();
  151. }
  152. $requiredErrors = array();
  153. foreach($testcases as $i => $testcase)
  154. {
  155. /* Check required fields. */
  156. foreach(explode(',', $this->config->caselib->createcase->requiredFields) as $field)
  157. {
  158. $field = trim($field);
  159. if($field && empty($testcase->{$field}))
  160. {
  161. $fieldName = $this->config->testcase->form->batchCreate[$field]['type'] != 'array' ? "{$field}[{$i}]" : "{$field}[{$i}][]";
  162. $requiredErrors[$fieldName] = sprintf($this->lang->error->notempty, $this->lang->testcase->{$field});
  163. }
  164. }
  165. }
  166. if(!empty($requiredErrors)) dao::$errors = $requiredErrors;
  167. return $testcases;
  168. }
  169. /**
  170. * 准备编辑用例库的数据。
  171. * Prepare data for edit caselib.
  172. *
  173. * @param object $formData
  174. * @param int $libID
  175. * @access protected
  176. * @return object
  177. */
  178. protected function prepareEditExtras($formData, $libID)
  179. {
  180. $lib = $formData->add('id', $libID)
  181. ->add('lastEditedBy', $this->app->user->account)
  182. ->add('lastEditedDate', helper::now())
  183. ->stripTags($this->config->caselib->editor->edit['id'], $this->config->allowedTags)
  184. ->get();
  185. return $this->loadModel('file')->processImgURL($lib, $this->config->caselib->editor->edit['id'], $lib->uid);
  186. }
  187. /**
  188. * 获取导出模板的字段。
  189. * Get fields for export template.
  190. *
  191. * @access protected
  192. * @return array
  193. */
  194. protected function getFieldsForExportTemplate()
  195. {
  196. $fields = array();
  197. foreach($this->config->caselib->exportTemplateFields as $field) $fields[$field] = $this->lang->testcase->$field;
  198. $fields[''] = '';
  199. $fields['typeValue'] = $this->lang->testcase->lblTypeValue;
  200. $fields['stageValue'] = $this->lang->testcase->lblStageValue;
  201. return $fields;
  202. }
  203. /**
  204. * 获取导出模板的数据。
  205. * Get rows for export template.
  206. *
  207. * @param int $num
  208. * @param array $modules
  209. * @access protected
  210. * @return array
  211. */
  212. protected function getRowsForExportTemplate($num, $modules)
  213. {
  214. $rows = array();
  215. for($i = 0; $i < $num; $i++)
  216. {
  217. foreach($modules as $moduleID => $module)
  218. {
  219. $row = new stdclass();
  220. $row->module = $module . "(#$moduleID)";
  221. $row->stepDesc = "1. \n2. \n3.";
  222. $row->stepExpect = "1. \n2. \n3.";
  223. if(empty($rows))
  224. {
  225. unset($this->lang->testcase->typeList['unit']);
  226. $row->typeValue = implode("\n", $this->lang->testcase->typeList);
  227. $row->stageValue = implode("\n", $this->lang->testcase->stageList);
  228. }
  229. $rows[] = $row;
  230. }
  231. }
  232. return $rows;
  233. }
  234. /**
  235. * 获取导入文件的表头字段和列。
  236. * Get header and columns from import file.
  237. *
  238. * @param string $fileName
  239. * @param array $fields
  240. * @access protected
  241. * @return array
  242. */
  243. protected function getImportHeaderAndColumns($fileName, $fields)
  244. {
  245. $rows = $this->loadModel('file')->parseCSV($fileName);
  246. if(empty($rows[0])) return array(array(), array());
  247. $header = array();
  248. foreach($rows[0] as $i => $rowValue)
  249. {
  250. if(empty($rowValue)) break;
  251. $header[$i] = $rowValue;
  252. }
  253. $columns = array();
  254. foreach($header as $title)
  255. {
  256. if(!isset($fields[$title])) continue;
  257. $columns[] = $fields[$title];
  258. }
  259. return array($header, $columns);
  260. }
  261. /**
  262. * 获得用例的步骤和预期结果。
  263. * Get steps and expects from import file.
  264. *
  265. * @param string $field
  266. * @param int $row
  267. * @param string $cellValue
  268. * @access protected
  269. * @return array
  270. */
  271. protected function getStepsAndExpectsFromImportFile($field, $row, $cellValue)
  272. {
  273. $steps = array();
  274. $steps = explode("\n", $cellValue);
  275. if(strpos($cellValue, "\r")) $steps = explode("\r", $cellValue);
  276. $caseSteps = array();
  277. foreach($steps as $step)
  278. {
  279. $step = trim($step);
  280. if(empty($step)) continue;
  281. preg_match('/^((([0-9]+)[.]([0-9]+))[.]([0-9]+))[.、](.*)$/Uu', $step, $out);
  282. if(!$out) preg_match('/^(([0-9]+)[.]([0-9]+))[.、](.*)$/Uu', $step, $out);
  283. if(!$out) preg_match('/^([0-9]+)[.、](.*)$/Uu', $step, $out);
  284. if($out)
  285. {
  286. $count = count($out);
  287. $num = $out[1];
  288. $parent = $count > 4 ? $out[2] : '0';
  289. $grand = $count > 6 ? $out[3] : '0';
  290. $step = trim($out[2]);
  291. if($count > 4) $step = $count > 6 ? trim($out[6]) : trim($out[4]);
  292. $caseSteps[$num]['content'] = $step;
  293. $caseSteps[$num]['number'] = $num;
  294. $caseSteps[$num]['type'] = $count > 4 ? 'item' : 'step';
  295. if(!empty($parent)) $caseSteps[$parent]['type'] = 'group';
  296. if(!empty($grand)) $caseSteps[$grand]['type'] = 'group';
  297. }
  298. elseif(isset($num))
  299. {
  300. $caseSteps[$num]['content'] = isset($caseSteps[$num]['content']) ? "{$caseSteps[$num]['content']}\n{$step}" : "\n{$step}";
  301. }
  302. elseif($field == 'stepDesc')
  303. {
  304. $num = 1;
  305. $caseSteps[$num]['content'] = $step;
  306. $caseSteps[$num]['type'] = 'step';
  307. $caseSteps[$num]['number'] = $num;
  308. }
  309. elseif($field == 'stepExpect' && isset($stepData[$row]['desc']))
  310. {
  311. end($stepData[$row]['desc']);
  312. $num = key($stepData[$row]['desc']);
  313. $caseSteps[$num]['content'] = $step;
  314. $caseSteps[$num]['number'] = $num;
  315. }
  316. }
  317. return $caseSteps;
  318. }
  319. /**
  320. * 获取导入用例的字段。
  321. * Get fields for import test case.
  322. *
  323. * @access protected
  324. * @return array
  325. */
  326. protected function getFieldsForImport()
  327. {
  328. $fields = explode(',', $this->config->testcase->exportFields);
  329. $libFields = array_flip($this->config->caselib->exportTemplateFields);
  330. foreach($fields as $key => $fieldName)
  331. {
  332. $fieldName = trim($fieldName);
  333. if(isset($libFields[$fieldName])) $fields[$fieldName] = zget($this->lang->testcase, $fieldName);
  334. unset($fields[$key]);
  335. }
  336. return array_flip($fields);
  337. }
  338. /**
  339. * 获取展示导入用例的列。
  340. * Get columns for show import.
  341. *
  342. * @param array $firstRow
  343. * @param array $fields
  344. * @access protected
  345. * @return array
  346. */
  347. protected function getColumnsForShowImport($firstRow, $fields)
  348. {
  349. /* 获取表头和列。*/
  350. $header = array();
  351. foreach($firstRow as $i => $rowValue)
  352. {
  353. if(empty($rowValue)) break;
  354. $header[$i] = $rowValue;
  355. }
  356. $columns = array();
  357. foreach($header as $i => $title)
  358. {
  359. if(!isset($fields[$title])) continue;
  360. $columns[$i] = $fields[$title];
  361. }
  362. return $columns;
  363. }
  364. /**
  365. * 获取导入用例的数据。
  366. * Get data for import testcase.
  367. *
  368. * @param int $maxImport
  369. * @param string $tmpFile
  370. * @param array $fields
  371. * @access protected
  372. * @return array
  373. */
  374. protected function getDataForImport($maxImport, $tmpFile, $fields)
  375. {
  376. $stepVars = 0;
  377. if(!empty($maxImport) && file_exists($tmpFile))
  378. {
  379. $data = unserialize(file_get_contents($tmpFile));
  380. return array($data['caseData'], $stepVars);
  381. }
  382. $rows = $this->loadModel('file')->parseCSV($this->session->fileImport);
  383. $columns = $this->getColumnsForShowImport($rows[0], $fields);
  384. unset($rows[0]);
  385. $caseData = array();
  386. foreach($rows as $row => $data)
  387. {
  388. $case = new stdclass();
  389. foreach($columns as $key => $field)
  390. {
  391. if(!isset($data[$key])) continue;
  392. $cellValue = $data[$key];
  393. $case->$field = $cellValue;
  394. if($field == 'module') $case->$field = strrpos($cellValue, '(#') !== false ? trim(substr($cellValue, strrpos($cellValue, '(#') + 2), ')') : 0;
  395. if(in_array($field, $this->config->testcase->export->listFields))
  396. {
  397. if($field == 'stage')
  398. {
  399. $stages = explode("\n", $cellValue);
  400. $case->stage = array();
  401. foreach($stages as $stage) $case->stage[] = array_search($stage, $this->lang->testcase->stageList);
  402. $case->stage = implode(',', $case->stage);
  403. }
  404. else
  405. {
  406. $case->$field = array_search($cellValue, $this->lang->testcase->{$field . 'List'});
  407. }
  408. }
  409. if($field == 'stepDesc') $case->steps = $cellValue;
  410. if($field == 'stepExpect') $case->expects = $cellValue;
  411. }
  412. if(empty($case->title)) continue;
  413. $caseData[$row] = $case;
  414. }
  415. $data = array('caseData' => $caseData);
  416. file_put_contents($tmpFile, serialize($data));
  417. return array($caseData, $stepVars);
  418. }
  419. /**
  420. * 导入用例的返回。
  421. * Response after show import.
  422. *
  423. * @param int $libID
  424. * @param array $caseData
  425. * @param int $maxImport
  426. * @param int $pageID
  427. * @param int $stepVars
  428. * @access protected
  429. * @return bool
  430. */
  431. protected function responseAfterShowImport($libID, $caseData, $maxImport, $pageID, $stepVars)
  432. {
  433. /* 如果没有用例数据时返回。*/
  434. /* Response when there is no case. */
  435. if(empty($caseData))
  436. {
  437. unlink($this->session->fileImport);
  438. unset($_SESSION['fileImport']);
  439. return $this->send(array('result' => 'fail', 'load' => array('alert' => $this->lang->error->noData, 'locate' => $this->createLink('caselib', 'browse', "libID=$libID"))));
  440. }
  441. /* 如果导入的用例多余设置的最大导入数。*/
  442. /* If the total amount of the import case is more than the max import. */
  443. $totalAmount = count($caseData);
  444. if($totalAmount > $this->config->file->maxImport)
  445. {
  446. /* 如果没有限制每页的导入数量,按照默认最大导入数分页导入。*/
  447. /* If there is no limit for import, limit as the max import in config. */
  448. if(empty($maxImport))
  449. {
  450. $this->view->totalAmount = $totalAmount;
  451. $this->view->maxImport = $maxImport;
  452. $this->view->libID = $libID;
  453. die($this->display());
  454. }
  455. $caseData = array_slice($caseData, ($pageID - 1) * $maxImport, $maxImport, true);
  456. }
  457. if(empty($caseData)) return $this->send(array('result'=>'success', 'load' => $this->createLink('caselib', 'browse', "libID=$libID")));
  458. $countInputVars = count($caseData) * 9 + (isset($stepVars) ? $stepVars : 0);
  459. $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars);
  460. if($showSuhosinInfo)
  461. {
  462. $this->view->suhosinInfo = sprintf((extension_loaded('suhosin') ? $this->lang->suhosinInfo : $this->lang->maxVarsInfo), $countInputVars);
  463. die($this->display());
  464. }
  465. return true;
  466. }
  467. /**
  468. * 获取导出的字段列表。
  469. * Get the export fields.
  470. *
  471. * @access protected
  472. * @return array
  473. */
  474. protected function getExportCasesFields()
  475. {
  476. $this->app->loadLang('testcase');
  477. $fields = $this->post->exportFields ? $this->post->exportFields : explode(',', $this->config->caselib->exportFields);
  478. foreach($fields as $key => $fieldName)
  479. {
  480. $fieldName = trim($fieldName);
  481. $fields[$fieldName] = zget($this->lang->testcase, $fieldName);
  482. unset($fields[$key]);
  483. }
  484. return $fields;
  485. }
  486. /**
  487. * 处理导出的用例数据。
  488. * Process export cases.
  489. *
  490. * @param array $cases
  491. * @param int $libID
  492. * @access protected
  493. * @return array
  494. */
  495. protected function processCasesForExport($cases, $libID)
  496. {
  497. $users = $this->loadModel('user')->getPairs('noletter');
  498. $relatedModules = $this->loadModel('tree')->getModulePairs($libID, 'caselib');
  499. $relatedSteps = $this->loadModel('testcase')->getRelatedSteps(array_keys($cases));
  500. $relatedFiles = $this->testcase->getRelatedFiles(array_keys($cases));
  501. $cases = $this->testcase->appendData($cases);
  502. foreach($cases as $case)
  503. {
  504. $case->stepDesc = '';
  505. $case->stepExpect = '';
  506. $case->openedDate = !helper::isZeroDate($case->openedDate) ? substr($case->openedDate, 0, 10) : '';
  507. $case->lastRunDate = !helper::isZeroDate($case->lastRunDate) ? $case->lastRunDate : '';
  508. $case->module = isset($relatedModules[$case->module])? $relatedModules[$case->module] . "(#$case->module)" : '';
  509. $case->pri = zget($this->lang->testcase->priList, $case->pri);
  510. $case->type = zget($this->lang->testcase->typeList, $case->type);
  511. $case->status = $this->processStatus('testcase', $case);
  512. $case->openedBy = zget($users, $case->openedBy);
  513. $case->lastEditedBy = zget($users, $case->lastEditedBy);
  514. $this->processStepForExport($case, $relatedSteps);
  515. $this->processStageForExport($case);
  516. $this->processFileForExport($case, $relatedFiles);
  517. if($case->linkCase) $this->processLinkCaseForExport($case);
  518. }
  519. return $cases;
  520. }
  521. /**
  522. * 处理导出的用例的步骤。
  523. * Process step of case for export.
  524. *
  525. * @param object $case
  526. * @param array $relatedSteps
  527. * @access protected
  528. * @return void
  529. */
  530. protected function processStepForExport($case, $relatedSteps)
  531. {
  532. if(isset($relatedSteps[$case->id]))
  533. {
  534. $preGrade = 1;
  535. $parentSteps = array();
  536. $key = array(0, 0, 0);
  537. foreach($relatedSteps[$case->id] as $step)
  538. {
  539. $grade = 1;
  540. $parentSteps[$step->id] = $step->parent;
  541. if(isset($parentSteps[$step->parent])) $grade = isset($parentSteps[$parentSteps[$step->parent]]) ? 3 : 2;
  542. if($grade > $preGrade)
  543. {
  544. $key[$grade - 1] = 1;
  545. }
  546. else
  547. {
  548. if($grade < $preGrade)
  549. {
  550. if($grade < 2) $key[1] = 0;
  551. if($grade < 3) $key[2] = 0;
  552. }
  553. $key[$grade - 1] ++;
  554. }
  555. $stepID = implode('.', $key);
  556. $stepID = str_replace('.0', '', $stepID);
  557. $stepID = str_replace('.0', '', $stepID);
  558. $sign = (in_array($this->post->fileType, array('html', 'xml'))) ? '<br />' : "\n";
  559. $case->stepDesc .= $stepID . ". " . htmlspecialchars_decode($step->desc) . $sign;
  560. $case->stepExpect .= $stepID . ". " . htmlspecialchars_decode($step->expect) . $sign;
  561. $preGrade = $grade;
  562. }
  563. }
  564. $case->stepDesc = trim($case->stepDesc);
  565. $case->stepExpect = trim($case->stepExpect);
  566. if($this->post->fileType == 'csv')
  567. {
  568. $case->stepDesc = str_replace('"', '""', $case->stepDesc);
  569. $case->stepExpect = str_replace('"', '""', $case->stepExpect);
  570. }
  571. }
  572. /**
  573. * 处理导出的用例的适用阶段。
  574. * Process stage of case for export.
  575. *
  576. * @param object $case
  577. * @access protected
  578. * @return void
  579. */
  580. protected function processStageForExport($case)
  581. {
  582. $case->stage = explode(',', $case->stage);
  583. foreach($case->stage as $key => $stage) $case->stage[$key] = isset($this->lang->testcase->stageList[$stage]) ? $this->lang->testcase->stageList[$stage] : $stage;
  584. $case->stage = implode("\n", $case->stage);
  585. }
  586. /**
  587. * 处理导出用例的附件。
  588. * Process file of case for export.
  589. *
  590. * @param object $case
  591. * @param array $relatedFiles
  592. * @access protected
  593. * @return void
  594. */
  595. protected function processFileForExport($case, $relatedFiles)
  596. {
  597. $case->files = '';
  598. if(isset($relatedFiles[$case->id]))
  599. {
  600. foreach($relatedFiles[$case->id] as $file)
  601. {
  602. $fileURL = common::getSysURL() . $this->createLink('file', 'download', "fileID={$file->id}");
  603. $case->files .= html::a($fileURL, $file->title, '_blank') . '<br />';
  604. }
  605. }
  606. }
  607. /**
  608. * 处理导出用例的相关用例。
  609. * Process link case of the case for export.
  610. *
  611. * @param object $case
  612. * @access protected
  613. * @return void
  614. */
  615. protected function processLinkCaseForExport($case)
  616. {
  617. $tmpLinkCases = array();
  618. $linkCaseIdList = explode(',', $case->linkCase);
  619. foreach($linkCaseIdList as $linkCaseID)
  620. {
  621. $linkCaseID = trim($linkCaseID);
  622. $tmpLinkCases[] = isset($relatedCases[$linkCaseID]) ? $relatedCases[$linkCaseID] . "(#$linkCaseID)" : $linkCaseID;
  623. }
  624. $case->linkCase = implode("; \n", $tmpLinkCases);
  625. }
  626. }