From 27bd5770b129cc36970898fbcdc110a2ef50fdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Thu, 18 Nov 2021 16:03:06 +0800 Subject: [PATCH] * code for task #44332. --- api/v1/entries/execution.php | 4 +++ api/v1/entries/executioncases.php | 49 +++++++++++++++++++++++++++++++ config/routes.php | 7 +++-- module/testcase/model.php | 24 ++++++++++++++- 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 api/v1/entries/executioncases.php diff --git a/api/v1/entries/execution.php b/api/v1/entries/execution.php index 4134a3c3d3..ce54d2ebb5 100644 --- a/api/v1/entries/execution.php +++ b/api/v1/entries/execution.php @@ -33,6 +33,10 @@ class executionEntry extends Entry } $execution = $this->format($data->data->execution, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,begin:date,end:date,realBegan:date,realEnd:date,deleted:bool'); + + $this->app->loadConfig('testcase'); + $execution->caseReview = ($config->testcase->needReview or !empty($config->testcase->forceReview)); + if(!$fields) $this->send(200, $execution); /* Set other fields. */ diff --git a/api/v1/entries/executioncases.php b/api/v1/entries/executioncases.php new file mode 100644 index 0000000000..f0431fb2a6 --- /dev/null +++ b/api/v1/entries/executioncases.php @@ -0,0 +1,49 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class executionCasesEntry extends entry +{ + /** + * GET method. + * + * @param int $executionID + * @access public + * @return void + */ + public function get($executionID = 0) + { + if(!$executionID) $executionID = $this->param('execution', 0); + if(empty($executionID)) return $this->sendError(400, 'Need execution id.'); + + $control = $this->loadController('execution', 'testcase'); + $control->testcase($executionID, $this->param('status', 'all'), $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); + + $data = $this->getData(); + + if(isset($data->status) and $data->status == 'success') + { + $cases = $data->data->cases; + $pager = $data->data->pager; + $result = array(); + foreach($cases as $case) + { + $case->status = array('code' => $case->status, 'name' => $this->lang->testcase->statusList[$case->status]); + $result[] = $this->format($case, 'openedDate:time,reviewedDate:date,lastEditedDate:time,lastRunDate:time'); + } + + return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'cases' => $result)); + } + + if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + + return $this->sendError(400, 'error'); + } +} diff --git a/config/routes.php b/config/routes.php index e782bf3b79..0a3d96dd15 100644 --- a/config/routes.php +++ b/config/routes.php @@ -83,9 +83,10 @@ $routes['/projects/:projectID/builds'] = 'builds'; $routes['/builds'] = 'builds'; $routes['/builds/:id'] = 'build'; -$routes['/products/:id/testcases'] = 'testcases'; -$routes['/testcases'] = 'testcases'; -$routes['/testcases/:id'] = 'testcase'; +$routes['/products/:id/testcases'] = 'testcases'; +$routes['/executions/:id/testcases'] = 'executioncases'; +$routes['/testcases'] = 'testcases'; +$routes['/testcases/:id'] = 'testcase'; $routes['/projects/:projectID/testtasks'] = 'testtasks'; $routes['/testtasks'] = 'testtasks'; diff --git a/module/testcase/model.php b/module/testcase/model.php index 6da824b03d..8c0123742b 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -302,12 +302,27 @@ class testcaseModel extends model * @param int $executionID * @param string $orderBy * @param object $pager - * @param string $browseType + * @param string $browseType all|wait|needconfirm * @access public * @return array */ public function getExecutionCases($executionID, $orderBy = 'id_desc', $pager = null, $browseType = '') { + if($browseType == 'needconfirm') + { + return $this->dao->select('distinct t1.*, t2.*')->from(TABLE_PROJECTCASE)->alias('t1') + ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') + ->leftJoin(TABLE_STORY)->alias('t3')->on('t1.story = t3.id') + ->where('t1.project')->eq((int)$executionID) + ->beginIF($browseType != 'all')->andWhere('t2.status')->eq($browseType)->fi() + ->andWhere('t2.deleted')->eq('0') + ->andWhere('t3.version > t2.storyVersion') + ->andWhere("t3.status")->eq('active') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + } + return $this->dao->select('distinct t1.*, t2.*')->from(TABLE_PROJECTCASE)->alias('t1') ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case=t2.id') ->where('t1.project')->eq((int)$executionID) @@ -1701,6 +1716,13 @@ class testcaseModel extends model return false; } + /** + * Summary cases + * + * @param array $cases + * @access public + * @return string + */ public function summary($cases) { $executed = 0;