diff --git a/api/v1/entries/testcase.php b/api/v1/entries/testcase.php new file mode 100644 index 0000000000..7d0a7e8f42 --- /dev/null +++ b/api/v1/entries/testcase.php @@ -0,0 +1,33 @@ +loadController('testcase', 'view'); + $control->view($testcaseID, $this->param('version', 0)); + + $data = $this->getData(); + if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(!isset($data->case)) $this->sendError(400, 'error'); + + $this->send(200, $this->format($data->case, 'openedDate:time,lastEditedDate:time,lastRunDate:time')); + } + + public function delete($testcaseID) + { + $control = $this->loadController('testcase', 'delete'); + $control->delete($testcaseID, 'yes'); + + $this->getData(); + + $this->sendSuccess(200, 'success'); + } +} diff --git a/api/v1/entries/testcases.php b/api/v1/entries/testcases.php new file mode 100644 index 0000000000..9078ab60c6 --- /dev/null +++ b/api/v1/entries/testcases.php @@ -0,0 +1,26 @@ +app->loadClass('pager', $static = true); + $pager = pager::init($this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); + + $testcases = $this->loadModel('testcase')->getByStatus($this->param('productID', 0), $this->param('branch', ''), $this->param('type', 'all'), $this->param('status', 'all'), $this->param('moduleID', 0), $this->param('order', 'id_desc'), $pager, $this->param('auto', 'no')); + + $result = array(); + foreach($testcases as $testcase) + { + $result[] = $this->format($testcase, 'openedDate:time,lastEditedDate:time,lastRunDate:time'); + } + + return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testcases' => $result)); + } +} diff --git a/config/routes.php b/config/routes.php index 99b2d4f67c..ac08ee509d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -50,6 +50,9 @@ $routes['/issues/:issueID'] = 'issue'; $routes['/todos'] = 'todos'; $routes['/todos/:id'] = 'todo'; +$routes['/testcases'] = 'testcases'; +$routes['/testcases/:id'] = 'testcase'; + $routes['/projects/:projectID/testtasks'] = 'testtasks'; $routes['/testtasks'] = 'testtasks'; $routes['/testtasks/:id'] = 'testtask'; diff --git a/module/testcase/control.php b/module/testcase/control.php index 19eb265941..b6cd44016e 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -600,7 +600,11 @@ class testcase extends control { $caseID = (int)$caseID; $case = $this->testcase->getById($caseID, $version); - if(!$case) die(js::error($this->lang->notFound) . js::locate('back')); + if(!$case) + { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'message' => '404 Not found')); + die(js::error($this->lang->notFound) . js::locate('back')); + } if($case->auto == 'unit') { $this->lang->testcase->subMenu->testcase->feature['alias'] = ''; @@ -681,6 +685,7 @@ class testcase extends control $this->view->isLibCase = $isLibCase; $this->view->caseFails = $caseFails; + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'case' => $case)); $this->display(); } @@ -1017,6 +1022,7 @@ class testcase extends control } $locateLink = $this->session->caseList ? $this->session->caseList : inlink('browse', "productID={$case->product}"); + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success')); die(js::locate($locateLink, 'parent')); } } diff --git a/module/testcase/model.php b/module/testcase/model.php index 18132e884b..c21a664a2c 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -571,6 +571,39 @@ class testcaseModel extends model ->orderBy($orderBy)->page($pager)->fetchAll(); } + /** + * Get cases by type + * + * @param int $productID + * @param int $branch + * @param string $type all|needconfirm + * @param string $status all|normal|blocked|investigate + * @param int $moduleID + * @param string $orderBy + * @param object $pager + * @param string $auto no|unit|skip + * @access public + * @return array + */ + public function getByStatus($productID = 0, $branch, $type = 'all', $status = 'all', $moduleID, $orderBy = 'id_desc', $pager, $auto = 'no') + { + $modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0'; + + $cases = $this->dao->select('t1.*, t2.title as storyTitlen')->from(TABLE_CASE)->alias('t1') + ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') + ->beginIF($productID)->where('t1.product')->eq((int) $productID)->fi() + ->beginIF($productID == 0)->where('t1.product')->in($this->app->user->view->products)->fi() + ->beginIF($branch)->andWhere('t1.branch')->eq($branch)->fi() + ->beginIF($modules)->andWhere('t1.module')->in($modules)->fi() + ->beginIF($type == 'needconfirm')->andWhere("t2.status = 'active'")->andWhere('t2.version > t1.storyVersion')->fi() + ->beginIF($status != 'all')->andWhere('t1.status')->eq($status)->fi() + ->beginIF($auto == 'unit')->andWhere('t1.auto')->eq('unit')->fi() + ->beginIF($auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() + ->andWhere('t1.deleted')->eq('0') + ->orderBy($orderBy)->page($pager)->fetchAll('id'); + return $this->appendData($cases); + } + /** * Get cases of a story. *