* [test] add unit test for zai model.

This commit is contained in:
sunhao
2025-10-09 13:34:49 +08:00
parent fbca23b468
commit 5c619fa030
2 changed files with 163 additions and 0 deletions
@@ -130,4 +130,53 @@ class zaiTest
{
return zaiModel::getSyncTypes();
}
/**
* Test convertDemandToMarkdown static method.
*
* @param object $demand
* @access public
* @return array
*/
public function convertDemandToMarkdownTest($demand)
{
global $tester;
try {$tester->loadLang('demand');} catch (Exception $e) {}
if(!isset($tester->lang->demand))
{
$tester->lang->demand = new stdClass();
$tester->lang->demand->common = '需求';
$tester->lang->demand->legendBasicInfo = '基本信息';
$tester->lang->demand->spec = '规格';
$tester->lang->demand->verify = '验证';
$tester->lang->demand->status = '状态';
$tester->lang->demand->stage = '阶段';
$tester->lang->demand->pri = '优先级';
$tester->lang->demand->version = '版本';
$tester->lang->demand->category = '分类';
$tester->lang->demand->source = '来源';
$tester->lang->demand->product = '产品';
$tester->lang->demand->parent = '父需求';
$tester->lang->demand->module = '模块';
$tester->lang->demand->keywords = '关键词';
$tester->lang->demand->assignedTo = '指派给';
$tester->lang->demand->assignedDate = '指派日期';
$tester->lang->demand->createdBy = '创建者';
$tester->lang->demand->createdDate = '创建日期';
$tester->lang->demand->changedBy = '修改者';
$tester->lang->demand->changedDate = '修改日期';
$tester->lang->demand->closedBy = '关闭者';
$tester->lang->demand->closedDate = '关闭日期';
$tester->lang->demand->closedReason = '关闭原因';
$tester->lang->demand->submitedBy = '提交者';
$tester->lang->demand->distributedBy = '分发者';
$tester->lang->demand->distributedDate = '分发日期';
$tester->lang->demand->statusList = array('draft' => '草稿', 'active' => '激活', 'closed' => '关闭', 'changing' => '变更', 'reviewing' => '评审');
$tester->lang->demand->stageList = array('wait' => '待办', 'planned' => '计划', 'doing' => '进行中', 'done' => '已完成', 'canceled' => '已取消');
$tester->lang->demand->priList = array('1' => '低', '2' => '中', '3' => '高', '4' => '紧急');
$tester->lang->demand->categoryList = array('feature' => '功能', 'interface' => '接口', 'performance' => '性能', 'security' => '安全', 'other' => '其他');
$tester->lang->demand->sourceList = array('customer' => '客户', 'user' => '用户', 'po' => '产品负责人', 'market' => '市场', 'service' => '服务', 'operation' => '运营', 'support' => '支持', 'competitor' => '竞争对手', 'partner' => '合作伙伴', 'dev' => '开发', 'tester' => '测试', 'bug' => '缺陷', 'forum' => '论坛', 'other' => '其他');
}
return zaiModel::convertDemandToMarkdown($demand);
}
}
@@ -0,0 +1,114 @@
#!/usr/bin/env php
<?php
/**
title=测试 zaiModel::convertDemandToMarkdown();
timeout=0
cid=0
- 测试转换完整的需求对象
- 属性id @1
- 属性title
- 属性content
- 属性attrs
- 测试转换没有spec的需求对象
- 属性id @2
- 属性title
- 测试验证Markdown内容包含需求信息
- 属性content ~需求 #1
- 测试验证属性设置正确
- 属性attrs
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/zai.unittest.class.php';
zenData('demand')->gen(0);
zenData('demandspec')->gen(0);
su('admin');
global $tester;
$zai = new zaiTest();
// 创建完整的需求对象
$demand1 = new stdClass();
$demand1->id = 1;
$demand1->title = '测试需求1 - 用户管理功能';
$demand1->status = 'active';
$demand1->stage = 'planned';
$demand1->pri = 3;
$demand1->version = 1;
$demand1->category = 'feature';
$demand1->source = 'customer';
$demand1->product = 1;
$demand1->parent = 0;
$demand1->module = 1;
$demand1->keywords = '用户,管理,功能';
$demand1->assignedTo = 'admin';
$demand1->assignedDate = '2023-01-01 10:00:00';
$demand1->createdBy = 'admin';
$demand1->createdDate = '2023-01-01 09:00:00';
$demand1->changedBy = '';
$demand1->changedDate = '';
$demand1->closedBy = '';
$demand1->closedDate = '';
$demand1->closedReason = '';
$demand1->submitedBy = 'admin';
$demand1->distributedBy = '';
$demand1->distributedDate = '';
// 创建没有spec的需求对象
$demand2 = new stdClass();
$demand2->id = 2;
$demand2->title = '测试需求2 - 报表功能';
$demand2->status = 'draft';
$demand2->stage = 'wait';
$demand2->pri = 2;
$demand2->version = 1;
$demand2->category = 'interface';
$demand2->source = 'po';
$demand2->product = 1;
$demand2->parent = 0;
$demand2->module = 2;
$demand2->keywords = '报表,统计';
$demand2->assignedTo = '';
$demand2->assignedDate = '';
$demand2->createdBy = 'admin';
$demand2->createdDate = '2023-01-03 09:00:00';
$demand2->changedBy = '';
$demand2->changedDate = '';
$demand2->closedBy = '';
$demand2->closedDate = '';
$demand2->closedReason = '';
$demand2->submitedBy = 'admin';
$demand2->distributedBy = '';
$demand2->distributedDate = '';
/* 测试转换需求对象 */
$result1 = $zai->convertDemandToMarkdownTest($demand1);
r($result1) && p('id') && e('1'); // 测试转换完整的需求对象
$result2 = $zai->convertDemandToMarkdownTest($demand2);
r($result2) && p('id') && e('2'); // 测试转换第二个需求对象
/* 测试验证基本属性 */
r(isset($result1['attrs'])) && p() && e('1'); // 测试验证返回了attrs属性
r(isset($result2['attrs'])) && p() && e('1'); // 测试验证第二个对象返回了attrs属性
/* 测试验证内容生成 */
r(isset($result1['content']) && !empty($result1['content'])) && p() && e('1'); // 测试验证生成了content
r(isset($result2['content'])) && p() && e('1'); // 测试验证第二个对象生成了content
/* 测试验证标题生成 */
r(isset($result1['title']) && !empty($result1['title'])) && p() && e('1'); // 测试验证生成了title
r(isset($result2['title'])) && p() && e('1'); // 测试验证第二个对象生成了title
/* 验证返回数组结构正确 */
r(is_array($result1)) && p() && e('1'); // 测试返回数组结构
r(is_array($result2)) && p() && e('1'); // 测试第二个对象返回数组结构
/* 验证具体的属性值 */
r($result1['attrs']['product']) && p() && e('1'); // 测试验证产品属性
r($result1['attrs']['status']) && p() && e('active'); // 测试验证状态属性