* [misc] Enhance unit tests for dataviewModel::genTreeOptions() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:15:51 +08:00
co-authored by Claude
parent ac8263bccd
commit f41d58bbd6
2 changed files with 50 additions and 8 deletions
@@ -117,4 +117,21 @@ class dataviewTest
return $result;
}
/**
* Test genTreeOptions method.
*
* @param object $moduleTree
* @param array $values
* @param array $paths
* @access public
* @return mixed
*/
public function genTreeOptionsTest(&$moduleTree, $values, $paths)
{
$this->objectModel->genTreeOptions($moduleTree, $values, $paths);
if(dao::isError()) return dao::getError();
return $moduleTree;
}
}
+33 -8
View File
@@ -1,20 +1,45 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
su('admin');
/**
title=测试 dataviewModel::genTreeOptions();
timeout=0
cid=1
cid=0
- 获取treeOptions。 @0
- 执行dataviewTest模块的genTreeOptionsTest方法,参数是$tree1, array 第children条的0:title属性 @Root Node
- 执行dataviewTest模块的genTreeOptionsTest方法,参数是$tree2, array 第children条的0:children:0:children:0:title属性 @Level 3
- 执行dataviewTest模块的genTreeOptionsTest方法,参数是$tree3, array 第children条的0:children:0:title属性 @New Node
- 执行dataviewTest模块的genTreeOptionsTest方法,参数是$tree4, array 第children条的0:title属性 @Branch 1
- 执行dataviewTest模块的genTreeOptionsTest方法,参数是$tree4, array 第children条的1:title属性 @Branch 2
- 执行dataviewTest模块的genTreeOptionsTest方法,参数是$tree5, array 第children条的0:children:0:value属性 @b
*/
global $tester;
$tester->loadModel('dataview');
$dataview = new stdclass();
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/dataview.unittest.class.php';
r($tester->dataview->genTreeOptions($dataview, array('aa' => '1', 'bb' => '2'), array('aa', 'bb'))) && p() && e('0'); //获取treeOptions。
su('admin');
$dataviewTest = new dataviewTest();
$tree1 = new stdclass();
r($dataviewTest->genTreeOptionsTest($tree1, array('root' => 'Root Node'), array('root'))) && p('children:0:title') && e('Root Node');
$tree2 = new stdclass();
r($dataviewTest->genTreeOptionsTest($tree2, array('level1' => 'Level 1', 'level2' => 'Level 2', 'level3' => 'Level 3'), array('level1', 'level2', 'level3'))) && p('children:0:children:0:children:0:title') && e('Level 3');
$tree3 = new stdclass();
$tree3->children = array();
$existingChild = new stdclass();
$existingChild->title = 'Existing Node';
$existingChild->value = 'existing';
$tree3->children[] = $existingChild;
r($dataviewTest->genTreeOptionsTest($tree3, array('existing' => 'Existing Node', 'new' => 'New Node'), array('existing', 'new'))) && p('children:0:children:0:title') && e('New Node');
$tree4 = new stdclass();
r($dataviewTest->genTreeOptionsTest($tree4, array('branch1' => 'Branch 1', 'branch2' => 'Branch 2'), array('branch1'))) && p('children:0:title') && e('Branch 1');
r($dataviewTest->genTreeOptionsTest($tree4, array('branch1' => 'Branch 1', 'branch2' => 'Branch 2'), array('branch2'))) && p('children:1:title') && e('Branch 2');
$tree5 = new stdclass();
r($dataviewTest->genTreeOptionsTest($tree5, array('a' => 'Node A', 'b' => 'Node B', 'c' => 'Node C'), array('a', 'b'))) && p('children:0:children:0:value') && e('b');