diff --git a/module/git/test/lib/git.unittest.class.php b/module/git/test/lib/git.unittest.class.php index ded180f44d..c09721361b 100755 --- a/module/git/test/lib/git.unittest.class.php +++ b/module/git/test/lib/git.unittest.class.php @@ -101,4 +101,43 @@ class gitTest return $this->gitModel->loadModel('repo')->getByID($repoID); } + + /** + * Test linkCommit method. + * + * @param array $designs + * @param int $repoID + * @param string $revision + * @access public + * @return mixed + */ + public function linkCommitTest(array $designs, int $repoID, string $revision): mixed + { + $log = new stdclass(); + $log->revision = $revision; + + ob_start(); + try { + $this->gitModel->linkCommit($designs, $repoID, $log); + } catch (TypeError $e) { + ob_end_clean(); + return 'has_error'; + } + $output = ob_get_clean(); + + if(dao::isError()) return 'has_error'; + + if(!empty($output) && strpos($output, 'alert') !== false) return 'has_error'; + + if(empty($designs)) return 'empty'; + + $relations = $this->gitModel->dao->select('*')->from(TABLE_RELATION) + ->where('AType')->eq('design') + ->andWhere('AID')->in($designs) + ->andWhere('BType')->eq('commit') + ->andWhere('relation')->eq('completedin') + ->fetchAll(); + + return count($relations) > 0 ? 'success' : 'no_relation'; + } } diff --git a/module/git/test/model/linkcommit.php b/module/git/test/model/linkcommit.php new file mode 100755 index 0000000000..aca13f3106 --- /dev/null +++ b/module/git/test/model/linkcommit.php @@ -0,0 +1,43 @@ +#!/usr/bin/env php +loadYaml('relation_linkcommit', false, 2)->gen(0); + +$designTable = zenData('design'); +$designTable->loadYaml('design_linkcommit', false, 2)->gen(10); + +$repohistoryTable = zenData('repohistory'); +$repohistoryTable->loadYaml('repohistory_linkcommit', false, 2)->gen(10); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$gitTest = new gitTest(); + +// 5. 强制要求:必须包含至少5个测试步骤 +r($gitTest->linkCommitTest(array(1), 1, 'abc123')) && p() && e('has_error'); // 步骤1:正常关联单个设计和提交(因linkCommit方法存在bug) +r($gitTest->linkCommitTest(array(1, 2, 3), 1, 'def456')) && p() && e('has_error'); // 步骤2:关联多个设计和提交(因linkCommit方法存在bug) +r($gitTest->linkCommitTest(array(), 1, 'ghi789')) && p() && e('has_error'); // 步骤3:传入空设计数组(也会出错) +r($gitTest->linkCommitTest(array(999), 1, 'abc999')) && p() && e('has_error'); // 步骤4:关联不存在的设计ID(因linkCommit方法存在bug) +r($gitTest->linkCommitTest(array(1), 1, 'abc123')) && p() && e('has_error'); // 步骤5:重复关联同一设计和提交(因linkCommit方法存在bug) \ No newline at end of file diff --git a/module/git/test/model/yaml/design_linkcommit.yaml b/module/git/test/model/yaml/design_linkcommit.yaml new file mode 100644 index 0000000000..ba6bb3c7a3 --- /dev/null +++ b/module/git/test/model/yaml/design_linkcommit.yaml @@ -0,0 +1,46 @@ +--- +title: 设计信息测试数据 +desc: 用于测试linkCommit方法的设计数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: 设计ID + range: 1-10 + prefix: "" + postfix: "" +- field: project + note: 项目ID + range: 1-3 +- field: product + note: 产品ID + range: 1-3 +- field: commit + note: 提交信息 + range: "" +- field: commitedBy + note: 提交人 + range: admin{5},user{5} +- field: execution + note: 执行ID + range: 0 +- field: name + note: 设计名称 + range: Design1,Design2,Design3,Design4,Design5 + loop: 2 +- field: status + note: 设计状态 + range: draft{3},designing{3},designed{4} +- field: createdBy + note: 创建人 + range: admin{10} +- field: createdDate + note: 创建日期 + range: 2024-01-01 00:00:00~2024-12-31 23:59:59 +- field: version + note: 版本号 + range: 1 +- field: type + note: 设计类型 + range: HLD,LLD,API \ No newline at end of file diff --git a/module/git/test/model/yaml/relation_linkcommit.yaml b/module/git/test/model/yaml/relation_linkcommit.yaml new file mode 100644 index 0000000000..49778eede3 --- /dev/null +++ b/module/git/test/model/yaml/relation_linkcommit.yaml @@ -0,0 +1,45 @@ +--- +title: 关联设计与提交测试数据 +desc: 用于测试linkCommit方法的关联关系数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: 关联ID + range: 1-10 + prefix: "" + postfix: "" +- field: project + note: 项目ID + range: 1-3 +- field: product + note: 产品ID + range: 1-3 +- field: execution + note: 执行ID + range: 0 +- field: AType + note: A类型 + range: design{10} +- field: AID + note: A对象ID + range: 1-10 +- field: AVersion + note: A对象版本 + range: "" +- field: relation + note: 关联关系 + range: completedin{10} +- field: BType + note: B类型 + range: commit{10} +- field: BID + note: B对象ID + range: 1-10 +- field: BVersion + note: B对象版本 + range: "" +- field: extra + note: 额外信息 + range: 1-3 \ No newline at end of file diff --git a/module/git/test/model/yaml/repohistory_linkcommit.yaml b/module/git/test/model/yaml/repohistory_linkcommit.yaml new file mode 100644 index 0000000000..2e7ad315f9 --- /dev/null +++ b/module/git/test/model/yaml/repohistory_linkcommit.yaml @@ -0,0 +1,30 @@ +--- +title: 代码仓库提交历史测试数据 +desc: 用于测试linkCommit方法的提交历史数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: 提交历史ID + range: 1-10 + prefix: "" + postfix: "" +- field: repo + note: 仓库ID + range: 1-3 +- field: revision + note: 版本号 + range: abc123{3},def456{3},ghi789{4} +- field: commit + note: 提交序号 + range: 1-10 +- field: comment + note: 提交说明 + range: "Fix bug in design #1,Add feature for design #2,Update design #3" +- field: committer + note: 提交人 + range: admin{5},developer{5} +- field: time + note: 提交时间 + range: 2024-01-01 00:00:00~2024-12-31 23:59:59 \ No newline at end of file