diff --git a/module/pivot/test/lib/pivot.unittest.class.php b/module/pivot/test/lib/pivot.unittest.class.php index dab2b527ee..c480574036 100644 --- a/module/pivot/test/lib/pivot.unittest.class.php +++ b/module/pivot/test/lib/pivot.unittest.class.php @@ -596,4 +596,19 @@ class pivotTest return $result; } + + /** + * Test flattenRow method. + * + * @param array $row + * @access public + * @return array + */ + public function flattenRowTest(array $row): array + { + $result = $this->objectModel->flattenRow($row); + if(dao::isError()) return dao::getError(); + + return $result; + } } \ No newline at end of file diff --git a/module/pivot/test/model/flattenrow.php b/module/pivot/test/model/flattenrow.php new file mode 100755 index 0000000000..3094057c93 --- /dev/null +++ b/module/pivot/test/model/flattenrow.php @@ -0,0 +1,69 @@ +#!/usr/bin/env php + 'admin', + 'status' => 'active', + 'count' => 10 +); +r($pivotTest->flattenRowTest($scalarRow)) && p('name:value;status:value;count:value') && e('admin;active;10'); + +// 测试步骤2:混合数据行处理(标量和带value键数据) +$mixedRow = array( + 'name' => 'user1', + 'total' => array('value' => 100, 'format' => 'number'), + 'status' => 'active' +); +r($pivotTest->flattenRowTest($mixedRow)) && p('name:value;total:value;status:value') && e('user1;100;active'); + +// 测试步骤3:复杂单元格数据处理(包含额外属性) +$complexRow = array( + 'project' => array('value' => 'Project A', 'color' => 'blue', 'link' => '/project/1'), + 'progress' => array('value' => 75, 'unit' => '%', 'style' => 'progress-bar'), + 'simple' => 'test' +); +r($pivotTest->flattenRowTest($complexRow)) && p('project:value;progress:value;simple:value') && e('Project A;75;test'); + +// 测试步骤4:空数据行处理 +$emptyRow = array(); +r($pivotTest->flattenRowTest($emptyRow)) && p() && e(0); + +// 测试步骤5:带有空值数据行处理 +$emptyValueRow = array( + 'field2' => '', + 'field3' => 0 +); +r($pivotTest->flattenRowTest($emptyValueRow)) && p('field2:value;field3:value') && e('~~;0'); \ No newline at end of file