From 0274b33e5f082fd8fee3205fc7d95ca22bd6973e Mon Sep 17 00:00:00 2001 From: wangxuepeng Date: Mon, 18 Sep 2023 08:20:54 +0000 Subject: [PATCH] * Unit test of the getbysql method of action module. --- module/action/model.php | 5 +++-- module/action/test/model/getbysql.php | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/module/action/model.php b/module/action/model.php index 2ac8da17ba..31c3f54318 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -1278,6 +1278,7 @@ class actionModel extends model } /** + * 通过sql获取actions。 * Get actions by SQL. * * @param string $sql @@ -1286,12 +1287,12 @@ class actionModel extends model * @access public * @return array */ - public function getBySQL($sql, $orderBy, $pager = null) + public function getBySQL(string $sql, string $orderBy, object $pager = null): array { $actionCondition = $this->getActionCondition(); if(is_array($actionCondition)) return array(); - return $actions = $this->dao->select('*')->from(TABLE_ACTION) + return $this->dao->select('*')->from(TABLE_ACTION) ->where($sql) ->beginIF(!empty($actionCondition))->andWhere("($actionCondition)")->fi() ->orderBy($orderBy) diff --git a/module/action/test/model/getbysql.php b/module/action/test/model/getbysql.php index afade9b2a6..db577bfc11 100755 --- a/module/action/test/model/getbysql.php +++ b/module/action/test/model/getbysql.php @@ -4,6 +4,8 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/action.class.php'; su('admin'); +zdTable('action')->gen(50); + /** title=测试 actionModel->getBySQL(); @@ -26,8 +28,8 @@ $sql5 = "`read` = '0'"; $action = new actionTest(); -r($action->getBySQLTest($sql1)) && p() && e('12'); // 查询id like %1的动作个数 -r($action->getBySQLTest($sql2)) && p() && e('5'); // 查询objectType = product的动作个数 +r($action->getBySQLTest($sql1)) && p() && e('11'); // 查询id like %1的动作个数 +r($action->getBySQLTest($sql2)) && p() && e('3'); // 查询objectType = product的动作个数 r($action->getBySQLTest($sql3)) && p() && e('9'); // 查询objectID < 10的动作个数 -r($action->getBySQLTest($sql4)) && p() && e('3'); // 查询action = opend的动作个数 -r($action->getBySQLTest($sql5)) && p() && e('50'); // 查询read = 0的动作个数 \ No newline at end of file +r($action->getBySQLTest($sql4)) && p() && e('2'); // 查询action = opend的动作个数 +r($action->getBySQLTest($sql5)) && p() && e('25'); // 查询read = 0的动作个数