From 9931ec474ac865ae32e145f119e7b5e182924a81 Mon Sep 17 00:00:00 2001 From: denghongtao Date: Mon, 9 May 2022 10:39:04 +0800 Subject: [PATCH] add webhook unittest --- test/class/webhook.class.php | 473 ++++++++++++++++++++++++ test/model/webhook/bind.php | 59 +++ test/model/webhook/builddata.php | 47 +++ test/model/webhook/create.php | 95 +++++ test/model/webhook/fetchhook.php | 49 +++ test/model/webhook/getbearychatdata.php | 56 +++ test/model/webhook/getbindaccount.php | 37 ++ test/model/webhook/getboundusers.php | 35 ++ test/model/webhook/getbyid.php | 36 ++ test/model/webhook/getbytype.php | 52 +++ test/model/webhook/getdatalist.php | 21 ++ test/model/webhook/getdingdingdata.php | 37 ++ test/model/webhook/getfeishudata.php | 34 ++ test/model/webhook/getlist.php | 34 ++ test/model/webhook/getloglist.php | 35 ++ test/model/webhook/getopenidlist.php | 30 ++ test/model/webhook/getviewlink.php | 37 ++ test/model/webhook/getweixindata.php | 41 ++ test/model/webhook/savedata.php | 45 +++ test/model/webhook/savelog.php | 19 + test/model/webhook/send.php | 78 ++++ test/model/webhook/setsentstatus.php | 19 + test/model/webhook/update.php | 92 +++++ 23 files changed, 1461 insertions(+) create mode 100644 test/class/webhook.class.php create mode 100755 test/model/webhook/bind.php create mode 100755 test/model/webhook/builddata.php create mode 100755 test/model/webhook/create.php create mode 100755 test/model/webhook/fetchhook.php create mode 100755 test/model/webhook/getbearychatdata.php create mode 100755 test/model/webhook/getbindaccount.php create mode 100755 test/model/webhook/getboundusers.php create mode 100755 test/model/webhook/getbyid.php create mode 100755 test/model/webhook/getbytype.php create mode 100755 test/model/webhook/getdatalist.php create mode 100755 test/model/webhook/getdingdingdata.php create mode 100755 test/model/webhook/getfeishudata.php create mode 100755 test/model/webhook/getlist.php create mode 100755 test/model/webhook/getloglist.php create mode 100755 test/model/webhook/getopenidlist.php create mode 100755 test/model/webhook/getviewlink.php create mode 100755 test/model/webhook/getweixindata.php create mode 100755 test/model/webhook/savedata.php create mode 100755 test/model/webhook/savelog.php create mode 100755 test/model/webhook/send.php create mode 100755 test/model/webhook/setsentstatus.php create mode 100755 test/model/webhook/update.php diff --git a/test/class/webhook.class.php b/test/class/webhook.class.php new file mode 100644 index 0000000000..b06a2700af --- /dev/null +++ b/test/class/webhook.class.php @@ -0,0 +1,473 @@ +objectModel = $tester->loadModel('webhook'); + } + + /** + * Get by ID Test + * + * @param int mixed $id + * @access public + * @return array + */ + public function getByIDTest($id) + { + $objects = $this->objectModel->getByID($id); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get by type Test + * + * @param string mixed $type + * @access public + * @return array + */ + public function getByTypeTest($type) + { + $objects = $this->objectModel->getByType($type); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get bind account Test + * + * @param int mixed $webhookID + * @param string mixed $webhookType + * @param int mixed $openID + * @access public + * @return string + */ + public function getBindAccountTest($webhookID, $webhookType, $openID) + { + $objects = $this->objectModel->getBindAccount($webhookID, $webhookType, $openID); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get list Test + * + * @param string $orderBy + * @param int mixed $pager + * @param bool mixed $decode + * @access public + * @return array + */ + public function getListTest($orderBy = 'id_desc', $pager = null, $decode = true) + { + $objects = $this->objectModel->getList($orderBy, $pager, $decode); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get log list Test + * + * @param int mixed $id + * @param string $orderBy + * @param int mixed $pager + * @access public + * @return array + */ + public function getLogListTest($id, $orderBy = 'date_desc', $pager = null) + { + $objects = $this->objectModel->getLogList($id, $orderBy, $pager); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get data list Test + * + * @access public + * @return array + */ + public function getDataListTest() + { + global $tester; + $objects = $this->objectModel->getDataList(); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get bound users Test + * + * @param int mixed $webhookID + * @param array $users + * @access public + * @return int + */ + public function getBoundUsersTest($webhookID, $users = array()) + { + $objects = $this->objectModel->getBoundUsers($webhookID, $users); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + public function createTest($webhooks) + { + $posts = array(); + $posts['type'] = ''; + $posts['name'] = ''; + $posts['url'] = ''; + $posts['secret'] = ''; + $posts['agentId'] = ''; + $posts['appKey'] = ''; + $posts['appSecret'] = ''; + $posts['wechatCorpId'] = ''; + $posts['wechatCorpSecret'] = ''; + $posts['wechatAgentId'] = ''; + $posts['feishuAppId'] = ''; + $posts['feishuAppSecret'] = ''; + $posts['domain'] = ''; + $posts['sendType'] = ''; + $posts['products'] = array(); + $posts['executions'] = array(); + $posts['desc'] = ''; + + foreach($posts as $field => $defaultvalue) $_POST[$field] = $defaultvalue; + foreach($webhooks as $key => $value) $_POST[$key] = $value; + + $objects = $this->objectModel->create(); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Update Test + * + * @param aray mixed $create + * @param int mixed $id + * @access public + * @return int + */ + public function updateTest($create, $update) + { + global $tester; + $webhook1 = $this->createTest($create); + $id = $tester->dao->select('id')->from(TABLE_WEBHOOK)->where('name')->eq($create['name'])->fetch('id'); + + if($id == null) + { + a($webhook); + return; + } + else{ + $post = array(); + $post['type'] = ''; + $post['name'] = ''; + $post['url'] = ''; + $post['secret'] = ''; + $post['domain'] = ''; + $post['products'] = array(); + $post['executions'] = array(); + $post['desc'] = ''; + foreach($post as $field => $defaultvalue) $_POST[$field] = $defaultvalue; + foreach($update as $key => $value) $_POST[$key] = $value; + + $objects = $this->objectModel->update($id); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + } + + /** + * Bind Test + * + * @param array mixed $create + * @param array mixed $bind + * @access public + * @return array + */ + public function bindTest($create, $bind) + { + global $tester; + $result = $this->createTest($create); + $id = $tester->dao->select('id')->from(TABLE_WEBHOOK)->where('name')->eq($create['name'])->fetch('id'); + + if($id == null) + { + a($result); + return; + }else + { + foreach($bind as $key => $value) $_POST[$key] = $value; + + $objects = $this->objectModel->bind($id); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + } + + /** + * Send Test + * + * @param string mixed $objectType + * @param int mixed $objectID + * @param string mixed $actionType + * @param int mixed $actionID + * @param string $actor + * @access public + * @return bool + */ + public function sendTest($objectType, $objectID, $actionType, $actionID, $actor = '') + { + $objects = $this->objectModel->send($objectType, $objectID, $actionType, $actionID, $actor); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Build data Test + * + * @param string mixed $objectType + * @param int mixed $objectID + * @param string mixed $actionType + * @param int mixed $actionID + * @access public + * @return bool + */ + public function buildDataTest($objectType, $objectID, $actionType, $actionID) + { + static $webhooks = array(); + if(!$webhooks) $webhooks = $this->getListTest(); + if(!$webhooks) return true; + + foreach($webhooks as $id => $webhook) + { + $objects = $this->objectModel->buildData($objectType, $objectID, $actionType, $actionID, $webhook); + } + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get view link Test + * + * @param string mixed $objectType + * @param int mixed $objectID + * @access public + * @return string + */ + public function getViewLinkTest($objectType, $objectID) + { + $objects = $this->objectModel->getViewLink($objectType, $objectID); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get dingding data Test + * + * @param string mixed $title + * @param string mixed $text + * @param string mixed $mobile + * @access public + * @return array + */ + public function getDingdingDataTest($title, $text, $mobile) + { + $objects = $this->objectModel->getDingdingData($title, $text, $mobile); + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get bearychat data Test + * + * @param string mixed $text + * @param string mixed $mobile + * @param string mixed $email + * @param string mixed $objectType + * @param int mixed $objectID + * @access public + * @return array + */ + public function getBearychatDataTest($text, $mobile, $email, $objectType, $objectID) + { + $objects = $this->objectModel->getBearychatData($text, $mobile, $email, $objectType, $objectID); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get weixin data Test + * + * @param string mixed $title + * @param string mixed $text + * @param string mixed $mobile + * @access public + * @return array + */ + public function getWeixinDataTest($title, $text, $mobile) + { + $objects = $this->objectModel->getWeixinData($title, $text, $mobile); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get feishu data Test + * + * @param string mixed $title + * @param string mixed $text + * @access public + * @return array + */ + public function getFeishuDataTest($title, $text) + { + $objects = $this->objectModel->getFeishuData($title, $text); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Get open id list Test + * + * @param int mixed $actionID + * @access public + * @return void + */ + public function getOpenIdListTest($webhookID, $actionID) + { + static $webhooks = array(); + if(!$webhooks) $webhooks = $this->getListTest(); + if(!$webhooks) return true; + + foreach($webhooks as $id => $webhook) + { + $objects = $this->objectModel->getOpenIdList($webhook->id, $actionID); + } + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Fetch hook Test + * + * @param object mixed $webhook + * @param object mixed $sendData + * @param int $actionID + * @access public + * @return int + */ + public function fetchHookTest($objectType, $objectID, $actionType, $actionID = 0) + { + static $webhooks = array(); + if(!$webhooks) $webhooks = $this->getListTest(); + if(!$webhooks) return true; + + foreach($webhooks as $id => $webhook) + { + $postData = $this->objectModel->buildData($objectType, $objectID, $actionType, $actionID, $webhook); + $objects = $this->objectModel->fetchHook($webhook, $postData, $actionID); + } + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Save data Test + * + * @param int mixed $webhookID + * @param int mixed $actionID + * @param string mixed $data + * @param string $actor + * @access public + * @return void + */ + public function saveDataTest($objectType, $objectID, $actionType, $webhookID, $actionID, $actor = '') + { + static $webhooks = array(); + if(!$webhooks) $webhooks = $this->getListTest(); + if(!$webhooks) return true; + + foreach($webhooks as $id => $webhook) + { + $postData = $this->objectModel->buildData($objectType, $objectID, $actionType, $actionID, $webhook); + $objects = $this->objectModel->saveData($webhookID, $actionID, $postData, $actor); + } + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Save log Test + * + * @param object mixed $webhook + * @param int mixed $actionID + * @param string mixed $data + * @param string mixed $result + * @access public + * @return void + */ + public function saveLogTest($webhook, $actionID, $data, $result) + { + $objects = $this->objectModel->saveLog($webhook, $actionID, $data, $result); + + if(dao::isError()) return dao::getError(); + + return $objects; + } + + /** + * Set sent status Test + * + * @param array mixed $idList + * @param string mixed $status + * @param string $time + * @access public + * @return void + */ + public function setSentStatusTest($idList, $status, $time = '') + { + $objects = $this->objectModel->setSentStatus($idList, $status, $time); + + if(dao::isError()) return dao::getError(); + + return $objects; + } +} diff --git a/test/model/webhook/bind.php b/test/model/webhook/bind.php new file mode 100755 index 0000000000..b06c306757 --- /dev/null +++ b/test/model/webhook/bind.php @@ -0,0 +1,59 @@ +#!/usr/bin/env php +bind(); +cid=1 +pid=1 + +绑定admin账号给飞书账号的白袁李(创建了测试用户飞书管理端,然后通过create方法创建了一条数据,关联飞书里的一个用户,页面验证成功绑定) >> 1 + +*/ + +$webhook = new webhookTest(); + +$post = array(); +$post['type'] = 'feishuuser'; +$post['name'] = '测试绑定的webhook'; +$post['url'] = ''; +$post['secret'] = ''; +$post['agentId'] = ''; +$post['appKey'] = ''; +$post['appSecret'] = ''; +$post['wechatCorpId'] = ''; +$post['wechatCorpSecret'] = ''; +$post['wechatAgentId'] = ''; +$post['feishuAppId'] = 'cli_a2e1f12e6d785013'; +$post['feishuAppSecret'] = 'Pk4rYTwtFJveepj4JDfPCciSgUqBJYM5'; +$post['domain'] = 'http://www.zentaopms.com'; +$post['sendType'] = 'sync'; +$post['products'] = array('0' => 93); +$post['executions'] = array('0' => 690); +$post['desc'] = '当你老了~~~'; + +$bind = array(); +$bind['userid'] = array(); +$bind['userid']['admin'] = 'ou_584a4988c0cf7aa997ccd71b57d740ab'; +$bind['userid']['program1whitelist'] = ''; +$bind['userid']['program1whitelist'] = ''; +$bind['userid']['user3'] = ''; +$bind['userid']['user4'] = ''; +$bind['userid']['user5'] = ''; +$bind['userid']['user6'] = ''; +$bind['userid']['user7'] = ''; +$bind['userid']['user8'] = ''; +$bind['userid']['user9'] = ''; +$bind['userid']['user10'] = ''; +$bind['userid']['user11'] = ''; +$bind['userid']['user12'] = ''; +$bind['userid']['user13'] = ''; +$bind['userid']['user14'] = ''; + +$result1 = $webhook->bindTest($post, $bind); + +r($result1) && p() && e('1'); //绑定admin账号给飞书账号的白袁李(创建了测试用户飞书管理端,然后通过create方法创建了一条数据,关联飞书里的一个用户,页面验证成功绑定) +system("./ztest init"); \ No newline at end of file diff --git a/test/model/webhook/builddata.php b/test/model/webhook/builddata.php new file mode 100755 index 0000000000..d3a1dd3f00 --- /dev/null +++ b/test/model/webhook/builddata.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php +buildData(); +cid=1 +pid=1 + +正常传入的情况 >> http.\/builddata.php?m=product&f=view&id=1 +不传objectType >> 0 +不传objectID >> 0 +不传actionType >> 0 +不传actionID >> admin\u521b\u5efa\u4ea7\u54c1 + +*/ + +$webhook = new webhookTest(); + +$objectType = array(); +$objectType[0] = 'release'; +$objectType[1] = ''; + +$objectID = array(); +$objectID[0] = 1; +$objectID[1] = ''; + +$actionType = array(); +$actionType[0] = 'created'; +$actionType[1] = ''; + +$actionID = array(); +$actionID[0] = 1; +$actionID[1] = ''; + +$result1 = $webhook->buildDataTest($objectType[0], $objectID[0], $actionType[0], $actionID[0]); +$result2 = $webhook->buildDataTest($objectType[1], $objectID[0], $actionType[0], $actionID[0]); +$result4 = $webhook->buildDataTest($objectType[0], $objectID[0], $actionType[1], $actionID[0]); +$result5 = $webhook->buildDataTest($objectType[0], $objectID[0], $actionType[0], $actionID[1]); + +r($result1) && p() && e('"msgtype":"markdown","markdown"'); //正常传入的情况 +r($result2) && p() && e('0'); //不传objectType +r($result4) && p() && e('0'); //不传actionType +r($result5) && p() && e('admin\u521b\u5efa\u4ea7\u54c1'); //不传actionID diff --git a/test/model/webhook/create.php b/test/model/webhook/create.php new file mode 100755 index 0000000000..d3d34275c1 --- /dev/null +++ b/test/model/webhook/create.php @@ -0,0 +1,95 @@ +#!/usr/bin/env php +create(); +cid=1 +pid=1 + +测试全部传入的正常创建 >> 8 +测试不传type的情况 >> 9 +测试不传name的情况 >> 『名称』不能为空。 +测试不传url的情况 >> 『Hook地址』不能为空。 +测试不传secret的情况 >> 10 +测试不传domain的情况 >> 11 +测试不传sendType的情况 >> 『发送方式』不符合格式,应当为:『/sync|async/』。 +测试不传products的情况 >> 12 +测试不传executions的情况 >> 13 +测试不传desc的情况 >> 14 + +*/ + +$webhook = new webhookTest(); + +$post = array(); +$post['type'] = 'dinggroup'; +$post['name'] = '新加的webhook'; +$post['url'] = 'https://open.feishu.cn/open-apis/bot/v2/hook/173bdc6e-6f37-476d-8134-fd25752f00f3'; +$post['secret'] = 'cs0iInSMVWAqhPPL8BcVjf'; +$post['agentId'] = ''; +$post['appKey'] = ''; +$post['appSecret'] = ''; +$post['wechatCorpId'] = ''; +$post['wechatCorpSecret'] = ''; +$post['wechatAgentId'] = ''; +$post['feishuAppId'] = ''; +$post['feishuAppSecret'] = ''; +$post['domain'] = 'http://www.zentaopms.com'; +$post['sendType'] = 'sync'; +$post['products'] = array('0' => 100); +$post['executions'] = array('0' => 700); +$post['desc'] = '当你老了~~~'; + +$post1 = $post; +$post1['type'] = ''; + +$post2 = $post; +$post2['name'] = ''; + +$post3 = $post; +$post3['url'] = ''; + +$post4 = $post; +$post4['secret'] = ''; + +$post5 = $post; +$post5['domain'] = ''; + +$post6 = $post; +$post6['sendType'] = ''; + +$post7 = $post; +$post7['products'] = ''; + +$post8 = $post; +$post8['executions'] = ''; + +$post9 = $post; +$post9['desc'] = ''; + +$result1 = $webhook->createTest($post); +$result2 = $webhook->createTest($post1); +$result3 = $webhook->createTest($post2); +$result4 = $webhook->createTest($post3); +$result5 = $webhook->createTest($post4); +$result6 = $webhook->createTest($post5); +$result7 = $webhook->createTest($post6); +$result8 = $webhook->createTest($post7); +$result9 = $webhook->createTest($post8); +$result10 = $webhook->createTest($post9); + +r($result1) && p() && e('8'); //测试全部传入的正常创建 +r($result2) && p() && e('9'); //测试不传type的情况 +r($result3) && p('name:0') && e('『名称』不能为空。'); //测试不传name的情况 +r($result4) && p('url:0') && e('『Hook地址』不能为空。'); //测试不传url的情况 +r($result5) && p() && e('10'); //测试不传secret的情况 +r($result6) && p() && e('11'); //测试不传domain的情况 +r($result7) && p('sendType:0') && e('『发送方式』不符合格式,应当为:『/sync|async/』。'); //测试不传sendType的情况 +r($result8) && p() && e('12'); //测试不传products的情况 +r($result9) && p() && e('13'); //测试不传executions的情况 +R($result10) && p() && e('14'); //测试不传desc的情况 +system("./ztest init"); \ No newline at end of file diff --git a/test/model/webhook/fetchhook.php b/test/model/webhook/fetchhook.php new file mode 100755 index 0000000000..2f81b8997d --- /dev/null +++ b/test/model/webhook/fetchhook.php @@ -0,0 +1,49 @@ +#!/usr/bin/env php +fetchHook(); +cid=1 +pid=1 + +传入正确参数 >> Could not resolve host: oapi.dinggroup.com; Unknown error +不传入objectType >> Could not resolve host: oapi.dinggroup.com; Unknown error +不传入objectID >> Could not resolve host: oapi.dinggroup.com; Unknown error +不传入actionType >> Could not resolve host: oapi.dinggroup.com; Unknown error +不传入actionID >> Could not resolve host: oapi.dinggroup.com; Unknown error + +*/ + +$webhook = new webhookTest(); + +$objectType = array(); +$objectType[0] = 'product'; +$objectType[1] = ''; + +$objectID = array(); +$objectID[0] = '1'; +$objectID[1] = ''; + +$actionType = array(); +$actionType[0] = 'created'; +$actionType[1] = ''; + +$actionID = array(); +$actionID[0] = '4'; +$actionID[1] = ''; + +$result1 = $webhook->fetchHookTest($objectType[0], $objectID[0], $actionType[0], $actionID[0]); +$result2 = $webhook->fetchHookTest($objectType[1], $objectID[0], $actionType[0], $actionID[0]); +$result3 = $webhook->fetchHookTest($objectType[0], $objectID[1], $actionType[0], $actionID[0]); +$result4 = $webhook->fetchHookTest($objectType[0], $objectID[0], $actionType[1], $actionID[0]); +$result5 = $webhook->fetchHookTest($objectType[0], $objectID[0], $actionType[0], $actionID[1]); + +r($webhook->fetchHookTest($result1)) && p() && e('Could not resolve host: oapi.dinggroup.com; Unknown error'); //传入正确参数 +r($webhook->fetchHookTest($result2)) && p() && e('Could not resolve host: oapi.dinggroup.com; Unknown error'); //不传入objectType +r($webhook->fetchHookTest($result3)) && p() && e('Could not resolve host: oapi.dinggroup.com; Unknown error'); //不传入objectID +r($webhook->fetchHookTest($result4)) && p() && e('Could not resolve host: oapi.dinggroup.com; Unknown error'); //不传入actionType +r($webhook->fetchHookTest($result5)) && p() && e('Could not resolve host: oapi.dinggroup.com; Unknown error'); //不传入actionID \ No newline at end of file diff --git a/test/model/webhook/getbearychatdata.php b/test/model/webhook/getbearychatdata.php new file mode 100755 index 0000000000..15f2312c26 --- /dev/null +++ b/test/model/webhook/getbearychatdata.php @@ -0,0 +1,56 @@ +#!/usr/bin/env php +getBearychatData(); +cid=1 +pid=1 + +测试传入正确数据 >> true +测试不传text >> true +测试不传mobile >> true +测试不传email >> true +测试不传objectType >> true +测试不传objectID >> true + +*/ + +$webhook = new webhookTest(); + +$text = array(); +$text[0] = 'denghongtao'; +$text[1] = ''; + +$mobile = array(); +$mobile[0] = '12345'; +$mobile[1] = ''; + +$email = array(); +$email[0] = '123456@outlook.com'; +$email[1] = ''; + +$objectType = array(); +$objectType[0] = 'product'; +$objectType[1] = ''; + +$objectID = array(); +$objectID[0] = '1'; +$objectID[1] = ''; + +$result1 = $webhook->getBearychatDataTest($text[0], $mobile[0], $email[0], $objectType[0], $objectID[0]); +$result2 = $webhook->getBearychatDataTest($text[1], $mobile[0], $email[0], $objectType[0], $objectID[0]); +$result3 = $webhook->getBearychatDataTest($text[0], $mobile[1], $email[0], $objectType[0], $objectID[0]); +$result4 = $webhook->getBearychatDataTest($text[0], $mobile[0], $email[1], $objectType[0], $objectID[0]); +$result5 = $webhook->getBearychatDataTest($text[0], $mobile[0], $email[0], $objectType[1], $objectID[0]); +$result6 = $webhook->getBearychatDataTest($text[0], $mobile[0], $email[0], $objectType[0], $objectID[1]); + +r($result1) && p('markdown') && e('true'); //测试传入正确数据 +r($result2) && p('markdown') && e('true'); //测试不传text +r($result3) && p('markdown') && e('true'); //测试不传mobile +r($result4) && p('markdown') && e('true'); //测试不传email +r($result5) && p('markdown') && e('true'); //测试不传objectType +r($result6) && p('markdown') && e('true'); //测试不传objectID \ No newline at end of file diff --git a/test/model/webhook/getbindaccount.php b/test/model/webhook/getbindaccount.php new file mode 100755 index 0000000000..1951b9e0d7 --- /dev/null +++ b/test/model/webhook/getbindaccount.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +getBindAccount(); +cid=1 +pid=1 + +按条件查出id=1的关联用户 >> user3 +按条件查出id=空时,关联的用户 >> 0 + +*/ + +$webhook = new webhookTest(); + +$ID = array(); +$ID[0] = 1; +$ID[1] = 2; +$ID[2] = ''; + +$type = array(); +$type[0] = 'gitlab'; +$type[1] = ''; + +$openID = array(); +$openID[0] = 1; +$openID[1] = ''; + +$result1 = $webhook->getBindAccountTest($ID[0], $type[0], $openID[0]); +$result2 = $webhook->getBindAccountTest($ID[1], $type[1], $openID[1]); + +r($result1) && p() && e('user3'); //按条件查出id=1的关联用户 +r($result2) && p() && e('0'); //按条件查出id=空时,关联的用户 \ No newline at end of file diff --git a/test/model/webhook/getboundusers.php b/test/model/webhook/getboundusers.php new file mode 100755 index 0000000000..5f9f199c95 --- /dev/null +++ b/test/model/webhook/getboundusers.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php +getBoundUsers(); +cid=1 +pid=1 + +统计匹配数量 >> 1 +取出其中一个用户 >> 2 +传入不存在的情况 >> 0 +传入空时 >> 0 + +*/ + +$webhook = new webhookTest(); + +$ID = array(); +$ID[0] = 1; +$ID[1] = 1111; +$ID[2] = ''; + +$user = array(); +$user[0] = array('user3', 'user4'); +$user[1] = 'user3, user1111'; +$user[2] = ''; + +r(count($webhook->getBoundUsersTest($ID[0], $user[0]))) && p() && e('1'); //统计匹配数量 +r($webhook->getBoundUsersTest($ID[0], $user[0])) && p('user4') && e('2'); //取出其中一个用户 +r(count($webhook->getBoundUsersTest($ID[1], $user[1]))) && p() && e('0'); //传入不存在的情况 +r(count($webhook->getBoundUsersTest($ID[2], $user[2]))) && p() && e('0'); //传入空时 \ No newline at end of file diff --git a/test/model/webhook/getbyid.php b/test/model/webhook/getbyid.php new file mode 100755 index 0000000000..6bbca40816 --- /dev/null +++ b/test/model/webhook/getbyid.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +getByID(); +cid=1 +pid=1 + +通过ID查创建人 >> admin +通过ID查名字 >> 钉钉群机器人 +查ID为2的创建人 >> admin +查ID为2的名字 >> 钉钉工作消息 +传入不存在的情况 >> 0 + +*/ + +$webhook = new webhookTest(); + +$ID = array(); +$ID[0] = 1; +$ID[1] = 2; +$ID[2] = 1111; + +$result1 = $webhook->getByIDTest($ID[0]); +$result2 = $webhook->getByIDTest($ID[1]); +$result3 = $webhook->getByIDTest($ID[2]); + +r($result1) && p('createdBy') && e('admin'); //通过ID查创建人 +r($result1) && p('name') && e('钉钉群机器人'); //通过ID查名字 +r($result2) && p('createdBy') && e('admin'); //查ID为2的创建人 +r($result2) && p('name') && e('钉钉工作消息'); //查ID为2的名字 +r($result3) && p('') && e('0'); //传入不存在的情况 \ No newline at end of file diff --git a/test/model/webhook/getbytype.php b/test/model/webhook/getbytype.php new file mode 100755 index 0000000000..563bd8b71c --- /dev/null +++ b/test/model/webhook/getbytype.php @@ -0,0 +1,52 @@ +#!/usr/bin/env php +getByType(); +cid=1 +pid=1 + +通过type为dinggroup查id >> 1 +通过type为dinguser查id >> 2 +通过type为wechatgroup查id >> 3 +通过type为wechatuser查id >> 4 +通过type为feishugroup查id >> 5 +通过type为feishuuser查id >> 6 +通过type为default查id >> 7 +传入空的情况 >> 0 + +*/ + +$webhook = new webhookTest(); + +$type = array(); +$type[0] = 'dinggroup'; +$type[1] = 'dinguser'; +$type[2] = 'wechatgroup'; +$type[3] = 'wechatuser'; +$type[4] = 'feishugroup'; +$type[5] = 'feishuuser'; +$type[6] = 'default'; +$type[7] = ''; + +$result1 = $webhook->getByTypeTest($type[0]); +$result2 = $webhook->getbyTypetest($type[1]); +$result3 = $webhook->getbyTypetest($type[2]); +$result4 = $webhook->getbyTypetest($type[3]); +$result5 = $webhook->getbyTypetest($type[4]); +$result6 = $webhook->getbyTypetest($type[5]); +$result7 = $webhook->getbyTypetest($type[6]); +$result8 = $webhook->getbyTypetest($type[7]); + +r($result1) && p('id') && e('1'); //通过type为dinggroup查id +r($result2) && p('id') && e('2'); //通过type为dinguser查id +r($result3) && p('id') && e('3'); //通过type为wechatgroup查id +r($result4) && p('id') && e('4'); //通过type为wechatuser查id +r($result5) && p('id') && e('5'); //通过type为feishugroup查id +r($result6) && p('id') && e('6'); //通过type为feishuuser查id +r($result7) && p('id') && e('7'); //通过type为default查id +r($result8) && p('id') && e('0'); //传入空的情况 \ No newline at end of file diff --git a/test/model/webhook/getdatalist.php b/test/model/webhook/getdatalist.php new file mode 100755 index 0000000000..358ae1d240 --- /dev/null +++ b/test/model/webhook/getdatalist.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +getDataList(); +cid=1 +pid=1 + +不需传任何参数,取出其中一个ID=39的日志内容,这里时间上取当前时间三小时以前的 >> 用户创建了任务39 +统计数量 >> 20 + +*/ + +$webhook = new webhookTest(); + +r($webhook->getDataListTest()) && p('39:data') && e('用户创建了任务39'); //不需传任何参数,取出其中一个ID=39的日志内容,这里时间上取当前时间三小时以前的 +r(count($webhook->getDataListTest())) && p() && e('20'); //统计数量 \ No newline at end of file diff --git a/test/model/webhook/getdingdingdata.php b/test/model/webhook/getdingdingdata.php new file mode 100755 index 0000000000..e6ef014141 --- /dev/null +++ b/test/model/webhook/getdingdingdata.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +getDingdingData(); +cid=1 +pid=1 + +打印出msgtype >> 文本信息 @123456 +测试不传text的情况 >> @123456 +测试不传mobile的情况 >> 文本信息 +测试不传mobile的情况 >> 文本信息 @123456 + +*/ + +$webhook = new webhookTest(); + +$title = array(); +$title[0] = 'denghongtao'; +$title[1] = ''; + +$text = array(); +$text[0] = '文本信息'; +$text[1] = ''; + +$mobile = array(); +$mobile[0] = '123456'; +$mobile[1] = ''; + +r($webhook->getDingdingDataTest($title[0], $text[0], $mobile[0])) && p('markdown:text') && e('文本信息 @123456'); //打印出msgtype +r($webhook->getDingdingDataTest($title[0], $text[1], $mobile[0])) && p('markdown:text') && e('@123456'); //测试不传text的情况 +r($webhook->getDingdingDataTest($title[0], $text[0], $mobile[1])) && p('markdown:text') && e('文本信息'); //测试不传mobile的情况 +r($webhook->getDingdingDataTest($title[1], $text[0], $mobile[0])) && p('markdown:text') && e('文本信息 @123456'); //测试不传mobile的情况 \ No newline at end of file diff --git a/test/model/webhook/getfeishudata.php b/test/model/webhook/getfeishudata.php new file mode 100755 index 0000000000..7a0fcf6214 --- /dev/null +++ b/test/model/webhook/getfeishudata.php @@ -0,0 +1,34 @@ +#!/usr/bin/env php +getFeishuData(); +cid=1 +pid=1 + +测试正常传入的情况 >> wenbenxiaoxiang +测试不传title的情况 >> wenbenxiaoxiang + +*/ + +$webhook = new webhookTest(); + +$title = array(); +$title[0] = 'denghongtao'; +$title[1] = ''; + +$text = array(); +$text[0] = 'wenbenxiaoxiang'; +$text[1] = ''; + +$result1 = $webhook->getFeishuDataTest($title[0], $text[0]); +$result2 = $webhook->getFeishuDataTest($title[1], $text[0]); +$result3 = $webhook->getFeishuDataTest($title[0], $text[1]); + +r($result1) && p('content:text') && e('wenbenxiaoxiang'); //测试正常传入的情况 +r($result2) && p('content:text') && e('wenbenxiaoxiang'); //测试不传title的情况 +r($result3) && p('content:text') && e(''); //测试不传text的情况 \ No newline at end of file diff --git a/test/model/webhook/getlist.php b/test/model/webhook/getlist.php new file mode 100755 index 0000000000..e988e4cccf --- /dev/null +++ b/test/model/webhook/getlist.php @@ -0,0 +1,34 @@ +#!/usr/bin/env php +getList(); +cid=1 +pid=1 + +统计获取list里元素数量 >> 7 +取出其中一个id >> 1 + +*/ + +$webhook = new webhookTest(); + +$orderBy = array(); +$orderBy[0] = 'id_desc'; +$orderBy[1] = ''; + +$pager = array(); +$pager[0] = null; + +$decode = array(); +$decode[0] = true; +$decode[1] = ''; + +$result1 = $webhook->getListTest($orderBy[0]); + +r(count($result1)) && p() && e('15'); //统计获取list里元素数量 +r($result1) && p('1:id') && e('1'); //取出其中一个id diff --git a/test/model/webhook/getloglist.php b/test/model/webhook/getloglist.php new file mode 100755 index 0000000000..e898398729 --- /dev/null +++ b/test/model/webhook/getloglist.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php +getLogList(); +cid=1 +pid=1 + +统计ID为1的日志数量 >> 0 +统计ID为2的日志数量 >> 0 +统计ID不存在时的数量 >> 0 +取出ID为1的其中一个匹配操作内容 >> 0 + +*/ + +$webhook = new webhookTest(); + +$ID = array(); +$ID[0] = 1; +$ID[1] = 3; +$ID[2] = 1111; + +$result1 = $webhook->getLogListTest($ID[0], '', ''); +$result2 = $webhook->getLogListTest($ID[1], '', ''); +$result3 = $webhook->getLogListTest($ID[2], '', ''); + +//a($result1);die; +r(count($result1)) && p() && e('0'); //统计ID为1的日志数量 +r(count($result2)) && p() && e('0'); //统计ID为2的日志数量 +r(count($result3)) && p() && e('0'); //统计ID不存在时的数量 +r($result1) && p('4:action') && e('0'); //取出ID为1的其中一个匹配操作内容 \ No newline at end of file diff --git a/test/model/webhook/getopenidlist.php b/test/model/webhook/getopenidlist.php new file mode 100755 index 0000000000..71ce3985ba --- /dev/null +++ b/test/model/webhook/getopenidlist.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +getOpenIdList(); +cid=1 +pid=1 + + + +*/ + +$webhook = new webhookTest(); + +$webhook = array(); +$webhook[0] = 2; +$webhook[1] = ''; + +$action = array(); +$action[0] = 1; +$action[1] = ''; + +r($webhook->getOpenIdListTest($webhook[0], $action[0])) && p() && e(''); //测试传入正常数据的情况 +r($webhook->getOpenIdListTest($webhook[1], $action[1])) && p() && e(''); //测试传入空的情况 +r($webhook->getOpenIdListTest($webhook[0], $action[1])) && p() && e(''); //测试webhook传入空的情况 +r($webhook->getOpenIdListTest($webhook[1], $action[0])) && p() && e(''); //测试action传入空的情况 \ No newline at end of file diff --git a/test/model/webhook/getviewlink.php b/test/model/webhook/getviewlink.php new file mode 100755 index 0000000000..10c99e4c33 --- /dev/null +++ b/test/model/webhook/getviewlink.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +getViewLink(); +cid=1 +pid=1 + +打印出了get链接,我是通过./执行文件,所以打印的是./文件名和传入的参数,通过页面调用返回的则是url >> ./getviewlink.php?m=product&f=view&id=1 +同样返回调用方法的url >> ./getviewlink.php?m=story&f=view&id=2 +当不传入参数时 >> ./getviewlink.php?m=&f=view&id= + +*/ + +$webhook = new webhookTest(); + +$type = array(); +$type[0] = 'product'; +$type[1] = 'story'; +$type[2] = ''; + +$ID = array(); +$ID[0] = '1'; +$ID[1] = '2'; +$ID[2] = ''; + +$result1 = $webhook->getViewLinkTest($type[0], $ID[0]); +$result2 = $webhook->getViewLinkTest($type[1], $ID[1]); +$result3 = $webhook->getViewLinkTest($type[2], $ID[2]); + +r($result1) && p() && e('./getviewlink.php?m=product&f=view&id=1'); //打印出了get链接,我是通过./执行文件,所以打印的是./文件名和传入的参数,通过页面调用返回的则是url +r($result2) && p() && e('./getviewlink.php?m=story&f=view&id=2'); //同样返回调用方法的url +r($result3) && p() && e('./getviewlink.php?m=&f=view&id='); //当不传入参数时 \ No newline at end of file diff --git a/test/model/webhook/getweixindata.php b/test/model/webhook/getweixindata.php new file mode 100755 index 0000000000..b2660ea44a --- /dev/null +++ b/test/model/webhook/getweixindata.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php +getWeixinData(); +cid=1 +pid=1 + +测试正常传入的情况 >> 文本选择 +测试不传title >> 文本选择 +测试不传mobile >> 文本选择 + +*/ + +$webhook = new webhookTest(); + +$title = array(); +$title[0] = '名称'; +$title[1] = ''; + +$text = array(); +$text[0] = '文本选择'; +$text[1] = ''; + +$mobile = array(); +$mobile[0] = '123456'; +$mobile[1] = ''; + +$result1 = $webhook->getWeixinDataTest($title[0], $text[0], $mobile[0]); +$result2 = $webhook->getWeixinDataTest($title[1], $text[0], $mobile[0]); +$result3 = $webhook->getWeixinDataTest($title[0], $text[1], $mobile[0]); +$result4 = $webhook->getWeixinDataTest($title[0], $text[0], $mobile[1]); + +r($result1) && p('markdown:content') && e('文本选择'); //测试正常传入的情况 +r($result2) && p('markdown:content') && e('文本选择'); //测试不传title +r($result3) && p('markdown:content') && e(''); //测试不传text +r($result4) && p('markdown:content') && e('文本选择'); //测试不传mobile \ No newline at end of file diff --git a/test/model/webhook/savedata.php b/test/model/webhook/savedata.php new file mode 100755 index 0000000000..d1732bdf8b --- /dev/null +++ b/test/model/webhook/savedata.php @@ -0,0 +1,45 @@ +#!/usr/bin/env php +saveData(); +cid=1 +pid=1 + +测试正常传入的情况不传任何参数都会报错,所以这里没写其他传入情况 >> 1 + +*/ + +$webhook = new webhookTest(); + +$objectType = array(); +$objectType[0] = 'productplan'; +$objectType[1] = ''; + +$objectID = array(); +$objectID[0] = '3'; +$objectID[1] = ''; + +$actionType = array(); +$actionType[0] = 'opened'; +$actionType[1] = ''; + +$webhookID = array(); +$webhookID[0] = '3'; +$webhookID[1] = ''; + +$actionID = array(); +$actionID[0] = '3'; +$actionID[1] = ''; + +$actor = array(); +$actor[0] = 'test18'; +$actor[1] = ''; + +$result1 = $webhook->saveDataTest($objectType[0], $objectID[0], $actionType[0], $webhookID[0], $actionID[0], $actor[0]); + +r($webhook->saveDataTest($result1)) && p() && e('1'); //测试正常传入的情况不传任何参数都会报错,所以这里没写其他传入情况 \ No newline at end of file diff --git a/test/model/webhook/savelog.php b/test/model/webhook/savelog.php new file mode 100755 index 0000000000..9927cd1404 --- /dev/null +++ b/test/model/webhook/savelog.php @@ -0,0 +1,19 @@ +#!/usr/bin/env php +saveLog(); +cid=1 +pid=1 + + + +*/ + +$webhook = new webhookTest(); + +//r($webhook->saveLogTest()) && p() && e(); \ No newline at end of file diff --git a/test/model/webhook/send.php b/test/model/webhook/send.php new file mode 100755 index 0000000000..538cf0d913 --- /dev/null +++ b/test/model/webhook/send.php @@ -0,0 +1,78 @@ +#!/usr/bin/env php +send(); +cid=1 +pid=1 + +传入正常数据的情况,返回true >> 1 +传入正常数据2 >> 1 +传入objectType为空时 >> 1 +传入objectID为空时 >> 1 +传入actionType为空时 >> 1 +传入actionID为空时 >> 1 +传入actor为空时 >> 1 +传入参数不符的情况 >> 1 + +*/ + +$webhook = new webhookTest(); + +$objectType = array(); +$objectType[0] = 'product'; +$objectType[1] = 'story'; +$objectType[2] = 'productplan'; +$objectType[3] = 'release'; +$objectType[4] = 'project'; +$objectType[5] = ''; + +$objectID = array(); +$objectID[0] = 1; +$objectID[1] = 2; +$objectID[2] = 3; +$objectID[3] = 4; +$objectID[4] = ''; + +$actionType = array(); +$actionType[0] = 'common'; +$actionType[1] = 'extra'; +$actionType[2] = 'opented'; +$actionType[3] = 'created'; +$actionType[4] = ''; + +$actionID = array(); +$actionID[0] = 1; +$actionID[1] = 2; +$actionID[2] = 3; +$actionID[3] = 4; +$actionID[4] = ''; + +$actor = array(); +$actor[0] = 'admin'; +$actor[1] = 'dev17'; +$actor[2] = 'test18'; +$actor[3] = 'dev18'; +$actor[4] = ''; + +$result1 = $webhook->sendTest($objectType[0], $objectID[0], $actionType[0], $actionID[0], $actor[0]); +$result2 = $webhook->sendTest($objectType[1], $objectID[1], $actionType[1], $actionID[1], $actor[1]); +$result3 = $webhook->sendTest($objectType[5], $objectID[2], $actionType[2], $actionID[2], $actor[2]); +$result4 = $webhook->sendTest($objectType[0], $objectID[4], $actionType[0], $actionID[0], $actor[0]); +$result5 = $webhook->sendTest($objectType[0], $objectID[0], $actionType[4], $actionID[0], $actor[0]); +$result6 = $webhook->sendTest($objectType[0], $objectID[0], $actionType[0], $actionID[4], $actor[0]); +$result7 = $webhook->sendTest($objectType[0], $objectID[3], $actionType[0], $actionID[0], $actor[0]); +$result8 = $webhook->sendTest($objectType[1], $objectID[1], $actionType[0], $actionID[1], $actor[3]); + +r($result1) && p() && e('1'); //传入正常数据的情况,返回true +r($result2) && p() && e('1'); //传入正常数据2 +r($result3) && p() && e('1'); //传入objectType为空时 +r($result4) && p() && e('1'); //传入objectID为空时 +r($result5) && p() && e('1'); //传入actionType为空时 +r($result6) && p() && e('1'); //传入actionID为空时 +r($result7) && p() && e('1'); //传入actor为空时 +r($result8) && p() && e('1'); //传入参数不符的情况 \ No newline at end of file diff --git a/test/model/webhook/setsentstatus.php b/test/model/webhook/setsentstatus.php new file mode 100755 index 0000000000..230678ea71 --- /dev/null +++ b/test/model/webhook/setsentstatus.php @@ -0,0 +1,19 @@ +#!/usr/bin/env php +setSentStatus(); +cid=1 +pid=1 + + + +*/ + +$webhook = new webhookTest(); + +//r($webhook->setSentStatusTest()) && p() && e(); \ No newline at end of file diff --git a/test/model/webhook/update.php b/test/model/webhook/update.php new file mode 100755 index 0000000000..a74709aadf --- /dev/null +++ b/test/model/webhook/update.php @@ -0,0 +1,92 @@ +#!/usr/bin/env php +update(); +cid=1 +pid=1 + +我这里创建了一个新的webhook并修改他的信息 >> 1 +这里我只修改了name >> 『Hook地址』不能为空。 +这里修改name为空的情况 >> 『名称』不能为空。 +这里修改secret为空 >> 1 +这里修改domain为空 >> 1 +这里修改products为空 >> 1 +这里修改execution为空 >> 1 +这里修改desc为空 >> 1 + +*/ + +$webhook = new webhookTest(); + +$create = array(); +$create['type'] = 'dinggroup'; +$create['name'] = '新加的webhook'; +$create['url'] = 'https://www.baidu.com'; +$create['secret'] = 12222; +$create['agentId'] = ''; +$create['appKey'] = ''; +$create['appSecret'] = ''; +$create['wechatCorpId'] = ''; +$create['wechatCorpSecret'] = ''; +$create['wechatAgentId'] = ''; +$create['feishuAppId'] = ''; +$create['feishuAppSecret'] = ''; +$create['domain'] = 'http://www.zentaopms.com'; +$create['sendType'] = 'sync'; +$create['products'] = array('0' => 100); +$create['executions'] = array('0' => 700); +$create['desc'] = '当你老了~~~'; + +$update = array(); +$update['type'] = 'dinggroup'; +$update['name'] = '新加的webhook12'; +$update['url'] = 'https://www.baidu.com.'; +$update['secret'] = '122221'; +$update['domain'] = 'http://www.zentaopms.com'; +$update['products'] = array('0' => 100, '1' => 98); +$update['executions'] = array('0' => 700, '1' => 696); +$update['desc'] = '当你老了~~~敲不动了'; + +$update1 = array(); +$update1['name'] = '修改后的数据'; + +$update2 = array(); +$update2['name'] = ''; + +$update3 = $update; +$update3['secret'] = ''; + +$update4 = $update; +$update4['domain'] = ''; + +$update5 = $update; +$update5['products'] = array(); + +$update6 = $update; +$update6['executions'] = array(); + +$update7 = $update; +$update7['desc'] = ''; + +$result1 = $webhook->updateTest($create, $update); +$result2 = $webhook->updateTest($create, $update1); +$result3 = $webhook->updateTest($create, $update2); +$result4 = $webhook->updateTest($create, $update3); +$result5 = $webhook->updateTest($create, $update4); +$result6 = $webhook->updateTest($create, $update5); +$result7 = $webhook->updateTest($create, $update6); +$result8 = $webhook->updateTest($create, $update7); + +r($result1) && p() && e('1'); //我这里创建了一个新的webhook并修改他的信息 +r($result2) && p('url:0') && e('『Hook地址』不能为空。'); //这里我只修改了name +r($result3) && p('name:0') && e('『名称』不能为空。'); //这里修改name为空的情况 +r($result4) && p() && e('1'); //这里修改secret为空 +r($result5) && p() && e('1'); //这里修改domain为空 +r($result6) && p() && e('1'); //这里修改products为空 +r($result7) && p() && e('1'); //这里修改execution为空 +r($result8) && p() && e('1'); //这里修改desc为空 \ No newline at end of file