diff --git a/module/testcase/test/lib/testcasezen.unittest.class.php b/module/testcase/test/lib/testcasezen.unittest.class.php index 2202d09b63..1e57f4496d 100755 --- a/module/testcase/test/lib/testcasezen.unittest.class.php +++ b/module/testcase/test/lib/testcasezen.unittest.class.php @@ -2910,4 +2910,56 @@ class testcaseZenTest return $result; } + /** + * Test assignTitleForBatchEdit method. + * + * @param int $productID + * @param string $branch + * @param string $type + * @param array $cases + * @access public + * @return array + */ + public function assignTitleForBatchEditTest(int $productID, string $branch, string $type, array $cases): array + { + global $tester; + + // 初始化必要的对象 + if(!isset($tester->view)) $tester->view = new stdClass(); + if(!isset($tester->session)) $tester->session = new stdClass(); + if(!isset($tester->config)) $tester->config = new stdClass(); + if(!isset($tester->config->testcase)) $tester->config->testcase = new stdClass(); + + // 设置测试数据 + $tester->session->project = 1; + $tester->session->execution = 1; + + // 初始化config属性 + $tester->config->testcase->list = new stdClass(); + $tester->config->testcase->list->customBatchEditFields = 'module,story,stage,pri,status'; + $tester->config->testcase->custom = new stdClass(); + $tester->config->testcase->custom->batchEditFields = 'module,story,stage,pri,status'; + + try { + // 调用被测方法 + $result = callZenMethod('testcase', 'assignTitleForBatchEdit', [$productID, $branch, $type, $cases]); + + // 返回结果数组:[productIdList, libIdList] + return array( + 'productIdList' => $result[0], + 'libIdList' => $result[1], + 'productIdListCount' => count($result[0]), + 'libIdListCount' => count($result[1]) + ); + } catch (Exception $e) { + return array( + 'error' => $e->getMessage(), + 'productIdList' => array(), + 'libIdList' => array(), + 'productIdListCount' => 0, + 'libIdListCount' => 0 + ); + } + } + } diff --git a/module/testcase/test/zen/assigntitleforbatchedit.php b/module/testcase/test/zen/assigntitleforbatchedit.php new file mode 100755 index 0000000000..2bc6e68450 --- /dev/null +++ b/module/testcase/test/zen/assigntitleforbatchedit.php @@ -0,0 +1,99 @@ +#!/usr/bin/env php +id->range('1-20'); +$caseTable->product->range('1{5},2{5},3{5},4{5}'); +$caseTable->branch->range('0{10},1{5},2{5}'); +$caseTable->lib->range('0{10},1{5},2{5}'); +$caseTable->module->range('1-5'); +$caseTable->title->range('测试用例1,测试用例2,测试用例3,测试用例4,测试用例5'); +$caseTable->type->range('feature{10},performance{5},config{3},install{2}'); +$caseTable->status->range('normal{15},blocked{3},investigate{2}'); +$caseTable->deleted->range('0'); +$caseTable->gen(20); + +$productTable = zenData('product'); +$productTable->id->range('1-5'); +$productTable->name->range('产品A,产品B,产品C,产品D,产品E'); +$productTable->type->range('normal{3},branch{2}'); +$productTable->status->range('normal'); +$productTable->deleted->range('0'); +$productTable->gen(5); + +$libTable = zenData('testsuite'); +$libTable->id->range('1-5'); +$libTable->name->range('测试库A,测试库B,测试库C,测试库D,测试库E'); +$libTable->type->range('library'); +$libTable->product->range('0'); +$libTable->deleted->range('0'); +$libTable->gen(5); + +$branchTable = zenData('branch'); +$branchTable->id->range('1-5'); +$branchTable->product->range('4{3},5{2}'); +$branchTable->name->range('分支1,分支2,分支3,分支4,分支5'); +$branchTable->status->range('active'); +$branchTable->deleted->range('0'); +$branchTable->gen(5); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$testcaseTest = new testcaseZenTest(); + +// 准备测试用例数据 +$productCase1 = new stdClass(); +$productCase1->id = 1; +$productCase1->product = 1; +$productCase1->lib = 0; + +$productCase2 = new stdClass(); +$productCase2->id = 2; +$productCase2->product = 2; +$productCase2->lib = 0; + +$libCase1 = new stdClass(); +$libCase1->id = 11; +$libCase1->product = 0; +$libCase1->lib = 1; + +$libCase2 = new stdClass(); +$libCase2->id = 12; +$libCase2->product = 0; +$libCase2->lib = 2; + +$mixedCases = array($productCase1, $libCase1); + +// 5. 🔴 强制要求:必须包含至少5个测试步骤 +r($testcaseTest->assignTitleForBatchEditTest(1, '', 'lib', array())) && p('libIdListCount') && e('1'); // 步骤1:测试type为lib时 +r($testcaseTest->assignTitleForBatchEditTest(1, '', 'case', array())) && p('productIdListCount') && e('1'); // 步骤2:测试type为case且productID有效时 +r($testcaseTest->assignTitleForBatchEditTest(0, '', 'case', array($productCase1, $productCase2))) && p('productIdListCount') && e('2'); // 步骤3:测试从cases中提取productIdList +r($testcaseTest->assignTitleForBatchEditTest(0, '', 'case', array($libCase1, $libCase2))) && p('libIdListCount') && e('2'); // 步骤4:测试从cases中提取libIdList +r($testcaseTest->assignTitleForBatchEditTest(0, '', 'case', $mixedCases)) && p('productIdListCount,libIdListCount') && e('1,1'); // 步骤5:测试混合用例 +r($testcaseTest->assignTitleForBatchEditTest(2, '', 'case', array())) && p('productIdListCount') && e('1'); // 步骤6:测试空cases数组边界情况 +r($testcaseTest->assignTitleForBatchEditTest(4, '1', 'case', array())) && p('productIdListCount') && e('1'); // 步骤7:测试带分支的产品批量编辑 \ No newline at end of file