From 5397c980d2f9268cfcfc1e6c11cd7403684fc944 Mon Sep 17 00:00:00 2001 From: daitingting Date: Wed, 27 Dec 2023 03:27:01 +0000 Subject: [PATCH] * Test getByID function. --- module/zahost/test/model/getbyid.php | 32 ++++++++++++++++++++++++++++ module/zahost/test/zahost.class.php | 25 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 module/zahost/test/model/getbyid.php create mode 100644 module/zahost/test/zahost.class.php diff --git a/module/zahost/test/model/getbyid.php b/module/zahost/test/model/getbyid.php new file mode 100755 index 0000000000..9313c05be0 --- /dev/null +++ b/module/zahost/test/model/getbyid.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +getByID(); +timeout=0 +cid=1 + +- 查询 ID 为 1 的主机 + - 属性id @1 + - 属性name @宿主机1 + - 属性type @zahost +- 查询 ID 为 2 不存在的主机 @0 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/zahost.class.php'; +su('admin'); + +$host = zdTable('host'); +$host->type->range('zahost'); +$host->name->range('宿主机1'); +$host->gen(1); + +$zahost = new zahostTest(); + +$hostIDList = array('1', '2'); + +r($zahost->getByIDTest($hostIDList[0])) && p('id,name,type') && e('1,宿主机1,zahost'); //查询 ID 为 1 的主机 +r($zahost->getByIDTest($hostIDList[1])) && p('') && e('0'); //查询 ID 为 2 不存在的主机 diff --git a/module/zahost/test/zahost.class.php b/module/zahost/test/zahost.class.php new file mode 100644 index 0000000000..b137879741 --- /dev/null +++ b/module/zahost/test/zahost.class.php @@ -0,0 +1,25 @@ +objectModel = $tester->loadModel('zahost'); + } + + /** + * 测试根据编号获取主机信息。 + * Get by id test. + * + * @param int $zahostID + * @access public + * @return array|object + */ + public function getByIDTest(int $zahostID): array|object + { + $zahost = $this->objectModel->getByID($zahostID); + if(dao::isError()) return dao::getError(); + return $zahost; + } +}