ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  $tree = new ilTree(ROOT_FOLDER_ID);
102  $ids = $tree->getPathIdsUsingNestedSets(24,9); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
103 
104  $this->assertEquals($ids,array(9,14,24));
105 
106  $tree = new ilTree(ROOT_FOLDER_ID);
107  $ids = $tree->getPathIdsUsingNestedSets(24); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
108 
109  $this->assertEquals($ids,array(1,9,14,24));
110 
111  }
112 
119  public function testGetPathIds()
120  {
121  $tree = new ilTree(ROOT_FOLDER_ID);
122  $ids_ns = $tree->getPathIdsUsingNestedSets(24);
123  $ids_al = $tree->getPathIdsUsingAdjacencyMap(24);
124 
125  $this->assertEquals($ids_ns,$ids_al);
126  }
127 
133  public function testGetNodePath()
134  {
135  $tree = new ilTree(ROOT_FOLDER_ID);
136  $res = $tree->getNodePath(1,29);
137  }
138 
145  public function testMaxDepth()
146  {
147  $tree = new ilTree(ROOT_FOLDER_ID);
148  $tree->getMaximumDepth();
149  }
150 
157  public function testAllOthers()
158  {
159  $tree = new ilTree(ROOT_FOLDER_ID);
160  $d = $tree->getDepth(24);
161 
162  $this->assertEquals($d,4);
163 
164  $node = $tree->getNodeData(24);
165  $this->assertEquals($node['title'],'Public chat');
166 
167  $bool = $tree->isInTree(24);
168  $this->assertEquals($bool,true);
169 
170  $bool = $tree->isInTree(24242424);
171  $this->assertEquals($bool,false);
172 
173  /* ref_id 14 => obj_id 98 does not exist
174  $node = $tree->getParentNodeData(24);
175  $this->assertEquals($node['title'],'Chat-Server');
176  */
177 
178  $bool = $tree->isGrandChild(9,24);
179  $this->assertEquals($bool,1);
180 
181  /* see above
182  $node = $tree->getNodeDataByType('chac');
183  $this->assertEquals($node[0]['title'],'Chat-Server');
184  */
185 
186  $bool = $tree->isDeleted(24);
187  $this->assertEquals($bool,false);
188 
189  $id = $tree->getParentId(24);
190  $this->assertEquals($id,14);
191 
192  $lft = $tree->getLeftValue(24);
193  $this->assertEquals($lft,14);
194 
195  $seq = $tree->getChildSequenceNumber($tree->getNodeData(24));
196  $this->assertEquals($seq,1);
197 
198  $tree->getNodePath(9,1);
199 
200  $max_depth = $tree->getMaximumDepth();
201 
202  // Round trip
203  $tree = new ilTree(ROOT_FOLDER_ID);
204  $suc = $tree->fetchSuccessorNode(16); // cals
205  $cals = $tree->fetchPredecessorNode($suc['child']);
206  $this->assertEquals($cals['child'],16);
207  }
208 }
209 ?>