* [misc] Enhance unit tests for pivotModel::getConnectSQL() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:16:26 +08:00
co-authored by Claude
parent bdecf651ff
commit 5896b93daf
2 changed files with 34 additions and 19 deletions
@@ -2482,4 +2482,19 @@ class pivotTest
return (object)array('url' => $url, 'method' => 'post', 'data' => $data);
}
/**
* Test getConnectSQL method.
*
* @param array $filters
* @access public
* @return string
*/
public function getConnectSQLTest(array $filters): string
{
$result = $this->objectModel->getConnectSQL($filters);
if(dao::isError()) return dao::getError();
return $result;
}
}
+19 -19
View File
@@ -3,11 +3,11 @@
/**
title=测试 pivotModel->getConnectSQL().
title=测试 pivotModel->getConnectSQL();
timeout=0
cid=1
cid=0
- 根据过滤条件获取连接sql,判断生成的sql是否正确。 @1
- 空过滤条件输入 @
*/
@@ -16,23 +16,23 @@ include dirname(__FILE__, 2) . '/lib/pivot.unittest.class.php';
$pivot = new pivotTest();
$filters = array(
'name' => array(
'field' => 'name',
'operator' => 'sum',
'value' => 'xxx',
),
'score' => array(
'field' => 'score',
'operator' => 'sum',
'value' => 'yyy',
),
);
r($pivot->getConnectSQLTest(array(
'name' => array('field' => 'name', 'operator' => '=', 'value' => "'test'"),
'score' => array('field' => 'score', 'operator' => '>', 'value' => '100')
))) && p() && e(' where tt.`name` = \'test\' and tt.`score` > 100'); // 正常过滤条件生成SQL
$groupList = 'id,name';
r($pivot->getConnectSQLTest(array())) && p() && e(''); // 空过滤条件输入
$result = $pivot->getConnectSQL($filters);
r($pivot->getConnectSQLTest(array(
0 => array('from' => 'query', 'field' => 'name')
))) && p() && e(''); // 包含from键的过滤条件
$condition = $result == ' where tt.`name` sum xxx and tt.`score` sum yyy';
r($pivot->getConnectSQLTest(array(
'status' => array('field' => 'status', 'operator' => 'IN', 'value' => "('active','done')")
))) && p() && e(' where tt.`status` IN (\'active\',\'done\')'); // 单个过滤条件测试
r($condition) && p() && e('1'); //根据过滤条件获取连接sql,判断生成的sql是否正确。
r($pivot->getConnectSQLTest(array(
'id' => array('field' => 'id', 'operator' => '!=', 'value' => '0'),
'type' => array('field' => 'type', 'operator' => 'LIKE', 'value' => "'%bug%'"),
'priority' => array('field' => 'priority', 'operator' => 'BETWEEN', 'value' => '1 AND 3')
))) && p() && e(' where tt.`id` != 0 and tt.`type` LIKE \'%bug%\' and tt.`priority` BETWEEN 1 AND 3'); // 多种操作符的过滤条件