* Add test file for the method of processChart.

This commit is contained in:
xieqiyu
2023-11-29 14:51:14 +08:00
parent 0607f3013a
commit 465cbcbfa9
2 changed files with 47 additions and 0 deletions
+25
View File
@@ -6,4 +6,29 @@ class chartTest
global $tester;
$this->objectModel = $tester->loadModel('chart');
}
/**
* 测试处理图表数据。
* Test process the data of the chart.
*
* @param string $testType
* @access public
* @return object
*/
public function processChartTest(string $testType): object
{
$chart = $this->objectModel->getByID(1018);
$chart->langs = '';
$chart->filters = '';
$chart->settings = '';
$chart->fields = '{"name":{"name":"\u9879\u76ee\u540d\u79f0","object":"project","field":"name","type":"string"},"closedDate":{"name":"\u5173\u95ed\u65e5\u671f","object":"project","field":"closedDate","type":"date"},"daterate":{"name":"daterate","object":"project","field":"daterate","type":"number"}}';
if($testType == 'sqlNull') $chart->sql = null;
if($testType == 'trimSQL') $chart->sql = "SELECT id FROM zt_project WHERE type='program' AND parent=0 AND deleted='0';";
if($testType == 'decodeLangs') $chart->langs = '{"name":{"zh-cn":"\u9879\u76ee\u540d\u79f0","zh-tw":"","en":"","de":"","fr":""}}';
if($testType == 'decodeFilters') $chart->filters = '[{"field":"closedDate","type":"date","name":"\u5173\u95ed\u65e5\u671f","default":{"begin":"","end":""}}]';
if($testType == 'decodeSettings') $chart->settings = '[{"type":"cluBarY","xaxis":[{"field":"name","name":"\u9879\u76ee\u540d\u79f0","group":""}],"yaxis":[{"field":"daterate","name":"daterate","valOrAgg":"sum"}]}]';
return $this->objectModel->processChart($chart);
}
}
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env php
<?php
/**
title=测试 chartModel::processChart();
cid=1
pid=1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/chart.class.php';
zdTable('module')->config('module')->gen(27);
zdTable('user')->gen(5);
su('admin');
$chart = new chartTest();
r($chart->processChartTest('sqlNull')) && p('sql') && e('~~'); //测试sql字段为null的情况
r($chart->processChartTest('decodeLangs')) && p('langs[name]:zh-cn') && e('项目名称'); //测试解密langs字段
r($chart->processChartTest('decodeFilters')) && p('filters[0]:field') && e('closedDate'); //测试解密filters字段
r($chart->processChartTest('decodeSettings')) && p('settings[0]:type') && e('cluBarY'); //测试解密settings字段