ILIAS  eassessment Revision 61809
 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 
37 {
38  protected $backupGlobals = FALSE;
39 
40  protected function setUp()
41  {
42  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
44  }
45 
46  public function testGetChild()
47  {
48  $tree = new ilTree(ROOT_FOLDER_ID);
49  $childs = $tree->getChilds(14); // Chat settings (contains public chat)
50 
51  $this->assertEquals(count($childs),1);
52  }
53 
59  public function testGetChildsByType()
60  {
61  $tree = new ilTree(ROOT_FOLDER_ID);
62  $childs = $tree->getChildsByType(9,'cals'); // only calendar settings
63 
64  $this->assertEquals(count($childs),1);
65  }
66 
72  public function testGetChildsByTypeFilter()
73  {
74  $tree = new ilTree(ROOT_FOLDER_ID);
75  $childs = $tree->getChildsByTypeFilter(9,array('cals','rolf')); // only calendar settings and role folder
76 
77  $this->assertEquals(count($childs),2);
78  }
79 
85  public function testGetSubTree()
86  {
87  $tree = new ilTree(ROOT_FOLDER_ID);
88 
89  $root = $tree->getNodeData(1);
90  $childs = $tree->getSubTree($root,false,'cals'); // only calendar settings
91 
92  $this->assertEquals(count($childs),1);
93 
94  }
95 
102  {
103  $tree = new ilTree(ROOT_FOLDER_ID);
104  $ids = $tree->getPathIdsUsingNestedSets(24,9); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
105 
106  $this->assertEquals($ids,array(9,14,24));
107 
108  $tree = new ilTree(ROOT_FOLDER_ID);
109  $ids = $tree->getPathIdsUsingNestedSets(24); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
110 
111  $this->assertEquals($ids,array(1,9,14,24));
112 
113  }
114 
120  public function testGetPathIds()
121  {
122  $tree = new ilTree(ROOT_FOLDER_ID);
123  $ids_ns = $tree->getPathIdsUsingNestedSets(24);
124  $ids_al = $tree->getPathIdsUsingAdjacencyMap(24);
125 
126  $this->assertEquals($ids_ns,$ids_al);
127  }
128 
134  public function testGetNodePath()
135  {
136  $tree = new ilTree(ROOT_FOLDER_ID);
137  $res = $tree->getNodePath(1,29);
138  }
139 
145  public function testMaxDepth()
146  {
147  $tree = new ilTree(ROOT_FOLDER_ID);
148  $tree->getMaximumDepth();
149  }
150 
156  public function testAllOthers()
157  {
158  $tree = new ilTree(ROOT_FOLDER_ID);
159  $d = $tree->getDepth(24);
160 
161  $this->assertEquals($d,4);
162 
163  $node = $tree->getNodeData(24);
164  $this->assertEquals($node['title'],'Public chat');
165 
166  $bool = $tree->isInTree(24);
167  $this->assertEquals($bool,true);
168 
169  $bool = $tree->isInTree(24242424);
170  $this->assertEquals($bool,false);
171 
172  $node = $tree->getParentNodeData(24);
173  $this->assertEquals($node['title'],'Chat-Server');
174 
175  $bool = $tree->isGrandChild(9,24);
176  $this->assertEquals($bool,1);
177 
178  $node = $tree->getNodeDataByType('chac');
179  $this->assertEquals($node[0]['title'],'Chat-Server');
180 
181  $bool = $tree->isDeleted(24);
182  $this->assertEquals($bool,false);
183 
184  $id = $tree->getParentId(24);
185  $this->assertEquals($id,14);
186 
187  $lft = $tree->getLeftValue(24);
188  $this->assertEquals($lft,14);
189 
190  $seq = $tree->getChildSequenceNumber($tree->getNodeData(24));
191  $this->assertEquals($seq,1);
192 
193  $tree->getNodePath(9,1);
194 
195  $max_depth = $tree->getMaximumDepth();
196 
197  // Round trip
198  $tree = new ilTree(ROOT_FOLDER_ID);
199  $suc = $tree->fetchSuccessorNode(16); // cals
200  $cals = $tree->fetchPredecessorNode($suc['child']);
201  $this->assertEquals($cals['child'],16);
202  }
203 }
204 ?>