From dd92c2b9cd39c3dcf129e738f2f450f977cc72aa Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 22 Sep 2025 12:08:27 +0800 Subject: [PATCH] * [misc] Enhance unit tests for deptModel::getChildDepts() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/dept/test/lib/dept.unittest.class.php | 7 +++- module/dept/test/model/getchilddepts.php | 32 ++++++++++++------- .../test/model/yaml/dept_getchilddepts.yaml | 21 ++++++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 module/dept/test/model/yaml/dept_getchilddepts.yaml diff --git a/module/dept/test/lib/dept.unittest.class.php b/module/dept/test/lib/dept.unittest.class.php index b74877c6ce..23261cc009 100644 --- a/module/dept/test/lib/dept.unittest.class.php +++ b/module/dept/test/lib/dept.unittest.class.php @@ -423,14 +423,19 @@ class deptTest * Test getChildDepts method. * * @param mixed $rootDeptID + * @param string $type * @access public * @return mixed */ - public function getChildDeptsTest($rootDeptID = null) + public function getChildDeptsTest($rootDeptID = null, $type = '') { $result = $this->objectModel->getChildDepts((int)$rootDeptID); if(dao::isError()) return dao::getError(); + if($type == 'count') return count($result); + if($type == 'empty') return empty($result); + if($type == 'array') return is_array($result); + return $result; } } diff --git a/module/dept/test/model/getchilddepts.php b/module/dept/test/model/getchilddepts.php index 2198e76596..01759aec44 100755 --- a/module/dept/test/model/getchilddepts.php +++ b/module/dept/test/model/getchilddepts.php @@ -1,23 +1,31 @@ #!/usr/bin/env php loadYaml('dept')->gen(50)->fixPath(); /** -title=测试 deptModel->getChildDepts(); +title=测试 deptModel::getChildDepts(); timeout=0 -cid=1 +cid=0 -- 测试获取ID为6的部门名称第6条的name属性 @开发部26 -- 测试获取父ID为2且ID为8的部门名称第8条的name属性 @一级部门8 +- 测试步骤1:获取所有部门,验证总数量 @50 +- 测试步骤2:获取ID为1的部门,验证部门名称第1条的name属性 @产品部1 +- 测试步骤3:获取不存在部门的子部门,返回所有部门 @50 +- 测试步骤4:验证部门层级信息第3条的parent属性 @0 +- 测试步骤5:验证特定父部门下子部门数量 @7 */ -global $tester; -$tester->loadModel('dept'); +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/dept.unittest.class.php'; -r($tester->dept->getChildDepts(0)) && p('6:name') && e('开发部26'); // 测试获取ID为6的部门名称 -r($tester->dept->getChildDepts(2)) && p('8:name') && e('一级部门8'); // 测试获取父ID为2且ID为8的部门名称 +zenData('dept')->loadYaml('dept')->gen(50)->fixPath(); + +su('admin'); + +$deptTest = new deptTest(); + +r($deptTest->getChildDeptsTest(0, 'count')) && p() && e('50'); // 测试步骤1:获取所有部门,验证总数量 +r($deptTest->getChildDeptsTest(1)) && p('1:name') && e('产品部1'); // 测试步骤2:获取ID为1的部门,验证部门名称 +r($deptTest->getChildDeptsTest(999, 'count')) && p() && e('50'); // 测试步骤3:获取不存在部门的子部门,返回所有部门 +r($deptTest->getChildDeptsTest(3)) && p('3:parent') && e('0'); // 测试步骤4:验证部门层级信息 +r($deptTest->getChildDeptsTest(2, 'count')) && p() && e('7'); // 测试步骤5:验证特定父部门下子部门数量 \ No newline at end of file diff --git a/module/dept/test/model/yaml/dept_getchilddepts.yaml b/module/dept/test/model/yaml/dept_getchilddepts.yaml new file mode 100644 index 0000000000..5be1673a49 --- /dev/null +++ b/module/dept/test/model/yaml/dept_getchilddepts.yaml @@ -0,0 +1,21 @@ +--- +title: 部门表测试数据 - getChildDepts方法 +desc: 包含多层级部门结构的完整测试数据 +author: Claude +version: "1.0" + +fields: +- field: id + range: 1-15 +- field: name + range: 总部,研发中心,产品部,开发部,测试部,开发一组,开发二组,测试一组,测试二组,前端组,后端组,移动端组,数据分析组,市场部,销售部 +- field: parent + range: 0,0,0,1,1,4,4,5,5,4,4,4,1,2,2 +- field: path + range: ',1,',',2,',',3,',',1,4,',',1,5,',',1,4,6,',',1,4,7,',',1,5,8,',',1,5,9,',',1,4,10,',',1,4,11,',',1,4,12,',',1,13,',',2,14,',',2,15,' +- field: grade + range: 1,1,1,2,2,3,3,3,3,3,3,3,2,2,2 +- field: order + range: 10,20,30,10,20,10,20,10,20,30,40,50,30,10,20 +- field: manager + range: admin,user1,user2,user3,user4,dev1,dev2,test1,test2,fe1,be1,mobile1,data1,market1,sale1 \ No newline at end of file