* Add unit test for pivot.

This commit is contained in:
wangxuepeng
2023-12-23 17:34:09 +08:00
parent 8baa509d94
commit 0be25dffcc
4 changed files with 91 additions and 4 deletions
+2 -2
View File
@@ -917,7 +917,7 @@ class pivotModel extends model
* @access private
* @return array
*/
private function processGroupRows(array $columns, string $sql, array $filters, array $groups, string $groupList, array $fields, string $showColTotal, array &$cols ,array $langs): array
public function processGroupRows(array $columns, string $sql, array $filters, array $groups, string $groupList, array $fields, string $showColTotal, array &$cols ,array $langs): array
{
list($sql, $connectSQL, $groupSQL, $orderSQL) = $this->initSql($sql, $filters, $groupList);
$number = 0;
@@ -1017,7 +1017,7 @@ class pivotModel extends model
* @access private
* @return array
*/
public function getMergeData(array $columnRows, array &$groupsRow)
private function getMergeData(array $columnRows, array &$groupsRow)
{
$rowIndex = 0;
foreach($columnRows as $key => $row)
+2 -2
View File
@@ -3,7 +3,7 @@
/**
title=测试 pivotModel->processDataVar();
title=测试 pivotModel->initGroups().
timeout=0
cid=1
@@ -27,4 +27,4 @@ $condition2 = isset($result[1]) && $result[1] == 'tt.`一级项目集`,tt.`项
$condition3 = isset($result[2]) && $result[2][0]->name == '一级项目集' && $result[2][0]->isGroup = true;
$condition4 = isset($result[2]) && $result[2][1]->name == '项目名称' && $result[2][1]->isGroup = true;
r($condition1 && $condition2 && $condition3 && $condition4) && p('') && e(1); //测试生成的分组信息是否正确。
r($condition1 && $condition2 && $condition3 && $condition4) && p('') && e(1); //测试生成的分组信息是否正确。
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env php
<?php
/**
title=测试 pivotModel->initGroups().
timeout=0
cid=1
- 测试生成的表头信息是否正确。
- @一级项目集
- 属性8 @单位时间交付需求规模数6
- 测试生成的数据是否正确。
- 属性3 @3
- 属性4 @3
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/pivot.class.php';
zdTable('user')->gen(20);
zdTable('bug')->config('bug')->gen(20);
zdTable('product')->config('product')->gen(10);
zdTable('module')->gen(10);
zdTable('case')->gen(10);
zdTable('project')->config('project_gensheet')->gen(20);
zdTable('product')->gen(10);
zdTable('task')->gen(10);
$pivotTest = new pivotTest();
$cols = array();
list($pivot, $sql, $filterFormat, $fields, $langs) = $pivotTest->getPivotSheetConfig(1001);
list($groups, $groupList, $groupCol) = $pivotTest->initGroups($fields, $pivot->settings, $langs);
$groupRows = $pivotTest->processGroupRowsTest($pivot->settings['columns'], $sql, $filterFormat, $groups, $groupList, $fields, 'show', $cols, $langs);
$check = true;
$list = get_object_vars($groupRows[0]);
r(array_keys($list)) && p('0,8') && e('一级项目集,单位时间交付需求规模数6'); //测试生成的表头信息是否正确。
r(array_values($list)) && p('3,4') && e('3,3'); //测试生成的数据是否正确。
+44
View File
@@ -2,6 +2,8 @@
declare(strict_types=1);
class pivotTest
{
private $objectModel;
public function __construct()
{
global $tester;
@@ -50,4 +52,46 @@ class pivotTest
$sqlFile = $appPath . 'test/data/pivot.sql';
$tester->dbh->exec(file_get_contents($sqlFile));
}
/**
* 获取透视表配置相关信息。
* Get pivot table config info.
*
* @param int $pivotID
* @access public
* @return array
*/
public function getPivotSheetConfig(int $pivotID): array
{
$pivot = $this->objectModel->getByID($pivotID);
list($sql, $filterFormat) = $this->objectModel->getFilterFormat($pivot->sql, $pivot->filters);
$tables = $this->loadModel('chart')->getTables($sql);
$sql = $tables['sql'];
$fields = json_decode(json_encode($pivot->fieldSettings), true);
$langs = json_decode($pivot->langs, true) ?? array();
return array($pivot, $sql, $filterFormat,$fields, $langs);
}
/**
* 测试 processGroupRows。
* Test processGroupRows.
*
* @param array $columns
* @param string $sql
* @param array $filterFormat
* @param array $groups
* @param string $groupList
* @param array $fieldS
* @param string $showColTotal
* @param array $cols
* @param array $langs
* @access public
* @return array
*/
public function processGroupRowsTest(array $columns, string $sql, array $filterFormat, array $groups, string $groupList, array $fields, string $showColTotal, array &$cols, array $langs): array
{
return $this->objectModel->processGroupRows($columns, $sql, $filterFormat, $groups, $groupList, $fields, $showColTotal, $cols, $langs);
}
}