From 804a673a6dc4ad7488bd5cf32ce77633a6ed9766 Mon Sep 17 00:00:00 2001 From: wangyuting Date: Fri, 1 Dec 2023 15:02:28 +0800 Subject: [PATCH] * Optimize api getStructByID function and finish unit test script. --- module/api/model.php | 6 ++-- module/api/test/model/getstructbyid.php | 33 +++++++++++-------- .../api/test/model/getstructlistbylibid.php | 12 ++++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/module/api/model.php b/module/api/model.php index 9a950f3e0b..9ef0475653 100644 --- a/module/api/model.php +++ b/module/api/model.php @@ -244,11 +244,11 @@ class apiModel extends model /** * Get a struct info. * - * @param int $id + * @param int $id * @access public - * @return object + * @return object|false */ - public function getStructByID($id) + public function getStructByID(int $id): object|false { $model = $this->dao->select('*') ->from(TABLE_APISTRUCT) diff --git a/module/api/test/model/getstructbyid.php b/module/api/test/model/getstructbyid.php index 446a9b9600..dc881aa144 100755 --- a/module/api/test/model/getstructbyid.php +++ b/module/api/test/model/getstructbyid.php @@ -1,29 +1,34 @@ #!/usr/bin/env php gen(10); + /** title=测试 apiModel->getStructByID(); +timeout=0 cid=1 -pid=1 -获取刚创建的数据结构 >> struct +- 获取数据结构ID为1的数据结构。 + - 属性id @1 + - 属性name @数据接口1 + - 属性type @formData +- 获取数据结构ID为2的数据结构。 + - 属性id @2 + - 属性name @数据接口2 + - 属性type @json +- 获取不存在的数据结构ID为22的数据结构。 + - 属性id @0 + - 属性name @0 + - 属性type @0 */ global $tester; -$api = new apiTest(); +$tester->loadModel('api'); -$normalStruct = new stdclass(); -$normalStruct->name = 'struct'; -$normalStruct->type = 'formData'; -$normalStruct->attribute = '[{"field":"field1","paramsType":"string","required":true,"desc":"desc","structType":"formData","sub":1,"key":"l2u5qy3jc1se6ghigll","children":[]}]'; -$normalStruct->desc = ''; -$normalStruct->addedBy = $tester->app->user->account; -$normalStruct->addedDate = helper::now(); - -$struct = $api->createStructTest($normalStruct, false); -r($api->getStructByIDTest($struct->id)) && p('name') && e('struct'); //获取刚创建的数据结构 \ No newline at end of file +r($tester->api->getStructByID(1)) && p('id,name,type') && e('1,数据接口1,formData'); //获取数据结构ID为1的数据结构。 +r($tester->api->getStructByID(2)) && p('id,name,type') && e('2,数据接口2,json'); //获取数据结构ID为2的数据结构。 +r($tester->api->getStructByID(22)) && p('id,name,type') && e('0,0,0'); //获取不存在的数据结构ID为22的数据结构。 diff --git a/module/api/test/model/getstructlistbylibid.php b/module/api/test/model/getstructlistbylibid.php index 25559d95e3..76fd7bb3e3 100755 --- a/module/api/test/model/getstructlistbylibid.php +++ b/module/api/test/model/getstructlistbylibid.php @@ -4,16 +4,26 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; su('admin'); zdTable('apistruct')->gen(10); + /** title=测试 apiModel->getStructListByLibID(); timeout=0 cid=1 +- 获取文档目录ID为1的数据结构列表。 + - 第0条的id属性 @1 + - 第0条的name属性 @数据接口1 + - 第0条的type属性 @formData +- 获取文档目录ID为2的数据结构列表。 + - 第0条的id属性 @2 + - 第0条的name属性 @数据接口2 + - 第0条的type属性 @json + */ global $tester; $tester->loadModel('api'); r($tester->api->getStructListByLibID(1)) && p('0:id,name,type') && e('1,数据接口1,formData'); //获取文档目录ID为1的数据结构列表。 -r($tester->api->getStructListByLibID(2)) && p('0:id,name,type') && e('2,数据接口2,formData'); //获取文档目录ID为2的数据结构列表。 +r($tester->api->getStructListByLibID(2)) && p('0:id,name,type') && e('2,数据接口2,json'); //获取文档目录ID为2的数据结构列表。