From fbc3d3a204a0ca9cef22b4bce56555dc07cde37a Mon Sep 17 00:00:00 2001 From: liugang Date: Sat, 13 Sep 2025 00:42:13 +0800 Subject: [PATCH] + [misc] Add unit tests for webhookTao::getWeixinSecret() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../test/lib/webhook.unittest.class.php | 19 +++ module/webhook/test/tao/getweixinsecret.php | 63 ++++++++++ .../tao/yaml/webhook_getweixinsecret.yaml | 112 ++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100755 module/webhook/test/tao/getweixinsecret.php create mode 100644 module/webhook/test/tao/yaml/webhook_getweixinsecret.yaml diff --git a/module/webhook/test/lib/webhook.unittest.class.php b/module/webhook/test/lib/webhook.unittest.class.php index 93c02e165e..1b4d7cda5d 100644 --- a/module/webhook/test/lib/webhook.unittest.class.php +++ b/module/webhook/test/lib/webhook.unittest.class.php @@ -484,4 +484,23 @@ class webhookTest return $result; } + + /** + * Test getWeixinSecret method. + * + * @param object $webhook + * @access public + * @return object|false + */ + public function getWeixinSecretTest($webhook) + { + $reflection = new ReflectionClass($this->objectTao); + $method = $reflection->getMethod('getWeixinSecret'); + $method->setAccessible(true); + + $result = $method->invoke($this->objectTao, $webhook); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/webhook/test/tao/getweixinsecret.php b/module/webhook/test/tao/getweixinsecret.php new file mode 100755 index 0000000000..55b420af59 --- /dev/null +++ b/module/webhook/test/tao/getweixinsecret.php @@ -0,0 +1,63 @@ +#!/usr/bin/env php +wechatCorpId = 'wxcorp123456789'; +$normalWebhook->wechatCorpSecret = 'wechat_secret_123456789'; +$normalWebhook->wechatAgentId = '1000001'; + +r($webhookTest->getWeixinSecretTest($normalWebhook)) && p('url') && e('https://qyapi.weixin.qq.com/cgi-bin/'); + +// 缺少企业ID +$missingCorpId = new stdClass(); +$missingCorpId->wechatCorpId = ''; +$missingCorpId->wechatCorpSecret = 'wechat_secret_123456789'; +$missingCorpId->wechatAgentId = '1000001'; + +r($webhookTest->getWeixinSecretTest($missingCorpId)) && p('wechatCorpId') && e('『企业ID』不能为空。'); + +// 缺少企业秘钥 +$missingCorpSecret = new stdClass(); +$missingCorpSecret->wechatCorpId = 'wxcorp123456789'; +$missingCorpSecret->wechatCorpSecret = ''; +$missingCorpSecret->wechatAgentId = '1000001'; + +r($webhookTest->getWeixinSecretTest($missingCorpSecret)) && p('wechatCorpSecret') && e('『应用的凭证密钥』不能为空。'); + +// 缺少应用ID +$missingAgentId = new stdClass(); +$missingAgentId->wechatCorpId = 'wxcorp123456789'; +$missingAgentId->wechatCorpSecret = 'wechat_secret_123456789'; +$missingAgentId->wechatAgentId = ''; + +r($webhookTest->getWeixinSecretTest($missingAgentId)) && p('wechatAgentId') && e('『企业应用的ID』不能为空。'); + +// 所有参数都为空 +$emptyWebhook = new stdClass(); +$emptyWebhook->wechatCorpId = ''; +$emptyWebhook->wechatCorpSecret = ''; +$emptyWebhook->wechatAgentId = ''; + +r($webhookTest->getWeixinSecretTest($emptyWebhook)) && p('wechatCorpId') && e('『企业ID』不能为空。'); \ No newline at end of file diff --git a/module/webhook/test/tao/yaml/webhook_getweixinsecret.yaml b/module/webhook/test/tao/yaml/webhook_getweixinsecret.yaml new file mode 100644 index 0000000000..cdc5ad12c8 --- /dev/null +++ b/module/webhook/test/tao/yaml/webhook_getweixinsecret.yaml @@ -0,0 +1,112 @@ +--- +title: webhook表数据定义 +desc: 为getWeixinSecret方法测试准备webhook表数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: Webhook ID + range: 1-5 + prefix: "" + postfix: "" + +- field: type + note: Webhook类型 + range: weixin{5} + format: "" + +- field: name + note: Webhook名称 + range: 微信测试{5} + format: "" + +- field: url + note: Webhook URL地址 + range: https://qyapi.weixin.qq.com/cgi-bin/webhook/send{5} + format: "" + +- field: domain + note: 域名 + range: qyapi.weixin.qq.com{5} + format: "" + +- field: secret + note: 加密信息 + range: '{}'{5} + format: "" + +- field: contentType + note: 内容类型 + range: application/json{5} + format: "" + +- field: sendType + note: 发送类型 + range: sync{3},async{2} + format: "" + +- field: products + note: 产品列表 + range: '[]'{5} + format: "" + +- field: executions + note: 执行列表 + range: '[]'{5} + format: "" + +- field: params + note: 参数 + range: wechatCorpId,wechatCorpSecret,wechatAgentId{5} + format: "" + +- field: actions + note: 动作列表 + range: 'all'{5} + format: "" + +- field: desc + note: 描述 + range: 微信Webhook测试{5} + format: "" + +- field: createdBy + note: 创建者 + range: admin{5} + format: "" + +- field: createdDate + note: 创建时间 + range: 2024-01-01 10:00:00{5} + format: "" + +- field: editedBy + note: 编辑者 + range: admin{3},user{2} + format: "" + +- field: editedDate + note: 编辑时间 + range: 2024-01-01 11:00:00{5} + format: "" + +- field: deleted + note: 删除标记 + range: '0'{5} + format: "" + +- field: wechatCorpId + note: 微信企业ID + range: wxcorp123456789{3},wxcorp987654321{1},{}{1} + format: "" + +- field: wechatCorpSecret + note: 微信企业秘钥 + range: wechat_secret_123456789{3},wechat_secret_987654321{1},{}{1} + format: "" + +- field: wechatAgentId + note: 微信应用ID + range: 1000001{3},1000002{1},{}{1} + format: "" \ No newline at end of file