ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
99 {
100 // This test leads to a fatal error, as getPathIdsUsingNestedSets is
101 // not defined on ilTree.
102 $this->assertTrue(false, "Testcase leads to fatal error.");
103
104 $tree = new ilTree(ROOT_FOLDER_ID);
105 $ids = $tree->getPathIdsUsingNestedSets(24, 9); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
106
107 $this->assertEquals($ids, array(9,14,24));
108
109 $tree = new ilTree(ROOT_FOLDER_ID);
110 $ids = $tree->getPathIdsUsingNestedSets(24); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
111
112 $this->assertEquals($ids, array(1,9,14,24));
113 }
114
121 public function testGetPathIds()
122 {
123 // This test leads to a fatal error, as getPathIdsUsingNestedSets and
124 // getPathIdsUsingAdjacencyMap are not defined on ilTree.
125 $this->assertTrue(false, "Testcase leads to fatal error.");
126
127 $tree = new ilTree(ROOT_FOLDER_ID);
128 $ids_ns = $tree->getPathIdsUsingNestedSets(24);
129 $ids_al = $tree->getPathIdsUsingAdjacencyMap(24);
130
131 $this->assertEquals($ids_ns, $ids_al);
132 }
133
139 public function testGetNodePath()
140 {
141 $tree = new ilTree(ROOT_FOLDER_ID);
142 $res = $tree->getNodePath(1, 29);
143 }
144
151 public function testMaxDepth()
152 {
153 $tree = new ilTree(ROOT_FOLDER_ID);
154 $tree->getMaximumDepth();
155 }
156
163 public function testAllOthers()
164 {
165 $tree = new ilTree(ROOT_FOLDER_ID);
166 $d = $tree->getDepth(24);
167
168 $this->assertEquals($d, 4);
169
170 $node = $tree->getNodeData(24);
171 $this->assertEquals($node['title'], 'Public chat');
172
173 $bool = $tree->isInTree(24);
174 $this->assertEquals($bool, true);
175
176 $bool = $tree->isInTree(24242424);
177 $this->assertEquals($bool, false);
178
179 /* ref_id 14 => obj_id 98 does not exist
180 $node = $tree->getParentNodeData(24);
181 $this->assertEquals($node['title'],'Chat-Server');
182 */
183
184 $bool = $tree->isGrandChild(9, 24);
185 $this->assertEquals($bool, 1);
186
187 /* see above
188 $node = $tree->getNodeDataByType('chac');
189 $this->assertEquals($node[0]['title'],'Chat-Server');
190 */
191
192 $bool = $tree->isDeleted(24);
193 $this->assertEquals($bool, false);
194
195 $id = $tree->getParentId(24);
196 $this->assertEquals($id, 14);
197
198 $lft = $tree->getLeftValue(24);
199 $this->assertEquals($lft, 14);
200
201 $seq = $tree->getChildSequenceNumber($tree->getNodeData(24));
202 $this->assertEquals($seq, 1);
203
204 $tree->getNodePath(9, 1);
205
206 $max_depth = $tree->getMaximumDepth();
207
208 // Round trip
209 $tree = new ilTree(ROOT_FOLDER_ID);
210 $suc = $tree->fetchSuccessorNode(16); // cals
211 $cals = $tree->fetchPredecessorNode($suc['child']);
212 $this->assertEquals($cals['child'], 16);
213 }
214}
An exception for terminatinating execution or to throw for unit testing.
Unit tests for tree table.
Definition: ilTreeTest.php:34
testGetChildsByType()
get childs by type @group IL_Init
Definition: ilTreeTest.php:56
testGetNodePath()
@group IL_Init
Definition: ilTreeTest.php:139
testGetPathIds()
get path ids (adjacenca and nested set) @group IL_Init
Definition: ilTreeTest.php:121
testMaxDepth()
get path ids (adjacenca and nested set) @group IL_Init
Definition: ilTreeTest.php:151
testGetChildsByTypeFilter()
get childs by type filter @group IL_Init
Definition: ilTreeTest.php:69
testGetPathIdsUsingNestedSet()
get path ids using nested set @group IL_Init
Definition: ilTreeTest.php:98
testAllOthers()
get path ids (adjacenca and nested set) @group IL_Init
Definition: ilTreeTest.php:163
testGetSubTree()
get childs by type filter @group IL_Init
Definition: ilTreeTest.php:82
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
if(!array_key_exists('StateId', $_REQUEST)) $id
$root
Definition: sabredav.php:45
foreach($_POST as $key=> $value) $res