* Unit test of the getbysql method of action module.

This commit is contained in:
wangxuepeng
2023-09-18 08:21:10 +00:00
parent cfdcaedd94
commit 0274b33e5f
2 changed files with 9 additions and 6 deletions
+3 -2
View File
@@ -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)
+6 -4
View File
@@ -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的动作个数
r($action->getBySQLTest($sql4)) && p() && e('2'); // 查询action = opend的动作个数
r($action->getBySQLTest($sql5)) && p() && e('25'); // 查询read = 0的动作个数