From 2f111de3adf707ad2945f7b756e87223c899e749 Mon Sep 17 00:00:00 2001 From: liugang Date: Sun, 7 Sep 2025 08:17:21 +0800 Subject: [PATCH] + [misc] Add unit tests for biModel::validateSql() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/bi/test/lib/bi.unittest.class.php | 16 +++++++++++++++ module/bi/test/model/validatesql.php | 26 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 module/bi/test/model/validatesql.php diff --git a/module/bi/test/lib/bi.unittest.class.php b/module/bi/test/lib/bi.unittest.class.php index 68ecbc0436..c15c1f0adc 100644 --- a/module/bi/test/lib/bi.unittest.class.php +++ b/module/bi/test/lib/bi.unittest.class.php @@ -729,4 +729,20 @@ class biTest return $result; } + + /** + * Test validateSql method. + * + * @param string $sql + * @param string $driver + * @access public + * @return mixed + */ + public function validateSqlTest($sql, $driver = 'mysql') + { + $result = $this->objectModel->validateSql($sql, $driver); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/bi/test/model/validatesql.php b/module/bi/test/model/validatesql.php new file mode 100755 index 0000000000..26bba2b9a1 --- /dev/null +++ b/module/bi/test/model/validatesql.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +validateSqlTest('SELECT id, account FROM zt_user LIMIT 1')) && p() && e('1'); // 正常简单SELECT语句 +r($biTest->validateSqlTest('')) && p() && e('查询为空。'); // 空SQL语句 +r($biTest->validateSqlTest('SELECT * FROM nonexistent_table')) && p() && e('~Table.*doesn.*t exist~'); // 语法错误的SQL语句 +r($biTest->validateSqlTest('SELECT id as duplicate, account as duplicate FROM zt_user')) && p() && e('~字段名重复~'); // 包含重复字段的SQL语句 +r($biTest->validateSqlTest('INSERT INTO zt_user (account) VALUES ("test")')) && p() && e('~You have an error in your SQL syntax~'); // 非SELECT语句 \ No newline at end of file