ILIAS  Release_4_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");
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 
98  public function testGetPathIdsUsingNestedSet()
99  {
100  $tree = new ilTree(ROOT_FOLDER_ID);
101  $ids = $tree->getPathIdsUsingNestedSets(24,9); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
102 
103  $this->assertEquals($ids,array(9,14,24));
104 
105  $tree = new ilTree(ROOT_FOLDER_ID);
106  $ids = $tree->getPathIdsUsingNestedSets(24); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
107 
108  $this->assertEquals($ids,array(1,9,14,24));
109 
110  }
111 
117  public function testGetPathIds()
118  {
119  $tree = new ilTree(ROOT_FOLDER_ID);
120  $ids_ns = $tree->getPathIdsUsingNestedSets(24);
121  $ids_al = $tree->getPathIdsUsingAdjacencyMap(24);
122 
123  $this->assertEquals($ids_ns,$ids_al);
124  }
125 
131  public function testGetNodePath()
132  {
133  $tree = new ilTree(ROOT_FOLDER_ID);
134  $res = $tree->getNodePath(1,29);
135  }
136 
142  public function testMaxDepth()
143  {
144  $tree = new ilTree(ROOT_FOLDER_ID);
145  $tree->getMaximumDepth();
146  }
147 
153  public function testAllOthers()
154  {
155  $tree = new ilTree(ROOT_FOLDER_ID);
156  $d = $tree->getDepth(24);
157 
158  $this->assertEquals($d,4);
159 
160  $node = $tree->getNodeData(24);
161  $this->assertEquals($node['title'],'Public chat');
162 
163  $bool = $tree->isInTree(24);
164  $this->assertEquals($bool,true);
165 
166  $bool = $tree->isInTree(24242424);
167  $this->assertEquals($bool,false);
168 
169  $node = $tree->getParentNodeData(24);
170  $this->assertEquals($node['title'],'Chat-Server');
171 
172  $bool = $tree->isGrandChild(9,24);
173  $this->assertEquals($bool,1);
174 
175  $node = $tree->getNodeDataByType('chac');
176  $this->assertEquals($node[0]['title'],'Chat-Server');
177 
178  $bool = $tree->isDeleted(24);
179  $this->assertEquals($bool,false);
180 
181  $id = $tree->getParentId(24);
182  $this->assertEquals($id,14);
183 
184  $lft = $tree->getLeftValue(24);
185  $this->assertEquals($lft,14);
186 
187  $seq = $tree->getChildSequenceNumber($tree->getNodeData(24));
188  $this->assertEquals($seq,1);
189 
190  $tree->getNodePath(9,1);
191 
192  $max_depth = $tree->getMaximumDepth();
193 
194  // Round trip
195  $tree = new ilTree(ROOT_FOLDER_ID);
196  $suc = $tree->fetchSuccessorNode(16); // cals
197  $cals = $tree->fetchPredecessorNode($suc['child']);
198  $this->assertEquals($cals['child'],16);
199  }
200 }
201 ?>