ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilObjectTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5{
6 protected $backupGlobals = FALSE;
7
8 protected function setUp()
9 {
10 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
11 ilUnitUtil::performInitialisation();
12 }
13
17 public function testCreationDeletion()
18 {
19 $obj = new ilObject();
20 $obj->setType("xxx");
21 $obj->create();
22 $id = $obj->getId();
23
24 $obj2 = new ilObject();
25 $obj2->setType("xxx");
26 $obj2->create();
27 $id2 = $obj2->getId();
28
29 if ($id2 == ($id + 1))
30 {
31 $value.= "create1-";
32 }
33
34 if (ilObject::_exists($id))
35 {
36 $value.= "create2-";
37 }
38
39 $obj->delete();
40 $obj2->delete();
41
42 if (!ilObject::_exists($id))
43 {
44 $value.= "create3-";
45 }
46
47
48 $this->assertEquals("create1-create2-create3-", $value);
49 }
50
54 public function testSetGetLookup()
55 {
56 global $ilUser;
57
58 $obj = new ilObject();
59 $obj->setType(""); // otherwise type check will fail
60 $obj->setTitle("TestObject");
61 $obj->setDescription("TestDescription");
62 $obj->setImportId("imp_44");
63 $obj->create();
64 $obj->createReference();
65 $id = $obj->getId();
66 $ref_id = $obj->getRefId();
67 $obj = new ilObject($id, false);
68
69 if ($obj->getType() == "")
70 {
71 $value.= "sg1-";
72 }
73 if ($obj->getTitle() == "TestObject")
74 {
75 $value.= "sg2-";
76 }
77 if ($obj->getDescription() == "TestDescription")
78 {
79 $value.= "sg3-";
80 }
81 if ($obj->getImportId() == "imp_44")
82 {
83 $value.= "sg4-";
84 }
85 if ($obj->getOwner() == $ilUser->getId())
86 {
87 $value.= "sg5-";
88 }
89
90 $obj = new ilObject($ref_id);
91 if ($obj->getTitle() == "TestObject")
92 {
93 $value.= "sg6-";
94 }
95
96 if ($obj->getCreateDate() == ($lu = $obj->getLastUpdateDate()))
97 {
98 $value.= "sg7-";
99 }
100 $obj->setTitle("TestObject2");
101 sleep(2); // we want a different date here...
102 $obj->update();
103
104 $obj = new ilObject($ref_id);
105 if ($lu != ($lu2 = $obj->getLastUpdateDate()))
106 {
107 $value.= "up1-";
108 }
109 if ($obj->getTitle() == "TestObject2")
110 {
111 $value.= "up2-";
112 }
113
114 if ($id == ilObject::_lookupObjIdByImportId("imp_44"))
115 {
116 $value.= "lu1-";
117 }
118
120 {
121 $value.= "lu2-";
122 }
123
124 if (ilObject::_lookupTitle($id) == "TestObject2")
125 {
126 $value.= "lu3-";
127 }
128 if (ilObject::_lookupDescription($id) == "TestDescription")
129 {
130 $value.= "lu4-";
131 }
132 if (ilObject::_lookupLastUpdate($id) == $lu2)
133 {
134 $value.= "lu5-";
135 }
137 {
138 $value.= "lu6-";
139 }
140 if (ilObject::_lookupType($id) == "")
141 {
142 $value.= "lu7-";
143 }
145 {
146 $value.= "lu8-";
147 }
149 if (is_array($ar) && count($ar) == 1 && $ar[$ref_id] == $ref_id)
150 {
151 $value.= "lu9-";
152 }
153
154 $ids = ilObject::_getIdsForTitle("TestObject2");
155 foreach ($ids as $i)
156 {
157 if ($i == $id)
158 {
159 $value.= "lu10-";
160 }
161 }
162
163 $obs = ilObject::_getObjectsByType("usr");
164 foreach ($obs as $ob)
165 {
166 if ($ob["obj_id"] == $ilUser->getId())
167 {
168 $value.= "lu11-";
169 }
170 }
171
177 if ($d1 != $d2 && $d1 == $d3 && $d3 == null)
178 {
179 $value.= "dd1-";
180 }
181
182 $obj->delete();
183
184 $this->assertEquals("sg1-sg2-sg3-sg4-sg5-sg6-sg7-up1-up2-".
185 "lu1-lu2-lu3-lu4-lu5-lu6-lu7-lu8-lu9-lu10-lu11-dd1-", $value);
186 }
187
191 public function testTreeTrash()
192 {
193 global $tree;
194
195 $obj = new ilObject();
196 $obj->setType("xxx");
197 $obj->setTitle("TestObject");
198 $obj->setDescription("TestDescription");
199 $obj->setImportId("imp_44");
200 $obj->create();
201 $obj->createReference();
202 $id = $obj->getId();
203 $ref_id = $obj->getRefId();
204 $obj = new ilObject($ref_id);
205
206 $obj->putInTree(ROOT_FOLDER_ID);
207 $obj->setPermissions(ROOT_FOLDER_ID);
208 if ($tree->isInTree($ref_id))
209 {
210 $value.= "tree1-";
211 }
213 {
214 $value.= "tree2-";
215 }
216
217 // isSaved() uses internal cache!
218 $tree->useCache(false);
219
220 $tree->saveSubTree($ref_id, true);
221 if ($tree->isDeleted($ref_id))
222 {
223 $value.= "tree3-";
224 }
225 if ($tree->isSaved($ref_id))
226 {
227 $value.= "tree4-";
228 }
230 {
231 $value.= "tree5-";
232 }
234 {
235 $value.= "tree6-";
236 }
237
238 $saved_tree = new ilTree(-(int)$ref_id);
239 $node_data = $saved_tree->getNodeData($ref_id);
240 $saved_tree->deleteTree($node_data);
241
243 {
244 $value.= "tree7-";
245 }
246
247 $obs = ilUtil::_getObjectsByOperations("cat","read");
248 foreach ($obs as $ob)
249 {
251 {
252 $value.= "nocat-";
253 }
254 }
255
256 $obj->delete();
257
258 $this->assertEquals("tree1-tree2-tree3-tree4-tree5-tree6-tree7-", $value);
259
260 }
261
266 public function testObjectReference()
267 {
268 include_once './Services/Object/classes/class.ilObject.php';
269
270 $ref_ids = ilObject::_getAllReferences(1);
271 $bool = ilObject::_setDeletedDate(1);
274
275 $this->assertEquals($date, null);
276
277
278 }
279}
280?>
testCreationDeletion()
@group IL_Init
testSetGetLookup()
@group IL_Init
testTreeTrash()
@group IL_Init
testObjectReference()
test object reference queries @group IL_Init
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
_isInTrash($a_ref_id)
checks wether object is in trash
_lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _lookupObjectId($a_ref_id)
lookup object id
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _lookupDescription($a_id)
lookup object description
_setDeletedDate($a_ref_id)
only called in ilTree::saveSubTree
_lookupOwner($a_id)
lookup object owner
_hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
_resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _getAllReferences($a_id)
get all reference ids of object
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupObjIdByImportId($a_import_id)
_lookupLastUpdate($a_id, $a_as_string=false)
lookup last update
static _lookupType($a_id, $a_reference=false)
lookup object type
_lookupOwnerName($a_owner_id)
lookup owner name for owner id
static _getIdsForTitle($title, $type='', $partialmatch=false)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static _getObjectsByOperations($a_obj_type, $a_operation, $a_usr_id=0, $limit=0)
Get all objects of a specific type and check access This function is not recursive,...
$ref_id
Definition: sahs_server.php:39
global $ilUser
Definition: imgupload.php:15