From 87d7982a2d3d84dee0e9685325a34f2edb50bea1 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 24 Sep 2025 04:54:19 +0800 Subject: [PATCH] * [misc] Enhance unit tests for todoTao::getListBy() 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/todo/test/lib/todo.unittest.class.php | 26 +++++++++++ module/todo/test/tao/getlistby.php | 48 ++++++++++++-------- 2 files changed, 54 insertions(+), 20 deletions(-) mode change 100644 => 100755 module/todo/test/tao/getlistby.php diff --git a/module/todo/test/lib/todo.unittest.class.php b/module/todo/test/lib/todo.unittest.class.php index 7e5e36b225..634985fae3 100755 --- a/module/todo/test/lib/todo.unittest.class.php +++ b/module/todo/test/lib/todo.unittest.class.php @@ -653,4 +653,30 @@ class todoTest return $result; } + + /** + * Test getListBy method. + * + * @param string $type + * @param string $account + * @param string|array $status + * @param string $begin + * @param string $end + * @param int $limit + * @param string $orderBy + * @param object $pager + * @access public + * @return array + */ + public function getListByTest(string $type, string $account, array|string $status, string $begin, string $end, int $limit, string $orderBy, ?object $pager = null): array + { + $reflection = new ReflectionClass($this->objectTao); + $method = $reflection->getMethod('getListBy'); + $method->setAccessible(true); + + $result = $method->invoke($this->objectTao, $type, $account, $status, $begin, $end, $limit, $orderBy, $pager); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/todo/test/tao/getlistby.php b/module/todo/test/tao/getlistby.php old mode 100644 new mode 100755 index 645b6b3c19..66741d4cb4 --- a/module/todo/test/tao/getlistby.php +++ b/module/todo/test/tao/getlistby.php @@ -1,32 +1,40 @@ #!/usr/bin/env php loadYaml('getlistby')->gen(5); /** -title=测试 todoModel->getListBy(); -cid=1 -pid=0 +title=测试 todoTao::getListBy(); +timeout=0 +cid=0 + +- 步骤1:正常获取today类型待办列表 @1 +- 步骤2:获取指派给其他人的待办 @0 +- 步骤3:获取user1的待办 @1 +- 步骤4:按日期范围获取待办 @1 +- 步骤5:获取未完成状态待办 @1 +- 步骤6:限制返回数量为1 @1 +- 步骤7:测试其他用户的待办列表 @1 */ -global $tester; -$tester->loadModel('todo')->todoTao; +// 1. 导入依赖 +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/todo.unittest.class.php'; +// 2. zendata数据准备 +zenData('todo')->loadYaml('todo', false, 2)->gen(10); -$type = 'before'; // assignedtoother, cycle -$account = 'admin'; -$status = 'all'; // done,closed,wait,doing -$begin = '2021-02-03'; -$end = '2024-04-04'; -$limit = 5; -$orderBy = 'date_desc'; +// 3. 用户登录 +su('admin'); -$result = $tester->todo->getListBy($type, $account, $status, $begin, $end, $limit, $orderBy); +// 4. 创建测试实例 +$todoTest = new todoTest(); -r(count($result)) && p() && e('5'); //获取待办列表数量 -r($result[0]) && p('name,status') && e('待办5,doing'); //获取待办列表第1条的name和status +// 5. 测试步骤 +r(count($todoTest->getListByTest('today', 'admin', 'all', '2025-08-24', '2025-08-24', 0, 'date_desc'))) && p() && e('1'); // 步骤1:正常获取today类型待办列表 +r(count($todoTest->getListByTest('assignedtoother', 'admin', 'all', '', '', 0, 'date_desc'))) && p() && e('0'); // 步骤2:获取指派给其他人的待办 +r(count($todoTest->getListByTest('today', 'user1', 'all', '2025-08-25', '2025-08-25', 0, 'date_desc'))) && p() && e('1'); // 步骤3:获取user1的待办 +r(count($todoTest->getListByTest('today', 'admin', 'all', '2025-08-01', '2025-09-30', 0, 'date_desc'))) && p() && e('1'); // 步骤4:按日期范围获取待办 +r(count($todoTest->getListByTest('today', 'user1', 'undone', '2025-08-25', '2025-08-25', 0, 'date_desc'))) && p() && e('1'); // 步骤5:获取未完成状态待办 +r(count($todoTest->getListByTest('today', 'admin', 'all', '2025-08-01', '2025-09-30', 1, 'date_desc'))) && p() && e('1'); // 步骤6:限制返回数量为1 +r(count($todoTest->getListByTest('today', 'user2', 'all', '2025-08-26', '2025-08-26', 0, 'id_asc'))) && p() && e('1'); // 步骤7:测试其他用户的待办列表 \ No newline at end of file