+ [misc] Add unit tests for caselibZen::processCasesForExport() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1013,4 +1013,89 @@ class caselibTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processCasesForExport method.
|
||||
*
|
||||
* @param array $cases
|
||||
* @param int $libID
|
||||
* @param array $postData
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return array|int|string
|
||||
*/
|
||||
public function processCasesForExportTest(array $cases, int $libID, array $postData = array(), string $type = 'array')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 设置POST数据模拟
|
||||
$_POST['fileType'] = $postData['fileType'] ?? 'csv';
|
||||
|
||||
$zen = initReference('caselib');
|
||||
$method = $zen->getMethod('processCasesForExport');
|
||||
$zenInstance = $zen->newInstance();
|
||||
|
||||
$result = $method->invoke($zenInstance, $cases, $libID);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
if($type == 'count') return count($result);
|
||||
if($type == 'keys') return array_keys($result);
|
||||
if($type == 'first_case' && !empty($result)) return reset($result);
|
||||
if($type == 'first_case_id' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->id ?? '';
|
||||
}
|
||||
if($type == 'first_case_title' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->title ?? '';
|
||||
}
|
||||
if($type == 'first_case_module' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->module ?? '';
|
||||
}
|
||||
if($type == 'first_case_pri' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->pri ?? '';
|
||||
}
|
||||
if($type == 'first_case_type' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->type ?? '';
|
||||
}
|
||||
if($type == 'first_case_status' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->status ?? '';
|
||||
}
|
||||
if($type == 'first_case_openedBy' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->openedBy ?? '';
|
||||
}
|
||||
if($type == 'first_case_openedDate' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->openedDate ?? '';
|
||||
}
|
||||
if($type == 'first_case_stepDesc' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->stepDesc ?? '';
|
||||
}
|
||||
if($type == 'first_case_stepExpect' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->stepExpected ?? '';
|
||||
}
|
||||
if($type == 'first_case_stage' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->stage ?? '';
|
||||
}
|
||||
if($type == 'first_case_files' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return $firstCase->files ?? '';
|
||||
}
|
||||
if($type == 'has_linkCase' && !empty($result)) {
|
||||
$firstCase = reset($result);
|
||||
return isset($firstCase->linkCase) && !empty($firstCase->linkCase) ? 1 : 0;
|
||||
}
|
||||
if($type == 'is_empty') return empty($result) ? 1 : 0;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 caselibZen::processCasesForExport();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 执行caselibTest模块的processCasesForExportTest方法,参数是$normalCases, 1, array @1
|
||||
- 执行caselibTest模块的processCasesForExportTest方法,参数是array @1
|
||||
- 执行caselibTest模块的processCasesForExportTest方法,参数是$casesWithSteps, 1, array @1
|
||||
- 执行caselibTest模块的processCasesForExportTest方法,参数是$normalCases, 1, array @1
|
||||
- 执行caselibTest模块的processCasesForExportTest方法,参数是$casesWithLinkCase, 1, array @1
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/caselib.unittest.class.php';
|
||||
|
||||
zenData('user')->gen(10);
|
||||
zenData('module')->gen(10);
|
||||
zenData('case')->gen(10);
|
||||
zenData('casestep')->gen(20);
|
||||
zenData('file')->gen(5);
|
||||
|
||||
su('admin');
|
||||
|
||||
$caselibTest = new caselibTest();
|
||||
|
||||
// 步骤1:测试正常用例数据的导出处理
|
||||
$normalCases = array(
|
||||
1 => (object) array(
|
||||
'id' => 1,
|
||||
'title' => 'Test Case 1',
|
||||
'module' => 1,
|
||||
'pri' => 1,
|
||||
'type' => 'feature',
|
||||
'status' => 'normal',
|
||||
'openedBy' => 'admin',
|
||||
'lastEditedBy' => 'user1',
|
||||
'openedDate' => '2023-01-01 10:00:00',
|
||||
'lastRunDate' => '2023-01-02 10:00:00',
|
||||
'stage' => 'unittest,feature',
|
||||
'linkCase' => '',
|
||||
'stepDesc' => '',
|
||||
'stepExpect' => ''
|
||||
)
|
||||
);
|
||||
r($caselibTest->processCasesForExportTest($normalCases, 1, array('fileType' => 'csv'), 'count')) && p() && e('1');
|
||||
|
||||
// 步骤2:测试空用例数组的处理
|
||||
r($caselibTest->processCasesForExportTest(array(), 1, array('fileType' => 'csv'), 'is_empty')) && p() && e('1');
|
||||
|
||||
// 步骤3:测试包含步骤的用例导出处理,验证返回的用例数量
|
||||
$casesWithSteps = array(
|
||||
2 => (object) array(
|
||||
'id' => 2,
|
||||
'title' => 'Test Case with Steps',
|
||||
'module' => 2,
|
||||
'pri' => 2,
|
||||
'type' => 'performance',
|
||||
'status' => 'normal',
|
||||
'openedBy' => 'admin',
|
||||
'lastEditedBy' => 'user2',
|
||||
'openedDate' => '2023-01-01 10:00:00',
|
||||
'lastRunDate' => '2023-01-02 10:00:00',
|
||||
'stage' => 'feature',
|
||||
'linkCase' => '',
|
||||
'stepDesc' => '',
|
||||
'stepExpect' => ''
|
||||
)
|
||||
);
|
||||
r($caselibTest->processCasesForExportTest($casesWithSteps, 1, array('fileType' => 'csv'), 'count')) && p() && e('1');
|
||||
|
||||
// 步骤4:测试HTML文件类型的导出处理
|
||||
r($caselibTest->processCasesForExportTest($normalCases, 1, array('fileType' => 'html'), 'first_case_id')) && p() && e('1');
|
||||
|
||||
// 步骤5:测试包含关联用例的导出处理
|
||||
$casesWithLinkCase = array(
|
||||
3 => (object) array(
|
||||
'id' => 3,
|
||||
'title' => 'Test Case with Link',
|
||||
'module' => 3,
|
||||
'pri' => 3,
|
||||
'type' => 'interface',
|
||||
'status' => 'normal',
|
||||
'openedBy' => 'admin',
|
||||
'lastEditedBy' => 'user3',
|
||||
'openedDate' => '2023-01-01 10:00:00',
|
||||
'lastRunDate' => '2023-01-02 10:00:00',
|
||||
'stage' => 'feature,integration',
|
||||
'linkCase' => '1,2',
|
||||
'stepDesc' => '',
|
||||
'stepExpect' => ''
|
||||
)
|
||||
);
|
||||
r($caselibTest->processCasesForExportTest($casesWithLinkCase, 1, array('fileType' => 'csv'), 'has_linkCase')) && p() && e('1');
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
title: 用例步骤数据 for processCasesForExport
|
||||
desc: 用于测试 caselibZen::processCasesForExport 方法的用例步骤数据
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 步骤ID
|
||||
range: 1-20
|
||||
- field: case
|
||||
note: 用例ID
|
||||
range: 1{5},2{5},3{5},4{5}
|
||||
- field: version
|
||||
note: 版本号
|
||||
range: 1
|
||||
- field: type
|
||||
note: 步骤类型
|
||||
range: 'step{15},group{3},item{2}'
|
||||
- field: parent
|
||||
note: 父步骤ID
|
||||
range: 0{15},1{3},2{2}
|
||||
- field: desc
|
||||
note: 步骤描述
|
||||
range: 'Login to system{5},Navigate to page{5},Click button{5},Verify result{5}'
|
||||
- field: expect
|
||||
note: 预期结果
|
||||
range: 'Login successful{5},Page loaded{5},Button clicked{5},Result correct{5}'
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: 模块数据 for processCasesForExport
|
||||
desc: 用于测试 caselibZen::processCasesForExport 方法的模块数据
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 模块ID
|
||||
range: 1-10
|
||||
- field: root
|
||||
note: 根节点ID
|
||||
range: 1-3
|
||||
- field: type
|
||||
note: 模块类型
|
||||
range: 'caselib'
|
||||
- field: parent
|
||||
note: 父模块ID
|
||||
range: 0{5},1{3},2{2}
|
||||
- field: path
|
||||
note: 路径
|
||||
range: ',1,{3},1,2,{3},1,3,{2},2,4,{2}'
|
||||
- field: grade
|
||||
note: 级别
|
||||
range: 1{5},2{3},3{2}
|
||||
- field: order
|
||||
note: 排序
|
||||
range: 1-10
|
||||
- field: name
|
||||
note: 模块名称
|
||||
range: '功能模块{3},界面模块{3},性能模块{2},安全模块{2}'
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: 测试用例数据 for processCasesForExport
|
||||
desc: 用于测试 caselibZen::processCasesForExport 方法的测试用例数据
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 用例ID
|
||||
range: 1-10
|
||||
- field: lib
|
||||
note: 用例库ID
|
||||
range: 1-3
|
||||
- field: module
|
||||
note: 模块ID
|
||||
range: 1-5
|
||||
- field: title
|
||||
note: 用例标题
|
||||
range: 'Test Case {1-10}'
|
||||
- field: type
|
||||
note: 用例类型
|
||||
range: 'feature{3},performance{3},interface{2},unit{2}'
|
||||
- field: pri
|
||||
note: 优先级
|
||||
range: 1-4
|
||||
- field: status
|
||||
note: 状态
|
||||
range: 'normal{6},wait{2},blocked{2}'
|
||||
- field: openedBy
|
||||
note: 创建者
|
||||
range: 'admin{5},user1{3},user2{2}'
|
||||
- field: lastEditedBy
|
||||
note: 最后编辑者
|
||||
range: 'admin{4},user1{3},user2{3}'
|
||||
- field: openedDate
|
||||
note: 创建日期
|
||||
range: '2023-01-01 10:00:00{5},2023-01-02 10:00:00{3},2023-01-03 10:00:00{2}'
|
||||
- field: lastRunDate
|
||||
note: 最后运行日期
|
||||
range: '2023-01-05 10:00:00{5},0000-00-00 00:00:00{3},2023-01-06 10:00:00{2}'
|
||||
- field: stage
|
||||
note: 适用阶段
|
||||
range: 'unittest{3},feature{4},integration{2},system{1}'
|
||||
- field: linkCase
|
||||
note: 关联用例
|
||||
range: ''{6},1,2{2},2,3{2}'
|
||||
- field: stepDesc
|
||||
note: 步骤描述
|
||||
range: ''{5},Step 1. Do something{3},Step 1. First step{2}'
|
||||
- field: stepExpect
|
||||
note: 预期结果
|
||||
range: ''{5},Expect 1. Should work{3},Expect 1. Success{2}'
|
||||
Reference in New Issue
Block a user