+ [misc] Add unit tests for kanbanTao::updateColumnParent() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1811,4 +1811,95 @@ class kanbanTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test addChildColumnCell method.
|
||||
*
|
||||
* @param int $columnID
|
||||
* @param int $childColumnID
|
||||
* @param int $i
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function addChildColumnCellTest($columnID, $childColumnID, $i = 0)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 记录操作前的单元格数量
|
||||
$beforeCount = $tester->dao->select('COUNT(1) as count')->from(TABLE_KANBANCELL)->where('`column`')->eq($childColumnID)->fetch('count');
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('addChildColumnCell');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->objectTao, $columnID, $childColumnID, $i);
|
||||
|
||||
if(dao::isError()) return array('success' => 0, 'error' => dao::getError());
|
||||
|
||||
// 记录操作后的单元格数量
|
||||
$afterCount = $tester->dao->select('COUNT(1) as count')->from(TABLE_KANBANCELL)->where('`column`')->eq($childColumnID)->fetch('count');
|
||||
|
||||
// 判断是否成功创建了新的单元格
|
||||
$success = $afterCount > $beforeCount ? 1 : 0;
|
||||
|
||||
return array('success' => $success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateColumnParent method.
|
||||
*
|
||||
* @param int $columnID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function updateColumnParentTest($columnID)
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 获取待测试的列信息
|
||||
$column = $tester->dao->select('*')->from(TABLE_KANBANCOLUMN)->where('id')->eq($columnID)->fetch();
|
||||
|
||||
if(!$column) return array('result' => 0, 'error' => 'Column not found');
|
||||
|
||||
// 如果列没有父列,方法应该正常执行不报错
|
||||
if($column->parent == 0)
|
||||
{
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('updateColumnParent');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($this->objectTao, $column);
|
||||
return array('result' => 0); // 正常执行,无变化
|
||||
}
|
||||
|
||||
// 记录调用前的同父列子列数量
|
||||
$siblingCount = $tester->dao->select('COUNT(1) AS count')->from(TABLE_KANBANCOLUMN)
|
||||
->where('parent')->eq($column->parent)
|
||||
->andWhere('id')->ne($column->id)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('archived')->eq('0')
|
||||
->fetch('count');
|
||||
|
||||
// 调用被测试的方法
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('updateColumnParent');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$method->invoke($this->objectTao, $column);
|
||||
|
||||
if(dao::isError()) return array('result' => 0, 'error' => dao::getError());
|
||||
|
||||
// 获取父列的当前parent值
|
||||
$parentColumn = $tester->dao->select('*')->from(TABLE_KANBANCOLUMN)->where('id')->eq($column->parent)->fetch();
|
||||
$currentParent = $parentColumn ? $parentColumn->parent : -1;
|
||||
|
||||
// 判断结果:如果没有其他兄弟列,父列的parent应该被重置为0
|
||||
if($siblingCount == 0 && $currentParent == 0) {
|
||||
return array('result' => 1); // 正确重置
|
||||
} elseif($siblingCount > 0 && $currentParent != 0) {
|
||||
return array('result' => 0); // 正确保持不变
|
||||
} else {
|
||||
return array('result' => 0); // 其他情况
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 kanbanTao::updateColumnParent();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:删除父列1的唯一子列3后,父列1的parent重置为0属性result @1
|
||||
- 步骤2:删除父列2的一个子列4,但父列2还有子列5,不重置属性result @0
|
||||
- 步骤3:没有父列的情况,正常处理属性result @0
|
||||
- 步骤4:删除父列2的一个子列5,父列2还有子列4,不重置属性result @0
|
||||
- 步骤5:删除父列7的唯一子列8后,父列7的parent重置为0属性result @1
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/kanban.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备 - 使用默认数据
|
||||
zenData('kanbancolumn')->gen(50);
|
||||
|
||||
// 3. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 手动插入测试需要的特定数据
|
||||
global $tester;
|
||||
$tester->dao->delete()->from(TABLE_KANBANCOLUMN)->exec();
|
||||
|
||||
// 插入测试数据:父列和子列的关系
|
||||
// 情况1:父列1有1个子列3,删除子列3后父列1应该被重置parent=0
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 1, 'parent' => 10, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '父列1', 'color' => 'blue', 'limit' => -1, 'order' => 1, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 情况2:父列2有2个子列4、5,删除其中一个后父列2不应该重置
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 2, 'parent' => 20, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '父列2', 'color' => 'red', 'limit' => -1, 'order' => 2, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 子列3:父列1的唯一子列
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 3, 'parent' => 1, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '子列1-1', 'color' => 'green', 'limit' => -1, 'order' => 3, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 子列4:父列2的第一个子列
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 4, 'parent' => 2, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '子列2-1', 'color' => 'blue', 'limit' => -1, 'order' => 4, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 子列5:父列2的第二个子列
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 5, 'parent' => 2, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '子列2-2', 'color' => 'red', 'limit' => -1, 'order' => 5, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 独立列:没有父列
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 6, 'parent' => 0, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '无父列', 'color' => 'green', 'limit' => -1, 'order' => 6, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 父列3:有1个子列7,用于第二轮测试
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 7, 'parent' => 30, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '父列3', 'color' => 'yellow', 'limit' => -1, 'order' => 7, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 子列8:父列3的唯一子列
|
||||
$tester->dao->insert(TABLE_KANBANCOLUMN)->data(array(
|
||||
'id' => 8, 'parent' => 7, 'type' => 'column', 'region' => 1, 'group' => 1, 'name' => '子列3-1', 'color' => 'purple', 'limit' => -1, 'order' => 8, 'archived' => '0', 'deleted' => '0'
|
||||
))->exec();
|
||||
|
||||
// 4. 创建测试实例(变量名与模块名一致)
|
||||
$kanbanTest = new kanbanTest();
|
||||
|
||||
// 5. 强制要求:必须包含至少5个测试步骤
|
||||
r($kanbanTest->updateColumnParentTest(3)) && p('result') && e('1'); // 步骤1:删除父列1的唯一子列3后,父列1的parent重置为0
|
||||
r($kanbanTest->updateColumnParentTest(4)) && p('result') && e('0'); // 步骤2:删除父列2的一个子列4,但父列2还有子列5,不重置
|
||||
r($kanbanTest->updateColumnParentTest(6)) && p('result') && e('0'); // 步骤3:没有父列的情况,正常处理
|
||||
r($kanbanTest->updateColumnParentTest(5)) && p('result') && e('0'); // 步骤4:删除父列2的一个子列5,父列2还有子列4,不重置
|
||||
r($kanbanTest->updateColumnParentTest(8)) && p('result') && e('1'); // 步骤5:删除父列7的唯一子列8后,父列7的parent重置为0
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: kanbancolumn表数据定义
|
||||
desc: 用于测试updateColumnParent方法的看板列数据
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 列ID
|
||||
range: 1-20
|
||||
|
||||
- field: parent
|
||||
note: 父列ID
|
||||
range: 0{5}, 1{3}, 2{3}, 3{2}, 4{2}, 5{5}
|
||||
|
||||
- field: type
|
||||
note: 列类型
|
||||
range: column{15}, backlog{5}
|
||||
|
||||
- field: region
|
||||
note: 区域ID
|
||||
range: 1{10}, 2{10}
|
||||
|
||||
- field: group
|
||||
note: 分组ID
|
||||
range: 1{10}, 2{10}
|
||||
|
||||
- field: name
|
||||
note: 列名称
|
||||
range: 待处理{5}, 进行中{5}, 已完成{5}, 测试列{5}
|
||||
|
||||
- field: color
|
||||
note: 列颜色
|
||||
range: blue{10}, red{5}, green{5}
|
||||
|
||||
- field: limit
|
||||
note: 列限制数
|
||||
range: -1{15}, 5{3}, 10{2}
|
||||
|
||||
- field: order
|
||||
note: 排序号
|
||||
range: 1-20
|
||||
|
||||
- field: archived
|
||||
note: 是否归档
|
||||
range: 0{18}, 1{2}
|
||||
|
||||
- field: deleted
|
||||
note: 是否删除
|
||||
range: 0{18}, 1{2}
|
||||
Reference in New Issue
Block a user