+ [misc] Add unit tests for pivotTao::getAllProductsIDAndName() 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:44 +08:00
co-authored by Claude
parent 26259cd2ce
commit b2d316c471
3 changed files with 192 additions and 0 deletions
@@ -1534,4 +1534,23 @@ class pivotTest
return $result;
}
/**
* Test getAllProductsIDAndName method.
*
* @access public
* @return array
*/
public function getAllProductsIDAndNameTest(): array
{
// 使用反射访问protected方法
$reflection = new ReflectionClass($this->objectTao);
$method = $reflection->getMethod('getAllProductsIDAndName');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao);
if(dao::isError()) return dao::getError();
return $result;
}
}
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env php
<?php
/**
title=测试 pivotTao::getAllProductsIDAndName();
timeout=0
cid=0
- 步骤1:正常情况获取所有产品ID和名称 @1
- 步骤2:验证第1个产品名称属性1 @产品A
- 步骤3:验证第2个产品名称属性2 @产品B
- 步骤4:验证第3个产品名称属性3 @产品C
- 步骤5:验证未删除产品数量为8个 @8
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/pivot.unittest.class.php';
// 2. zendata数据准备(根据需要配置)
$table = zenData('product');
$table->id->range('1-10');
$table->name->range('产品A,产品B,产品C,产品D,产品E,产品F,产品G,产品H,产品I,产品J');
$table->code->range('PRODA,PRODB,PRODC,PRODD,PRODE,PRODF,PRODG,PRODH,PRODI,PRODJ');
$table->status->range('normal{8},closed{2}');
$table->deleted->range('0{8},1{2}');
$table->shadow->range('0');
$table->gen(10);
// 3. 用户登录(选择合适角色)
su('admin');
// 4. 创建测试实例(变量名与模块名一致)
$pivotTest = new pivotTest();
// 5. 强制要求:必须包含至少5个测试步骤
r(is_array($pivotTest->getAllProductsIDAndNameTest())) && p() && e('1'); // 步骤1:正常情况获取所有产品ID和名称
r($pivotTest->getAllProductsIDAndNameTest()) && p('1') && e('产品A'); // 步骤2:验证第1个产品名称
r($pivotTest->getAllProductsIDAndNameTest()) && p('2') && e('产品B'); // 步骤3:验证第2个产品名称
r($pivotTest->getAllProductsIDAndNameTest()) && p('3') && e('产品C'); // 步骤4:验证第3个产品名称
r(count($pivotTest->getAllProductsIDAndNameTest())) && p() && e('8'); // 步骤5:验证未删除产品数量为8个
@@ -0,0 +1,130 @@
---
title: 产品数据用于测试getAllProductsIDAndName方法
desc: 包含正常、已删除、shadow产品的测试数据
fields:
- field: id
note: 产品ID
range: 1-10
prefix: ""
postfix: ""
- field: program
note: 项目集ID
range: 0-5
prefix: ""
postfix: ""
- field: name
note: 产品名称
range: '产品A,产品B,产品C,测试产品D,已删除产品E,Shadow产品F,正常产品G,特殊字符产品H,空白产品I,最后产品J'
prefix: ""
postfix: ""
- field: code
note: 产品代码
range: 'PRODA,PRODB,PRODC,PRODD,PRODE,PRODF,PRODG,PRODH,PRODI,PRODJ'
prefix: ""
postfix: ""
- field: shadow
note: 是否shadow产品
range: '0{8},1{2}'
prefix: ""
postfix: ""
- field: bind
note: 是否绑定
range: '0{9},1{1}'
prefix: ""
postfix: ""
- field: line
note: 产品线ID
range: 0-3
prefix: ""
postfix: ""
- field: type
note: 产品类型
range: 'normal{8},branch{2}'
prefix: ""
postfix: ""
- field: status
note: 产品状态
range: 'normal{6},closed{3},developing{1}'
prefix: ""
postfix: ""
- field: subStatus
note: 子状态
range: '{8},[]{2}'
prefix: ""
postfix: ""
- field: desc
note: 产品描述
range: '产品描述{5},[]{5}'
prefix: ""
postfix: ""
- field: PO
note: 产品经理
range: 'admin{3},user1{3},user2{2},[]{2}'
prefix: ""
postfix: ""
- field: QD
note: 测试经理
range: 'admin{2},user1{2},user2{2},[]{4}'
prefix: ""
postfix: ""
- field: RD
note: 发布经理
range: 'admin{2},user1{2},user2{2},[]{4}'
prefix: ""
postfix: ""
- field: feedback
note: 反馈负责人
range: '[]{10}'
prefix: ""
postfix: ""
- field: ticket
note: 工单负责人
range: '[]{10}'
prefix: ""
postfix: ""
- field: workflowGroup
note: 工作流组
range: 0{10}
prefix: ""
postfix: ""
- field: acl
note: 访问控制
range: 'open{6},private{2},custom{2}'
prefix: ""
postfix: ""
- field: groups
note: 分组
range: '[]{10}'
prefix: ""
postfix: ""
- field: whitelist
note: 白名单
range: '[]{10}'
prefix: ""
postfix: ""
- field: createdBy
note: 创建者
range: 'admin{5},user1{3},user2{2}'
prefix: ""
postfix: ""
- field: createdDate
note: 创建时间
range: '2023-01-01 10:00:00-2023-12-31 18:00:00'
prefix: ""
postfix: ""
- field: editedBy
note: 编辑者
range: 'admin{4},user1{3},user2{2},[]{1}'
prefix: ""
postfix: ""
- field: editedDate
note: 编辑时间
range: '2023-01-02 10:00:00-2023-12-31 18:00:00'
prefix: ""
postfix: ""
- field: deleted
note: 是否删除
range: '0{8},1{2}'
prefix: ""
postfix: ""