ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilTreeTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  protected $backupGlobals = FALSE;
36 
37  protected function setUp()
38  {
39  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
40  ilUnitUtil::performInitialisation();
41  }
42 
43  public function testGetChild()
44  {
45  $tree = new ilTree(ROOT_FOLDER_ID);
46  $childs = $tree->getChilds(14); // Chat settings (contains public chat)
47 
48  $this->assertEquals(count($childs),1);
49  }
50 
56  public function testGetChildsByType()
57  {
58  $tree = new ilTree(ROOT_FOLDER_ID);
59  $childs = $tree->getChildsByType(9,'cals'); // only calendar settings
60 
61  $this->assertEquals(count($childs),1);
62  }
63 
69  public function testGetChildsByTypeFilter()
70  {
71  $tree = new ilTree(ROOT_FOLDER_ID);
72  $childs = $tree->getChildsByTypeFilter(9,array('cals','rolf')); // only calendar settings and role folder
73 
74  $this->assertEquals(count($childs),2);
75  }
76 
82  public function testGetSubTree()
83  {
84  $tree = new ilTree(ROOT_FOLDER_ID);
85 
86  $root = $tree->getNodeData(1);
87  $childs = $tree->getSubTree($root,false,'cals'); // only calendar settings
88 
89  $this->assertEquals(count($childs),1);
90 
91  }
92 
99  public function testGetPathIdsUsingNestedSet()
100  {
101  // This test leads to a fatal error, as getPathIdsUsingNestedSets is
102  // not defined on ilTree.
103  $this->assertTrue(false, "Testcase leads to fatal error.");
104 
105  $tree = new ilTree(ROOT_FOLDER_ID);
106  $ids = $tree->getPathIdsUsingNestedSets(24,9); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
107 
108  $this->assertEquals($ids,array(9,14,24));
109 
110  $tree = new ilTree(ROOT_FOLDER_ID);
111  $ids = $tree->getPathIdsUsingNestedSets(24); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
112 
113  $this->assertEquals($ids,array(1,9,14,24));
114  }
115 
122  public function testGetPathIds()
123  {
124  // This test leads to a fatal error, as getPathIdsUsingNestedSets and
125  // getPathIdsUsingAdjacencyMap are not defined on ilTree.
126  $this->assertTrue(false, "Testcase leads to fatal error.");
127 
128  $tree = new ilTree(ROOT_FOLDER_ID);
129  $ids_ns = $tree->getPathIdsUsingNestedSets(24);
130  $ids_al = $tree->getPathIdsUsingAdjacencyMap(24);
131 
132  $this->assertEquals($ids_ns,$ids_al);
133  }
134 
140  public function testGetNodePath()
141  {
142  $tree = new ilTree(ROOT_FOLDER_ID);
143  $res = $tree->getNodePath(1,29);
144  }
145 
152  public function testMaxDepth()
153  {
154  $tree = new ilTree(ROOT_FOLDER_ID);
155  $tree->getMaximumDepth();
156  }
157 
164  public function testAllOthers()
165  {
166  $tree = new ilTree(ROOT_FOLDER_ID);
167  $d = $tree->getDepth(24);
168 
169  $this->assertEquals($d,4);
170 
171  $node = $tree->getNodeData(24);
172  $this->assertEquals($node['title'],'Public chat');
173 
174  $bool = $tree->isInTree(24);
175  $this->assertEquals($bool,true);
176 
177  $bool = $tree->isInTree(24242424);
178  $this->assertEquals($bool,false);
179 
180  /* ref_id 14 => obj_id 98 does not exist
181  $node = $tree->getParentNodeData(24);
182  $this->assertEquals($node['title'],'Chat-Server');
183  */
184 
185  $bool = $tree->isGrandChild(9,24);
186  $this->assertEquals($bool,1);
187 
188  /* see above
189  $node = $tree->getNodeDataByType('chac');
190  $this->assertEquals($node[0]['title'],'Chat-Server');
191  */
192 
193  $bool = $tree->isDeleted(24);
194  $this->assertEquals($bool,false);
195 
196  $id = $tree->getParentId(24);
197  $this->assertEquals($id,14);
198 
199  $lft = $tree->getLeftValue(24);
200  $this->assertEquals($lft,14);
201 
202  $seq = $tree->getChildSequenceNumber($tree->getNodeData(24));
203  $this->assertEquals($seq,1);
204 
205  $tree->getNodePath(9,1);
206 
207  $max_depth = $tree->getMaximumDepth();
208 
209  // Round trip
210  $tree = new ilTree(ROOT_FOLDER_ID);
211  $suc = $tree->fetchSuccessorNode(16); // cals
212  $cals = $tree->fetchPredecessorNode($suc['child']);
213  $this->assertEquals($cals['child'],16);
214  }
215 }
216 ?>
testAllOthers()
get path ids (adjacenca and nested set) IL_Init
Definition: ilTreeTest.php:164
for($col=0; $col< 50; $col++) $d
testGetChildsByType()
get childs by type IL_Init
Definition: ilTreeTest.php:56
testGetSubTree()
get childs by type filter IL_Init
Definition: ilTreeTest.php:82
testGetPathIdsUsingNestedSet()
get path ids using nested set IL_Init
Definition: ilTreeTest.php:99
testGetPathIds()
get path ids (adjacenca and nested set) IL_Init
Definition: ilTreeTest.php:122
testGetChildsByTypeFilter()
get childs by type filter IL_Init
Definition: ilTreeTest.php:69
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
testGetNodePath()
IL_Init
Definition: ilTreeTest.php:140
testMaxDepth()
get path ids (adjacenca and nested set) IL_Init
Definition: ilTreeTest.php:152
Unit tests for tree table.
Definition: ilTreeTest.php:33