+ [misc] Add unit tests for caselibZen::getExportCasesFields() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -970,4 +970,47 @@ class caselibTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getExportCasesFields method.
|
||||
*
|
||||
* @param array $postData
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return array|int|string
|
||||
*/
|
||||
public function getExportCasesFieldsTest(array $postData = array(), string $type = 'array')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 设置POST数据模拟
|
||||
if(!empty($postData['exportFields'])) {
|
||||
$_POST['exportFields'] = $postData['exportFields'];
|
||||
} else {
|
||||
unset($_POST['exportFields']);
|
||||
}
|
||||
|
||||
$zen = initReference('caselib');
|
||||
$method = $zen->getMethod('getExportCasesFields');
|
||||
$zenInstance = $zen->newInstance();
|
||||
|
||||
$result = $method->invoke($zenInstance);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
if($type == 'count') return count($result);
|
||||
if($type == 'keys') return array_keys($result);
|
||||
if($type == 'values') return array_values($result);
|
||||
if($type == 'first_key' && !empty($result)) return key($result);
|
||||
if($type == 'first_value' && !empty($result)) return reset($result);
|
||||
if($type == 'has_id') return isset($result['id']) ? 1 : 0;
|
||||
if($type == 'has_title') return isset($result['title']) ? 1 : 0;
|
||||
if($type == 'has_module') return isset($result['module']) ? 1 : 0;
|
||||
if($type == 'has_precondition') return isset($result['precondition']) ? 1 : 0;
|
||||
if($type == 'has_stepDesc') return isset($result['stepDesc']) ? 1 : 0;
|
||||
if($type == 'has_stepExpect') return isset($result['stepExpect']) ? 1 : 0;
|
||||
if($type == 'is_empty') return empty($result) ? 1 : 0;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 caselibZen::getExportCasesFields();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:测试默认配置字段数量 @19
|
||||
- 步骤2:测试默认配置包含id字段 @1
|
||||
- 步骤3:测试自定义字段列表 @3
|
||||
- 步骤4:测试自定义字段包含title @1
|
||||
- 步骤5:测试自定义字段不包含id @0
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/caselib.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备(此方法不依赖数据库数据,无需准备)
|
||||
|
||||
// 3. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 4. 创建测试实例(变量名与模块名一致)
|
||||
$caselibTest = new caselibTest();
|
||||
|
||||
// 5. 🔴 强制要求:必须包含至少5个测试步骤
|
||||
r($caselibTest->getExportCasesFieldsTest(array(), 'count')) && p() && e('19'); // 步骤1:测试默认配置字段数量
|
||||
r($caselibTest->getExportCasesFieldsTest(array(), 'has_id')) && p() && e('1'); // 步骤2:测试默认配置包含id字段
|
||||
r($caselibTest->getExportCasesFieldsTest(array('exportFields' => array('title', 'module', 'type')), 'count')) && p() && e('3'); // 步骤3:测试自定义字段列表
|
||||
r($caselibTest->getExportCasesFieldsTest(array('exportFields' => array('title', 'module', 'type')), 'has_title')) && p() && e('1'); // 步骤4:测试自定义字段包含title
|
||||
r($caselibTest->getExportCasesFieldsTest(array('exportFields' => array('title', 'module', 'type')), 'has_id')) && p() && e('0'); // 步骤5:测试自定义字段不包含id
|
||||
Reference in New Issue
Block a user