diff --git a/module/task/test/lib/taskzen.unittest.class.php b/module/task/test/lib/taskzen.unittest.class.php index 89c8e986bd..ca9a78eb2a 100755 --- a/module/task/test/lib/taskzen.unittest.class.php +++ b/module/task/test/lib/taskzen.unittest.class.php @@ -2103,4 +2103,36 @@ class taskZenTest return array('error' => $e->getMessage()); } } + + /** + * Test checkGitRepo method. + * + * @param int $executionID + * @access public + * @return mixed + */ + public function checkGitRepoTest($executionID = null) + { + try + { + $taskZenInstance = $this->taskZenTest->newInstance(); + + // Get reflection method + $method = $this->taskZenTest->getMethod('checkGitRepo'); + $method->setAccessible(true); + + $result = $method->invokeArgs($taskZenInstance, [$executionID]); + + if(dao::isError()) return dao::getError(); + return $result; + } + catch(Exception $e) + { + return array('error' => $e->getMessage()); + } + catch(Throwable $e) + { + return array('error' => $e->getMessage()); + } + } } diff --git a/module/task/test/zen/checkgitrepo.php b/module/task/test/zen/checkgitrepo.php new file mode 100755 index 0000000000..34c45c71ec --- /dev/null +++ b/module/task/test/zen/checkgitrepo.php @@ -0,0 +1,52 @@ +#!/usr/bin/env php +loadModel('')->dao; + +// 清理并插入仓库数据 +$dao->exec("DELETE FROM zt_repo"); +$dao->exec("INSERT INTO zt_repo (id, product, SCM, name, deleted, synced) VALUES + (1, '1,2', 'Gitlab', 'repo1', '0', '1'), + (2, '2,3', 'Gitea', 'repo2', '0', '1'), + (3, '', 'Gogs', 'repo3', '0', '1')"); + +// 清理并插入项目产品关联数据 +$dao->exec("DELETE FROM zt_projectproduct"); +$dao->exec("INSERT INTO zt_projectproduct (project, product, branch) VALUES + (1, 1, 0), + (2, 2, 0), + (3, 3, 0)"); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$taskTest = new taskZenTest(); + +// 5. 🔴 强制要求:必须包含至少5个测试步骤 +r($taskTest->checkGitRepoTest(1)) && p() && e(1); // 步骤1:项目1关联产品1,仓库1关联产品1,2,应返回true +r($taskTest->checkGitRepoTest(2)) && p() && e(1); // 步骤2:项目2关联产品2,仓库1关联产品1,2,应返回true +r($taskTest->checkGitRepoTest(3)) && p() && e(1); // 步骤3:项目3关联产品3,仓库2关联产品2,3,应返回true +r($taskTest->checkGitRepoTest(999)) && p() && e(0); // 步骤4:不存在的项目执行ID,应返回false +r($taskTest->checkGitRepoTest(0)) && p() && e(1); // 步骤5:项目ID为0时获取所有产品,匹配仓库,应返回true \ No newline at end of file diff --git a/module/task/test/zen/yaml/repo_checkgitrepo.yaml b/module/task/test/zen/yaml/repo_checkgitrepo.yaml new file mode 100644 index 0000000000..ccce1817e1 --- /dev/null +++ b/module/task/test/zen/yaml/repo_checkgitrepo.yaml @@ -0,0 +1,92 @@ +--- +title: checkGitRepo测试数据 +desc: 为taskZen::checkGitRepo方法提供测试数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: 仓库ID + range: 1-10 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: product + note: 关联的产品ID(逗号分隔) + range: ['1,2', '2,3', '3,4', '1', '2', '3', '4', '', '1,2,3', '5,6'] +- field: projects + note: 关联的项目ID(逗号分隔) + range: ['1,2', '2,3', '3,4', '1', '2', '3', '4', '', '1,2,3', '5,6'] +- field: name + note: 仓库名称 + range: ['test-repo-1', 'test-repo-2', 'test-repo-3', 'test-repo-4', 'test-repo-5', 'test-repo-6', 'test-repo-7', 'test-repo-8', 'test-repo-9', 'test-repo-10'] +- field: path + note: 仓库路径 + range: ['/path/to/repo1', '/path/to/repo2', '/path/to/repo3', '/path/to/repo4', '/path/to/repo5', '/path/to/repo6', '/path/to/repo7', '/path/to/repo8', '/path/to/repo9', '/path/to/repo10'] +- field: prefix + note: 前缀 + range: ['', 'pre1', 'pre2', 'pre3', 'pre4', 'pre5', 'pre6', 'pre7', 'pre8', 'pre9'] +- field: encoding + note: 编码 + range: ['utf-8', 'utf-8', 'utf-8', 'utf-8', 'utf-8', 'utf-8', 'utf-8', 'utf-8', 'utf-8', 'utf-8'] +- field: SCM + note: 版本控制系统 + range: ['Gitlab', 'Gitea', 'Gogs', 'Gitlab', 'Gitea', 'Gogs', 'Gitlab', 'Gitea', 'Gogs', 'Gitlab'] +- field: client + note: 客户端 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: serviceHost + note: 服务主机 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: serviceProject + note: 服务项目 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: commits + note: 提交数量 + range: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] +- field: account + note: 账号 + range: ['', 'user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7', 'user8', 'user9'] +- field: password + note: 密码 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: encrypt + note: 加密方式 + range: ['plain', 'plain', 'plain', 'plain', 'plain', 'plain', 'plain', 'plain', 'plain', 'plain'] +- field: acl + note: 访问控制列表 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: synced + note: 是否已同步 + range: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] +- field: lastSync + note: 最后同步时间 + range: [null, '2023-01-01 00:00:00', '2023-01-02 00:00:00', '2023-01-03 00:00:00', '2023-01-04 00:00:00', '2023-01-05 00:00:00', '2023-01-06 00:00:00', '2023-01-07 00:00:00', '2023-01-08 00:00:00', '2023-01-09 00:00:00'] +- field: lastCommit + note: 最后提交时间 + range: [null, '2023-01-01 00:00:00', '2023-01-02 00:00:00', '2023-01-03 00:00:00', '2023-01-04 00:00:00', '2023-01-05 00:00:00', '2023-01-06 00:00:00', '2023-01-07 00:00:00', '2023-01-08 00:00:00', '2023-01-09 00:00:00'] +- field: desc + note: 描述 + range: ['', '描述1', '描述2', '描述3', '描述4', '描述5', '描述6', '描述7', '描述8', '描述9'] +- field: extra + note: 额外信息 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: preMerge + note: 预合并 + range: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0'] +- field: job + note: 任务ID + range: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] +- field: fileServerUrl + note: 文件服务器URL + range: [null, null, null, null, null, null, null, null, null, null] +- field: fileServerAccount + note: 文件服务器账号 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: fileServerPassword + note: 文件服务器密码 + range: ['', '', '', '', '', '', '', '', '', ''] +- field: deleted + note: 是否删除 + range: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0'] \ No newline at end of file