* Optimize api publishLib function and finish unit test script.
This commit is contained in:
+11
-9
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The model file of api module of ZenTaoCMS.
|
||||
*
|
||||
@@ -28,17 +29,18 @@ class apiModel extends model
|
||||
const PARAMS_TYPE_CUSTOM = 'custom';
|
||||
|
||||
/**
|
||||
* 发布接口。
|
||||
* Create release.
|
||||
*
|
||||
* @param object $data
|
||||
* @param object $formData
|
||||
* @access public
|
||||
* @return int
|
||||
* @return bool
|
||||
*/
|
||||
public function publishLib($data)
|
||||
public function publishLib(object $formData): bool
|
||||
{
|
||||
/* Get lib modules list. */
|
||||
$modules = $this->dao->select('*')->from(TABLE_MODULE)
|
||||
->where('root')->eq((int)$data->lib)
|
||||
->where('root')->eq((int)$formData->lib)
|
||||
->andWhere('type')->eq('api')
|
||||
->andWhere('deleted')->eq(0)
|
||||
->orderBy('grade desc, `order`')
|
||||
@@ -46,25 +48,25 @@ class apiModel extends model
|
||||
|
||||
/* Get all api list. */
|
||||
$apis = $this->dao->select('id,version')->from(TABLE_API)
|
||||
->where('lib')->eq($data->lib)
|
||||
->where('lib')->eq($formData->lib)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->fetchAll();
|
||||
|
||||
/* Get all struct list. */
|
||||
$structs = $this->dao->select('id,version')->from(TABLE_APISTRUCT)
|
||||
->where('lib')->eq($data->lib)
|
||||
->where('lib')->eq($formData->lib)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->fetchAll();
|
||||
|
||||
$snap = array('modules' => $modules, 'apis' => $apis, 'structs' => $structs);
|
||||
|
||||
$data->snap = json_encode($snap);
|
||||
$this->dao->insert(TABLE_API_LIB_RELEASE)->data($data)
|
||||
$formData->snap = json_encode($snap);
|
||||
$this->dao->insert(TABLE_API_LIB_RELEASE)->data($formData)
|
||||
->autoCheck()
|
||||
->batchCheck($this->config->api->createrelease->requiredFields, 'notempty')
|
||||
->exec();
|
||||
|
||||
return dao::isError() ? false : $this->dao->lastInsertID();
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,33 +4,35 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/api.class.php';
|
||||
su('admin');
|
||||
|
||||
zdTable('doclib')->config('doclib')->gen(10);
|
||||
zdTable('module')->config('module')->gen(10);
|
||||
zdTable('api')->gen(10);
|
||||
zdTable('apistruct')->gen(10);
|
||||
zdTable('api_lib_release')->gen(0);
|
||||
zdTable('apispec')->gen(0);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 apiModel->publishLib();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
没有版本名的发布 >> 『版本』不能为空。
|
||||
正常的发布 >> Version1
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$api = new apiTest();
|
||||
$tester->loadModel('api');
|
||||
|
||||
$emptyBuildRelease = new stdclass();
|
||||
$emptyBuildRelease->version = '';
|
||||
$emptyBuildRelease->desc = '';
|
||||
$emptyBuildRelease->lib = 910;
|
||||
$emptyBuildRelease->addedBy = $tester->app->user->account;
|
||||
$emptyBuildRelease->addedDate = helper::now();
|
||||
$formData = new stdclass();
|
||||
$formData->lib = '1';
|
||||
$formData->version = 'version1.0';
|
||||
$formData->desc = '我是描述';
|
||||
|
||||
$normalRelease = new stdclass();
|
||||
$normalRelease->version = 'Version1';
|
||||
$normalRelease->desc = '';
|
||||
$normalRelease->lib = 910;
|
||||
$normalRelease->addedBy = $tester->app->user->account;
|
||||
$normalRelease->addedDate = helper::now();
|
||||
r($tester->api->publishLib($formData)) && p() && e(1); // 测试所属模块为空。
|
||||
|
||||
r($api->publishLibTest($emptyBuildRelease)) && p('version:0') && e('『版本号』不能为空。'); //没有版本名的发布
|
||||
r($api->publishLibTest($normalRelease)) && p('version') && e('Version1'); //正常的发布
|
||||
$formData = new stdclass();
|
||||
$formData->lib = '1';
|
||||
$formData->version = '';
|
||||
$formData->desc = '我是描述';
|
||||
|
||||
r($tester->api->publishLib($formData)) && p() && e(0); // 测试版本号为空。
|
||||
r(dao::getError()) && p('version:0') && e('『版本号』不能为空。'); // 测试版本号为空的提示信息。
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: zt_doclib
|
||||
author: Yuting Wang
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: type
|
||||
note: "文档类型"
|
||||
range: api
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: product
|
||||
note: "产品库"
|
||||
range: 0{10},1-100,
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: project
|
||||
note: "项目库"
|
||||
range: 0{10},1-100,
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: name
|
||||
note: "文档库名称"
|
||||
fields:
|
||||
- field: name1
|
||||
range: 文档库
|
||||
- field: name2
|
||||
range: 1-10000
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: zt_module
|
||||
author: Yuting Wang
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: type
|
||||
note: "对象类型"
|
||||
range: api
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
@@ -0,0 +1,60 @@
|
||||
title: table zt_api
|
||||
desc: "接口"
|
||||
author: automated export
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
note: "ID"
|
||||
range: 1-10000
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: lib
|
||||
note: "文档库ID"
|
||||
range: 1-100
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: title
|
||||
fields:
|
||||
- field: title1
|
||||
range: BUG接口{10}, 项目接口{10}, 产品接口{10}, 迭代接口{10},
|
||||
- field: title2
|
||||
range: 1-10000
|
||||
- field: path
|
||||
note: "接口路径"
|
||||
range: bug-getList{10},project-getList{10},product-getList{10},execution-getList{10}
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: protocol
|
||||
note: "请求协议"
|
||||
range: HTTP,HTTPS,WS,WSS
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: method
|
||||
note: "请求方式"
|
||||
range: GET,POST,PUT,DELETE,PATCH,OPTIONS,HEAD
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: status
|
||||
note: "开发状态"
|
||||
range: doing,done,hidden
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: version
|
||||
note: "版本"
|
||||
range: 1
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
@@ -0,0 +1,39 @@
|
||||
title: table zt_apistruct
|
||||
desc: "数据结构"
|
||||
author: automated export
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
note: "ID"
|
||||
range: 1-10000
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: lib
|
||||
note: "文档库ID"
|
||||
range: 1-100
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: name
|
||||
fields:
|
||||
- field: name1
|
||||
range: 数据接口,
|
||||
- field: name2
|
||||
range: 1-10000
|
||||
- field: type
|
||||
note: "接口类型"
|
||||
range: formData,json,array,object
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: version
|
||||
note: "版本"
|
||||
range: 1
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
Reference in New Issue
Block a user