diff --git a/module/screen/model.php b/module/screen/model.php index 9d5ba47a3e..e4403f941f 100755 --- a/module/screen/model.php +++ b/module/screen/model.php @@ -787,13 +787,14 @@ class screenModel extends model */ public function setDefaultByDate(array &$filter): void { - $filter['default'] = null; + $filter['default'] = $filter['default'] ?? null; if(isset($filter['default'])) { extract($filter['default']); - if(empty($begin) || empty($end)) $filter['default'] = empty($begin) ? strtotime($end) * 1000 : strtotime($begin) * 1000; - if(!empty($begin) || !empty($end)) $filter['default'] = array(strtotime($begin) * 1000, strtotime($end) * 1000); + if(empty($begin) || empty($end)) $filter['default'] = empty($begin) ? strtotime($end) * 1000 : strtotime($begin) * 1000; + if(!empty($begin) && !empty($end)) $filter['default'] = array(strtotime($begin) * 1000, strtotime($end) * 1000); + if(empty($begin) && empty($end)) $filter['default'] = null; } } diff --git a/module/screen/test/model/getchartfilters.php b/module/screen/test/model/getchartfilters.php new file mode 100644 index 0000000000..b8c4852bc7 --- /dev/null +++ b/module/screen/test/model/getchartfilters.php @@ -0,0 +1,96 @@ +#!/usr/bin/env php +getByID(); +cid=1 +pid=1 + +当from为query时,type为date时,default应该为当前周一的日期,检查是否生成了正确的时间。 >> 1701014400000 +当from为query时,type为select时,options应该为用户列表,检查是否生成了正确的用户列表。 >> admin +当from不存在,type为date并且default不存在的时候,生成default应该为null,检查是否生成了正确的default值。 >> 0 +当from不存在,type为date并且default存在的时候,生成default应该为default的值,检查是否生成了正确的default值。 >> 1672502400000,1672588800000 +当from不存在,type为date并且default存在的时候,生成default应该为default的值,检查是否生成了正确的default值。 >> 1672502400000 +当from不存在,type为select时,options应该为用户列表,检查是否生成了正确的用户列表。 >> admin + +*/ + +$screen = new screenTest(); + +$chart = new stdclass(); +$filters = array( + 'from' => 'query', + 'type' => 'date', + 'default' => '$MONDAY' +); +$chart->filters = json_encode(array($filters)); +$chart->fields = json_encode(array()); + +$chart1 = new stdclass(); +$filters = array( + 'from' => 'query', + 'type' => 'select', + 'typeOption' => 'user' +); +$chart1->filters = json_encode(array($filters)); +$chart1->fields = json_encode(array()); + +$chart2 = new stdclass(); +$filters = array('type' => 'date'); +$chart2->filters = json_encode(array($filters)); +$chart2->fields = json_encode(array()); + +$chart3 = new stdclass(); +$filters = array( + 'type' => 'date', + 'default' => array( + 'begin' => '2023-01-01', + 'end' => '2023-01-02' + ) +); +$chart3->filters = json_encode(array($filters)); +$chart3->fields = json_encode(array()); + +$chart4 = new stdclass(); +$filters = array( + 'type' => 'select', + 'field' => 'user' +); +$chart4->filters = json_encode(array($filters)); +$fields = array( + 'user' => array( + 'type' => 'user', + 'object' => '', + 'field' => 'account' + ) +); +$chart4->fields = json_encode($fields); +$chart4->sql = ''; + +$chart5 = new stdclass(); +$filters = array( + 'type' => 'date', + 'default' => array('begin' => '2023-01-01', 'end' => '') +); +$chart5->filters = json_encode(array($filters)); +$chart5->fields = json_encode(array()); + +$time = date('Y-m-d', time() - (date('N') - 1) * 24 * 3600); +r($screen->getChartFiltersTest($chart)) && p('0:default') && e('1701014400000'); //当from为query时,type为date时,default应该为当前周一的日期,检查是否生成了正确的时间。 + +$result = $screen->getChartFiltersTest($chart1); +r($result[0]['options']) && p('0:value') && e('admin'); //当from为query时,type为select时,options应该为用户列表,检查是否生成了正确的用户列表。 + +r($screen->getChartFiltersTest($chart2)) && p('0:default') && e('~~'); //当from不存在,type为date并且default不存在的时候,生成default应该为null,检查是否生成了正确的default值。 + +$result = $screen->getChartFiltersTest($chart3); +r($result[0]['default']) && p('0,1') && e('1672502400000,1672588800000'); //当from不存在,type为date并且default存在的时候,生成default应该为default的值,检查是否生成了正确的default值。 + +$result = $screen->getChartFiltersTest($chart5); +r($result) && p('0:default') && e('1672502400000'); //当from不存在,type为date并且default存在的时候,生成default应该为default的值,检查是否生成了正确的default值。 + +$result = $screen->getChartFiltersTest($chart4); +r($result[0]['options']) && p('0:value') && e('admin'); //当from不存在,type为select时,options应该为用户列表,检查是否生成了正确的用户列表。 diff --git a/module/screen/test/screen.class.php b/module/screen/test/screen.class.php index 8cac781bfc..aaf8028000 100644 --- a/module/screen/test/screen.class.php +++ b/module/screen/test/screen.class.php @@ -54,6 +54,14 @@ class screenTest $tester->dbh->exec(file_get_contents($sqlFile)); } + /** + * 获取所有组件。 + * Get all components. + * + * @param array $filters + * @access public + * @return array + */ public function getAllComponent(array $filters = array()) { if(!empty($this->componentList)) @@ -91,7 +99,15 @@ class screenTest }); } - public function completeComponent($component) + /** + * 补充组件信息。 + * Supplement component information. + * + * @param object $component + * @access public + * @return array + */ + public function completeComponent($component): array { if(isset($component->key) && $component->key === 'Select') return array(null, $component); $chartID = zget($component->chartConfig, 'sourceID', ''); @@ -113,15 +129,37 @@ class screenTest * @param array $filters * @param object $component * @access public - * @return array + * @return void */ - public function completeComponentTest(object $chart, string $type, array $filters, object $component) + public function completeComponentTest(object $chart, string $type, array $filters, object $component): void { - return $this->objectModel->completeComponent($chart, $type, $filters, $component); + $this->objectModel->completeComponent($chart, $type, $filters, $component); } - public function getChartOptionTest(object $chart, object $component) + /** + * 测试getChartOption。 + * Test getChartOption. + * + * @param object $chart + * @param object $component + * @access public + * @return void + */ + public function getChartOptionTest(object $chart, object $component): void { - return $this->objectModel->getChartOption($chart, $component, array()); + $this->objectModel->getChartOption($chart, $component, array()); + } + + /** + * 测试getChartFilters。 + * Test getChartFilters. + * + * @param object $chart + * @access public + * @return void + */ + public function getChartFiltersTest(object $chart): array + { + return $this->objectModel->getChartFilters($chart); } }