* [ci,done,0.3h] add unit test for updatedocorder method.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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的文档顺序
|
||||
|
||||
Reference in New Issue
Block a user