* [misc] Enhance unit tests for executionModel::buildTree() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,75 +2,176 @@
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/execution.unittest.class.php';
|
||||
|
||||
// 准备基础测试数据
|
||||
zenData('user')->gen(5);
|
||||
zenData('config')->gen(10);
|
||||
|
||||
// 准备权限组数据
|
||||
$group = zenData('group');
|
||||
$group->id->range('1-5');
|
||||
$group->name->range('管理员,开发,测试,产品,项目经理');
|
||||
$group->role->range('admin,dev,qa,po,pm');
|
||||
$group->gen(5);
|
||||
|
||||
// 准备用户组关系数据
|
||||
$userGroup = zenData('usergroup');
|
||||
$userGroup->account->range('admin,user1,user2,user3,user4');
|
||||
$userGroup->group->range('1,2,3,4,5');
|
||||
$userGroup->gen(5);
|
||||
|
||||
// 准备权限数据
|
||||
$groupPriv = zenData('grouppriv');
|
||||
$groupPriv->group->range('1{20},2{15},3{10}');
|
||||
$groupPriv->module->range('execution{15},task{10},story{10}');
|
||||
$groupPriv->method->range('treeTask{10},treeStory{5},browse{5},view{5}');
|
||||
$groupPriv->gen(35);
|
||||
|
||||
// 准备语言包数据
|
||||
$lang = zenData('lang');
|
||||
$lang->lang->range('zh-cn');
|
||||
$lang->module->range('task,story,requirement,epic,branch');
|
||||
$lang->section->range('common');
|
||||
$lang->key->range('common');
|
||||
$lang->value->range('任务,需求,需求,史诗,分支');
|
||||
$lang->gen(5);
|
||||
|
||||
su('admin');
|
||||
|
||||
$execution = zenData('project');
|
||||
$execution->id->range('1-5');
|
||||
$execution->name->range('项目1,项目2,迭代1,迭代2,迭代3');
|
||||
$execution->type->range('project{2},sprint,stage,kanban');
|
||||
$execution->status->range('doing');
|
||||
$execution->parent->range('0,0,1,1,2');
|
||||
$execution->project->range('0,0,1,1,2');
|
||||
$execution->grade->range('2{2},1{3}');
|
||||
$execution->openedVersion->range('18.0');
|
||||
$execution->path->range('1,2,`1,3`,`1,4`,`2,5`')->prefix(',')->postfix(',');
|
||||
$execution->begin->range('20230102 000000:0')->type('timestamp')->format('YY/MM/DD');
|
||||
$execution->end->range('20230212 000000:0')->type('timestamp')->format('YY/MM/DD');
|
||||
$execution->gen(5);
|
||||
|
||||
$task = zenData('task');
|
||||
$task->id->range('1-10');
|
||||
$task->name->range('1-10')->prefix('任务');
|
||||
$task->execution->range('3-5');
|
||||
$task->type->range('test,devel');
|
||||
$task->status->range('wait,doing');
|
||||
$task->estimate->range('1-10');
|
||||
$task->left->range('1-10');
|
||||
$task->module->range('1-10');
|
||||
$task->consumed->range('1-10');
|
||||
$task->gen(10);
|
||||
|
||||
$product = zenData('product');
|
||||
$product->id->range('1-3');
|
||||
$product->name->range('1-3')->prefix('产品');
|
||||
$product->code->range('1-3')->prefix('product');
|
||||
$product->type->range('normal');
|
||||
$product->status->range('normal');
|
||||
$product->gen(3);
|
||||
|
||||
$product = zenData('module');
|
||||
$product->id->range('1-10');
|
||||
$product->name->range('1-10')->prefix('模块');
|
||||
$product->root->range('3-5');
|
||||
$product->parent->range('0,1{9}');
|
||||
$product->type->range('task');
|
||||
$product->gen(10);
|
||||
|
||||
$branch = zenData('branch');
|
||||
$branch->id->range('1-10');
|
||||
$branch->product->range('1-3');
|
||||
$branch->gen(5);
|
||||
|
||||
$related = zenData('projectproduct');
|
||||
$related->project->range('3-5');
|
||||
$related->product->range('1-3');
|
||||
$related->branch->range('0-1');
|
||||
$related->gen(5);
|
||||
|
||||
/**
|
||||
|
||||
title=测试executionModel->buildTree();
|
||||
title=测试 executionModel::buildTree();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 空树数组输入测试返回空数组 >> 期望返回空数组
|
||||
- 单个任务节点构建验证className属性 >> 期望包含正确的CSS类名
|
||||
- 任务节点内容HTML结构验证 >> 期望包含任务标签和标题
|
||||
- product类型节点构建验证 >> 期望正确渲染产品节点
|
||||
- story类型节点构建验证 >> 期望正确渲染需求节点
|
||||
- requirement类型节点构建验证 >> 期望正确渲染需求节点
|
||||
- epic类型节点构建验证 >> 期望正确渲染史诗节点
|
||||
- branch类型节点构建验证 >> 期望正确渲染分支节点
|
||||
- 包含子节点的嵌套树结构验证 >> 期望正确处理递归子节点
|
||||
- 权限控制验证无权限用户访问 >> 期望普通用户无URL访问权限
|
||||
|
||||
*/
|
||||
|
||||
$execution = new executionTest();
|
||||
$executionIDList = array(0, 3);
|
||||
$executionTest = new executionTest();
|
||||
|
||||
r($execution->buildTreeTest($executionIDList[0])) && p() && e('0'); // 查询不存在的执行
|
||||
// 步骤1:空树数组输入测试
|
||||
r($executionTest->buildTreeTestDirect(array())) && p() && e('0');
|
||||
|
||||
$tree = $execution->buildTreeTest($executionIDList[1]);
|
||||
r(count($tree[0]['items'])) && p() && e('1'); // 查询存在的执行
|
||||
r($tree[0]) && p('content:html') && e("<span class=' title' title='模块1'>模块1</span>"); // 查询存在的执行
|
||||
// 步骤2:单个任务节点构建验证className属性
|
||||
$singleTask = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'task',
|
||||
'title' => '测试任务',
|
||||
'assignedTo' => 'admin',
|
||||
'avatar' => 'A',
|
||||
'avatarAccount' => 'admin',
|
||||
'parent' => 0,
|
||||
'isParent' => false
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($singleTask)) && p('0:className') && e('py-2 cursor-pointer task');
|
||||
|
||||
// 步骤3:任务节点内容HTML结构验证
|
||||
r($executionTest->buildTreeTestDirect($singleTask)) && p('0:content:html') && e('*tree-link*');
|
||||
|
||||
// 步骤4:product类型节点构建验证
|
||||
$productNode = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'product',
|
||||
'name' => '测试产品'
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($productNode)) && p('0:className') && e('py-2 cursor-pointer product');
|
||||
|
||||
// 步骤5:story类型节点构建验证
|
||||
$storyNode = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'story',
|
||||
'title' => '测试需求',
|
||||
'storyId' => 1,
|
||||
'grade' => 1,
|
||||
'assignedTo' => '',
|
||||
'avatar' => '',
|
||||
'avatarAccount' => ''
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($storyNode)) && p('0:className') && e('py-2 cursor-pointer story');
|
||||
|
||||
// 步骤6:requirement类型节点构建验证
|
||||
$requirementNode = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'requirement',
|
||||
'title' => '测试需求文档',
|
||||
'storyId' => 1,
|
||||
'grade' => 1,
|
||||
'assignedTo' => 'admin',
|
||||
'avatar' => 'A',
|
||||
'avatarAccount' => 'admin'
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($requirementNode)) && p('0:className') && e('py-2 cursor-pointer requirement');
|
||||
|
||||
// 步骤7:epic类型节点构建验证
|
||||
$epicNode = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'epic',
|
||||
'title' => '测试史诗',
|
||||
'storyId' => 1,
|
||||
'grade' => 1,
|
||||
'assignedTo' => 'admin',
|
||||
'avatar' => 'A',
|
||||
'avatarAccount' => 'admin'
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($epicNode)) && p('0:className') && e('py-2 cursor-pointer epic');
|
||||
|
||||
// 步骤8:branch类型节点构建验证
|
||||
$branchNode = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'branch',
|
||||
'name' => '测试分支'
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($branchNode)) && p('0:className') && e('py-2 cursor-pointer branch');
|
||||
|
||||
// 步骤9:包含子节点的嵌套树结构验证
|
||||
$nestedTree = array(
|
||||
(object)array(
|
||||
'id' => 1,
|
||||
'type' => 'task',
|
||||
'title' => '父任务',
|
||||
'assignedTo' => 'admin',
|
||||
'avatar' => 'A',
|
||||
'avatarAccount' => 'admin',
|
||||
'parent' => 0,
|
||||
'isParent' => true,
|
||||
'children' => array(
|
||||
(object)array(
|
||||
'id' => 2,
|
||||
'type' => 'task',
|
||||
'title' => '子任务',
|
||||
'assignedTo' => 'user1',
|
||||
'avatar' => 'U',
|
||||
'avatarAccount' => 'user1',
|
||||
'parent' => 1,
|
||||
'isParent' => false
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
r($executionTest->buildTreeTestDirect($nestedTree)) && p('0:items:0:className') && e('py-2 cursor-pointer task');
|
||||
|
||||
// 步骤10:权限控制验证无权限用户访问
|
||||
su('user2');
|
||||
r($executionTest->buildTreeTestDirect($singleTask)) && p('0:url') && e('');
|
||||
Reference in New Issue
Block a user