ILIAS  release_7 Revision v7.30-3-g800a261c036
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
24use PHPUnit\Framework\TestCase;
25
35class ilTreeTest extends TestCase
36{
37 protected $backupGlobals = false;
38
39 protected function setUp() : void
40 {
41 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
42 ilUnitUtil::performInitialisation();
43 }
44
45 public function testGetChild()
46 {
47 $tree = new ilTree(ROOT_FOLDER_ID);
48 $childs = $tree->getChilds(14); // Chat settings (contains public chat)
49
50 $this->assertEquals(count($childs), 1);
51 }
52
58 public function testGetChildsByType()
59 {
60 $tree = new ilTree(ROOT_FOLDER_ID);
61 $childs = $tree->getChildsByType(9, 'cals'); // only calendar settings
62
63 $this->assertEquals(count($childs), 1);
64 }
65
71 public function testGetChildsByTypeFilter()
72 {
73 $tree = new ilTree(ROOT_FOLDER_ID);
74 $childs = $tree->getChildsByTypeFilter(9, array('cals','rolf')); // only calendar settings and role folder
75
76 $this->assertEquals(count($childs), 2);
77 }
78
84 public function testGetSubTree()
85 {
86 $tree = new ilTree(ROOT_FOLDER_ID);
87
88 $root = $tree->getNodeData(1);
89 $childs = $tree->getSubTree($root, false, 'cals'); // only calendar settings
90
91 $this->assertEquals(count($childs), 1);
92 }
93
101 {
102 // This test leads to a fatal error, as getPathIdsUsingNestedSets is
103 // not defined on ilTree.
104 $this->assertTrue(false, "Testcase leads to fatal error.");
105
106 $tree = new ilTree(ROOT_FOLDER_ID);
107 $ids = $tree->getPathIdsUsingNestedSets(24, 9); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
108
109 $this->assertEquals($ids, array(9,14,24));
110
111 $tree = new ilTree(ROOT_FOLDER_ID);
112 $ids = $tree->getPathIdsUsingNestedSets(24); // Administration -> Public Chat => should return 9,14,24 (chat server settings)
113
114 $this->assertEquals($ids, array(1,9,14,24));
115 }
116
123 public function testGetPathIds()
124 {
125 // This test leads to a fatal error, as getPathIdsUsingNestedSets and
126 // getPathIdsUsingAdjacencyMap are not defined on ilTree.
127 $this->assertTrue(false, "Testcase leads to fatal error.");
128
129 $tree = new ilTree(ROOT_FOLDER_ID);
130 $ids_ns = $tree->getPathIdsUsingNestedSets(24);
131 $ids_al = $tree->getPathIdsUsingAdjacencyMap(24);
132
133 $this->assertEquals($ids_ns, $ids_al);
134 }
135
141 public function testGetNodePath()
142 {
143 $tree = new ilTree(ROOT_FOLDER_ID);
144 $res = $tree->getNodePath(1, 29);
145 }
146
153 public function testMaxDepth()
154 {
155 $tree = new ilTree(ROOT_FOLDER_ID);
156 $tree->getMaximumDepth();
157 }
158
165 public function testAllOthers()
166 {
167 $tree = new ilTree(ROOT_FOLDER_ID);
168 $d = $tree->getDepth(24);
169
170 $this->assertEquals($d, 4);
171
172 $node = $tree->getNodeData(24);
173 $this->assertEquals($node['title'], 'Public chat');
174
175 $bool = $tree->isInTree(24);
176 $this->assertEquals($bool, true);
177
178 $bool = $tree->isInTree(24242424);
179 $this->assertEquals($bool, false);
180
181 /* ref_id 14 => obj_id 98 does not exist
182 $node = $tree->getParentNodeData(24);
183 $this->assertEquals($node['title'],'Chat-Server');
184 */
185
186 $bool = $tree->isGrandChild(9, 24);
187 $this->assertEquals($bool, 1);
188
189 /* see above
190 $node = $tree->getNodeDataByType('chac');
191 $this->assertEquals($node[0]['title'],'Chat-Server');
192 */
193
194 $bool = $tree->isDeleted(24);
195 $this->assertEquals($bool, false);
196
197 $id = $tree->getParentId(24);
198 $this->assertEquals($id, 14);
199
200 $lft = $tree->getLeftValue(24);
201 $this->assertEquals($lft, 14);
202
203 $seq = $tree->getChildSequenceNumber($tree->getNodeData(24));
204 $this->assertEquals($seq, 1);
205
206 $tree->getNodePath(9, 1);
207
208 $max_depth = $tree->getMaximumDepth();
209
210 // Round trip
211 $tree = new ilTree(ROOT_FOLDER_ID);
212 $suc = $tree->fetchSuccessorNode(16); // cals
213 $cals = $tree->fetchPredecessorNode($suc['child']);
214 $this->assertEquals($cals['child'], 16);
215 }
216}
An exception for terminatinating execution or to throw for unit testing.
Unit tests for tree table.
Definition: ilTreeTest.php:36
testGetChildsByType()
get childs by type @group IL_Init
Definition: ilTreeTest.php:58
testGetNodePath()
@group IL_Init
Definition: ilTreeTest.php:141
testGetPathIds()
get path ids (adjacenca and nested set) @group IL_Init
Definition: ilTreeTest.php:123
testMaxDepth()
get path ids (adjacenca and nested set) @group IL_Init
Definition: ilTreeTest.php:153
testGetChildsByTypeFilter()
get childs by type filter @group IL_Init
Definition: ilTreeTest.php:71
testGetPathIdsUsingNestedSet()
get path ids using nested set @group IL_Init
Definition: ilTreeTest.php:100
testAllOthers()
get path ids (adjacenca and nested set) @group IL_Init
Definition: ilTreeTest.php:165
testGetSubTree()
get childs by type filter @group IL_Init
Definition: ilTreeTest.php:84
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const ROOT_FOLDER_ID
Definition: constants.php:30
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
foreach($_POST as $key=> $value) $res