From 3b08231decf39b74dc6e4e9c81d230a6667fc077 Mon Sep 17 00:00:00 2001 From: liugang Date: Sun, 7 Sep 2025 04:42:31 +0800 Subject: [PATCH] + [misc] Add unit tests for biModel::preparePivotObject() 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 | 15 ++++ module/bi/test/model/preparepivotobject.php | 78 +++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100755 module/bi/test/model/preparepivotobject.php diff --git a/module/bi/test/lib/bi.unittest.class.php b/module/bi/test/lib/bi.unittest.class.php index eb87f624c0..41fbfb489c 100644 --- a/module/bi/test/lib/bi.unittest.class.php +++ b/module/bi/test/lib/bi.unittest.class.php @@ -428,4 +428,19 @@ class biTest return $result; } + + /** + * Test preparePivotObject method. + * + * @param mixed $pivot + * @access public + * @return mixed + */ + public function preparePivotObjectTest($pivot) + { + $result = $this->objectModel->preparePivotObject($pivot); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/bi/test/model/preparepivotobject.php b/module/bi/test/model/preparepivotobject.php new file mode 100755 index 0000000000..16a3b89ff8 --- /dev/null +++ b/module/bi/test/model/preparepivotobject.php @@ -0,0 +1,78 @@ +#!/usr/bin/env php + 1, + 'version' => '1.0', + 'sql' => 'SELECT * FROM zt_user', + 'name' => array('zh-cn' => '用户统计', 'en' => 'User Statistics') +); +r(count($bi->preparePivotObjectTest($basicPivot))) && p('') && e('3'); //检查返回数组长度 + +// 步骤2:包含所有可选字段的pivot对象处理 +$fullPivot = array( + 'id' => 2, + 'version' => '2.0', + 'sql' => 'SELECT account, realname FROM zt_user', + 'name' => array('zh-cn' => '完整用户', 'en' => 'Full User'), + 'desc' => array('zh-cn' => '描述', 'en' => 'Description'), + 'settings' => array('pageSize' => 20), + 'filters' => array('status' => 'active'), + 'fields' => array('account', 'realname'), + 'langs' => array('zh-cn' => '中文'), + 'vars' => array('limit' => 100), + 'driver' => 'mysql' +); +r($bi->preparePivotObjectTest($fullPivot)[1]->name) && p('') && e('{"zh-cn":"完整用户","en":"Full User"}'); //检查pivotSpec的name字段 + +// 步骤3:数组输入转换为对象 +$arrayPivot = array( + 'id' => 3, + 'version' => '1.5', + 'sql' => 'SELECT id FROM zt_task', + 'name' => array('zh-cn' => '任务列表') +); +r($bi->preparePivotObjectTest($arrayPivot)[0]->id) && p('') && e('3'); //检查转换后pivot对象的id + +// 步骤4:不包含可选字段的最小pivot对象 +$minimalPivot = array( + 'id' => 4, + 'version' => '1.0', + 'sql' => 'SELECT * FROM zt_bug', + 'name' => array('zh-cn' => '缺陷统计') +); +r($bi->preparePivotObjectTest($minimalPivot)[1]->settings) && p('') && e('~~'); //检查默认settings为null + +// 步骤5:包含drills字段的pivot对象处理 +$pivotWithDrills = array( + 'id' => 5, + 'version' => '1.0', + 'sql' => 'SELECT * FROM zt_story', + 'name' => array('zh-cn' => '需求统计'), + 'drills' => array( + array('field' => 'status', 'type' => 'group'), + array('field' => 'stage', 'type' => 'filter') + ) +); +r(count($bi->preparePivotObjectTest($pivotWithDrills)[2])) && p('') && e('2'); //检查drills数组长度 \ No newline at end of file