diff --git a/api/v1/entries/testcases.php b/api/v1/entries/testcases.php index e979bc4394..fef888623b 100644 --- a/api/v1/entries/testcases.php +++ b/api/v1/entries/testcases.php @@ -23,8 +23,17 @@ class testcasesEntry extends entry if(empty($productID)) $productID = $this->param('product', 0); if(empty($productID)) return $this->sendError(400, 'Need product id.'); + $type = 'all'; + $param = 0; + $moduleID = $this->param('module', 0); + if($moduleID) + { + $type = 'byModule'; + $param = $moduleID; + } + $control = $this->loadController('testcase', 'browse'); - $control->browse($productID, $this->param('branch', ''), $this->param('status', 'all'), 0, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); + $control->browse($productID, $this->param('branch', ''), $type, $param, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); $data = $this->getData(); diff --git a/api/v1/entries/testsuite.php b/api/v1/entries/testsuite.php new file mode 100644 index 0000000000..4ac05ec019 --- /dev/null +++ b/api/v1/entries/testsuite.php @@ -0,0 +1,58 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class testsuiteEntry extends entry +{ + /** + * GET method. + * + * @param int $testsuiteID + * @access public + * @return void + */ + public function get($testsuiteID) + { + $control = $this->loadController('testsuite', 'view'); + $control->view($testsuiteID, $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(zget($data, 'code', 400), $data->message); + if(!isset($data->data->suite)) $this->sendError(400, 'error'); + + $suite = $this->format($data->data->suite, 'addedBy:user,addedDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool'); + $suite->cases = array(); + + foreach($data->data->cases as $case) + { + $suite->cases[] = $this->format($case, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedBy:user,reviewedDate:date,deleted:bool'); + } + + $this->send(200, $suite); + } + + /** + * DELETE method. + * + * @param int $testsuiteID + * @access public + * @return void + */ + public function delete($testsuiteID) + { + $control = $this->loadController('testsuite', 'delete'); + $control->delete($testsuiteID, 'yes'); + + $this->getData(); + + $this->sendSuccess(200, 'success'); + } +} diff --git a/api/v1/entries/testsuites.php b/api/v1/entries/testsuites.php new file mode 100644 index 0000000000..53ff546a33 --- /dev/null +++ b/api/v1/entries/testsuites.php @@ -0,0 +1,79 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class testsuitesEntry extends entry +{ + /** + * GET method. + * + * @param int $productID + * @access public + * @return void + */ + public function get($productID = 0) + { + if(empty($productID)) $productID = $this->param('product', 0); + if(empty($productID)) return $this->sendError(400, 'Need product id.'); + + $control = $this->loadController('testsuite', 'browse'); + $control->browse($productID, $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') + { + $suites = $data->data->suites; + $pager = $data->data->pager; + $result = array(); + foreach($suites as $suite) + { + $result[] = $this->format($suite, 'addedBy:user,addedDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool'); + } + + return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testsuites' => $result)); + } + + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + return $this->sendError(400, 'error'); + } + + /** + * POST method. + * + * @param int $productID + * @access public + * @return void + */ + public function post($productID = 0) + { + if(!$productID) $productID = $this->param('product'); + if(!$productID and isset($this->requestBody->product)) $productID = $this->requestBody->product; + if(!$productID) return $this->sendError(400, 'Need product id.'); + + $fields = 'name,type'; + $this->batchSetPost($fields); + $this->setPost('product', $productID); + $this->setPost('desc', $this->request('desc', '')); + $this->setPost('type', $this->request('type', 'private')); + + $control = $this->loadController('testsuite', 'create'); + $this->requireFields('name'); + + $control->create($productID); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message); + + $suite = $this->loadModel('testsuite')->getByID($data->id); + + $this->send(200, $this->format($suite, 'addedBy:user,addedDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool')); + } +} diff --git a/config/routes.php b/config/routes.php index c47cd483aa..497482412f 100644 --- a/config/routes.php +++ b/config/routes.php @@ -98,6 +98,10 @@ $routes['/executions/:id/testcases'] = 'executionCases'; $routes['/testcases'] = 'testcases'; $routes['/testcases/:id'] = 'testcase'; +$routes['/products/:id/testsuites'] = 'testsuites'; +$routes['/testsuites'] = 'testsuites'; +$routes['/testsuites/:id'] = 'testsuite'; + $routes['/projects/:projectID/testtasks'] = 'testtasks'; $routes['/testtasks'] = 'testtasks'; $routes['/testtasks/:id'] = 'testtask'; diff --git a/module/bug/model.php b/module/bug/model.php index 0e0de27020..6c7e6cf9a9 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -83,7 +83,7 @@ class bugModel extends model /* Check repeat bug. */ $result = $this->loadModel('common')->removeDuplicate('bug', $bug, "product={$bug->product}"); - if($result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); + if($result and $result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); $bug = $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->create['id'], $this->post->uid);