From 344f3cfa87c99ed18823da013bbc9241d30a241c Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 24 Sep 2025 00:29:57 +0800 Subject: [PATCH] * [misc] Enhance unit tests for commonTao::queryListForPreAndNext() 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 --- .../common/test/lib/common.unittest.class.php | 16 ++++ .../test/tao/querylistforpreandnext.php | 81 ++++++++++++++----- 2 files changed, 77 insertions(+), 20 deletions(-) mode change 100644 => 100755 module/common/test/tao/querylistforpreandnext.php diff --git a/module/common/test/lib/common.unittest.class.php b/module/common/test/lib/common.unittest.class.php index a81315ab73..2fb4eac302 100644 --- a/module/common/test/lib/common.unittest.class.php +++ b/module/common/test/lib/common.unittest.class.php @@ -2819,4 +2819,20 @@ class commonTest // 返回结果 return $app->user; } + + /** + * Test queryListForPreAndNext method. + * + * @param string $type + * @param string $sql + * @access public + * @return mixed + */ + public function queryListForPreAndNextTest($type = '', $sql = '') + { + $result = $this->objectTao->queryListForPreAndNext($type, $sql); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/common/test/tao/querylistforpreandnext.php b/module/common/test/tao/querylistforpreandnext.php old mode 100644 new mode 100755 index 4e40df4422..448aa87b61 --- a/module/common/test/tao/querylistforpreandnext.php +++ b/module/common/test/tao/querylistforpreandnext.php @@ -1,35 +1,76 @@ #!/usr/bin/env php gen(10); /** -title=测试 commonTao->queryListForPreAndNext(); -cid=1 -pid=1 +title=测试 commonTao::queryListForPreAndNext(); +timeout=0 +cid=0 + +- 执行$list['objectList'] @1,2,3,4,5 + +- 执行$emptyList['objectList'] @5 +- 执行$newList['objectList'] @1,2,3 + +- 执行$testcaseList['idkey'] @case +- 执行$boundaryList['objectList'] @9,10 */ +// 1. 导入依赖 +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/common.unittest.class.php'; + +// 2. zendata数据准备 +$storyTable = zenData('story'); +$storyTable->id->range('1-10'); +$storyTable->title->range('Story %d'); +$storyTable->status->range('active{6},draft{2},closed{2}'); +$storyTable->type->range('story{8},requirement{2}'); +$storyTable->gen(10); + +$testcaseTable = zenData('case'); +$testcaseTable->id->range('1-5'); +$testcaseTable->title->range('Test case %d'); +$testcaseTable->status->range('normal{3},blocked{2}'); +$testcaseTable->type->range('feature{3},performance{2}'); +$testcaseTable->gen(5); + +// 3. 用户登录 +su('admin'); + +// 4. 加载common模块 global $tester; $tester->loadModel('common'); -$_SESSION['storyQueryCondition'] = 'id < 5'; -$_SESSION['storyOnlyCondition'] = true; -$sql = $tester->common->getPreAndNextSQL('story'); -$list = $tester->common->queryListForPreAndNext('story', $sql); -r(implode('|', $list['objectList'])) && p() && e('1|2|3|4'); +// 5. 测试步骤(必须包含至少5个测试步骤) +// 步骤1:正常查询story对象列表 $_SESSION['storyQueryCondition'] = 'id <= 5'; -$sql = $tester->common->getPreAndNextSQL('story'); +$_SESSION['storyOnlyCondition'] = true; +$sql = 'SELECT * FROM `zt_story` WHERE id <= 5 ORDER BY id'; $list = $tester->common->queryListForPreAndNext('story', $sql); -r(implode('|', $list['objectList'])) && p() && e('1|2|3|4|5'); +r(implode(',', $list['objectList'])) && p() && e('1,2,3,4,5'); -$tester->common->app->tab = 'my'; -$tester->common->app->moduleName = 'product'; -$tester->common->app->methodName = 'browse'; -$_SESSION['app-my']['storyBrowseList'] = array('sql' => 'SELECT * FROM `zt_story` WHERE id <= 5', 'idkey' => 'id', 'objectList' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4)); -$list = $tester->common->queryListForPreAndNext('story', $sql); -r(implode('|', $list['objectList'])) && p() && e('1|2|3|4'); +// 步骤2:测试空SQL查询情况 +$emptyList = $tester->common->queryListForPreAndNext('story', ''); +r(count($emptyList['objectList'])) && p() && e('5'); + +// 步骤3:测试会话缓存命中情况(SQL不同时重新查询) +$_SESSION['storyQueryCondition'] = 'id <= 3'; +$differentSql = 'SELECT * FROM `zt_story` WHERE id <= 3 ORDER BY id'; +$newList = $tester->common->queryListForPreAndNext('story', $differentSql); +r(implode(',', $newList['objectList'])) && p() && e('1,2,3'); + +// 步骤4:测试testcase类型的特殊键处理 +$_SESSION['testcaseOnlyCondition'] = false; +$testcaseSQL = 'SELECT *, id as `case` FROM `zt_case` WHERE id <= 3'; +$testcaseList = $tester->common->queryListForPreAndNext('testcase', $testcaseSQL); +r($testcaseList['idkey']) && p() && e('case'); + +// 步骤5:测试复杂查询条件的边界值 +$_SESSION['storyQueryCondition'] = 'id > 8'; +$_SESSION['storyOnlyCondition'] = true; +$boundarySql = 'SELECT * FROM `zt_story` WHERE id > 8 ORDER BY id'; +$boundaryList = $tester->common->queryListForPreAndNext('story', $boundarySql); +r(implode(',', $boundaryList['objectList'])) && p() && e('9,10'); \ No newline at end of file