+ [misc] Add unit tests for caselibZen::processLinkCaseForExport() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:09:51 +08:00
co-authored by Claude
parent be285387c8
commit b6a70fdd2c
2 changed files with 93 additions and 0 deletions
@@ -1229,4 +1229,50 @@ class caselibTest
return $case;
}
/**
* Test processLinkCaseForExport method.
*
* @param object $case
* @param string $type
* @access public
* @return mixed
*/
public function processLinkCaseForExportTest(object $case, string $type = 'case')
{
$zen = initReference('caselib');
$method = $zen->getMethod('processLinkCaseForExport');
$zenInstance = $zen->newInstance();
// 执行方法
$method->invoke($zenInstance, $case);
if(dao::isError()) return dao::getError();
if($type == 'linkCase') return $case->linkCase ?? '';
if($type == 'linkCase_length') return strlen($case->linkCase ?? '');
if($type == 'has_linkCase') return isset($case->linkCase) && !empty($case->linkCase) ? 1 : 0;
if($type == 'linkCase_count') return substr_count($case->linkCase ?? '', '; ') + 1;
if($type == 'has_semicolon') return strpos($case->linkCase ?? '', '; ') !== false ? 1 : 0;
if($type == 'has_newlines') return strpos($case->linkCase ?? '', "\n") !== false ? 1 : 0;
if($type == 'first_linkCase') {
$linkCases = explode('; ', $case->linkCase ?? '');
return !empty($linkCases) ? trim($linkCases[0]) : '';
}
if($type == 'last_linkCase') {
$linkCases = explode('; ', $case->linkCase ?? '');
return !empty($linkCases) ? trim(end($linkCases)) : '';
}
if($type == 'linkCase_parts_count') {
if(empty($case->linkCase)) return 0;
return count(explode('; ', $case->linkCase));
}
if($type == 'has_id_format') {
$linkCase = $case->linkCase ?? '';
return preg_match('/\(#\d+\)/', $linkCase) ? 1 : 0;
}
if($type == 'is_empty') return empty($case->linkCase) ? 1 : 0;
return $case;
}
}
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env php
<?php
/**
title=测试 caselibZen::processLinkCaseForExport();
timeout=0
cid=0
- 步骤1:单个ID @123
- 步骤2:多个ID包含分号 @1
- 步骤3:空值 @1
- 步骤4:无效ID @abc
- 步骤5:包含空格的ID数量 @3
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/caselib.unittest.class.php';
// 2. 用户登录(选择合适角色)
su('admin');
// 3. 创建测试实例(变量名与模块名一致)
$caselibTest = new caselibTest();
// 4. 🔴 强制要求:必须包含至少5个测试步骤
$case1 = new stdclass();
$case1->linkCase = '123';
r($caselibTest->processLinkCaseForExportTest($case1, 'linkCase')) && p() && e('123'); // 步骤1:单个ID
$case2 = new stdclass();
$case2->linkCase = '123,456,789';
r($caselibTest->processLinkCaseForExportTest($case2, 'has_semicolon')) && p() && e('1'); // 步骤2:多个ID包含分号
$case3 = new stdclass();
$case3->linkCase = '';
r($caselibTest->processLinkCaseForExportTest($case3, 'is_empty')) && p() && e('1'); // 步骤3:空值
$case4 = new stdclass();
$case4->linkCase = 'abc';
r($caselibTest->processLinkCaseForExportTest($case4, 'linkCase')) && p() && e('abc'); // 步骤4:无效ID
$case5 = new stdclass();
$case5->linkCase = '123, abc, 456';
r($caselibTest->processLinkCaseForExportTest($case5, 'linkCase_parts_count')) && p() && e('3'); // 步骤5:包含空格的ID数量