From d1608ab2898075f01e41bfbc94996c699b6776cf Mon Sep 17 00:00:00 2001 From: tianshujie Date: Wed, 16 Apr 2025 14:54:25 +0800 Subject: [PATCH] * [ci,done,0.3h] add unit test for updatedocorder method. --- module/doc/test/lib/doc.unittest.class.php | 16 ++++++++++++++++ module/doc/test/model/updatedocorder.php | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/module/doc/test/lib/doc.unittest.class.php b/module/doc/test/lib/doc.unittest.class.php index 8bb3fe14b6..88383b86d5 100644 --- a/module/doc/test/lib/doc.unittest.class.php +++ b/module/doc/test/lib/doc.unittest.class.php @@ -1457,4 +1457,20 @@ class docTest $deleted = $this->objectModel->dao->select('deleted')->from($table)->where('id')->eq($id)->fetch('deleted'); return $deleted == 1; } + + /** + * 更新文档顺序。 + * Update doc order. + * + * @param array $sortedIdList + * @access public + * @return array|bool + */ + public function updateDocOrderTest(array $sortedIdList): array|bool + { + $this->objectModel->updateDocOrder($sortedIdList); + + if(dao::isError()) return dao::getError(); + return $this->objectModel->dao->select('id,`order`')->from(TABLE_DOC)->where('id')->in($sortedIdList)->fetchPairs(); + } } diff --git a/module/doc/test/model/updatedocorder.php b/module/doc/test/model/updatedocorder.php index 36c9bc0936..bfa6d542b4 100644 --- a/module/doc/test/model/updatedocorder.php +++ b/module/doc/test/model/updatedocorder.php @@ -23,6 +23,20 @@ include dirname(__FILE__, 2) . '/lib/doc.unittest.class.php'; $docData = zenData('doc')->loadYaml('doc'); $docData->order->range('1-10'); $docData->gen(10); - zenData('user')->gen(5); su('admin'); + +$sortedIdList = array(2, 5, 1, 10, 7, 9, 8, 3, 4, 6); + +$docTester = new docTest(); +$sortedDocList = $docTester->updateDocOrderTest($sortedIdList); +r($sortedDocList[1]) && p() && e('3'); // 检查ID为1的文档顺序 +r($sortedDocList[2]) && p() && e('1'); // 检查ID为2的文档顺序 +r($sortedDocList[3]) && p() && e('8'); // 检查ID为3的文档顺序 +r($sortedDocList[4]) && p() && e('9'); // 检查ID为4的文档顺序 +r($sortedDocList[5]) && p() && e('2'); // 检查ID为5的文档顺序 +r($sortedDocList[6]) && p() && e('10'); // 检查ID为6的文档顺序 +r($sortedDocList[7]) && p() && e('5'); // 检查ID为7的文档顺序 +r($sortedDocList[8]) && p() && e('7'); // 检查ID为8的文档顺序 +r($sortedDocList[9]) && p() && e('6'); // 检查ID为9的文档顺序 +r($sortedDocList[10]) && p() && e('4'); // 检查ID为10的文档顺序