diff --git a/module/dataview/test/lib/dataview.unittest.class.php b/module/dataview/test/lib/dataview.unittest.class.php index 359f0618ca..fb8818cfa9 100644 --- a/module/dataview/test/lib/dataview.unittest.class.php +++ b/module/dataview/test/lib/dataview.unittest.class.php @@ -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; + } } \ No newline at end of file diff --git a/module/dataview/test/model/gentreeoptions.php b/module/dataview/test/model/gentreeoptions.php index 7b5ea5c797..945812a462 100755 --- a/module/dataview/test/model/gentreeoptions.php +++ b/module/dataview/test/model/gentreeoptions.php @@ -1,20 +1,45 @@ #!/usr/bin/env php 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'); \ No newline at end of file