ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjectTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
7{
8 protected $backupGlobals = false;
9
10 protected function setUp()
11 {
12 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
13 ilUnitUtil::performInitialisation();
14 }
15
19 public function testCreationDeletion()
20 {
21 $obj = new ilObject();
22 $obj->setType("xxx");
23 $obj->create();
24 $id = $obj->getId();
25
26 $obj2 = new ilObject();
27 $obj2->setType("xxx");
28 $obj2->create();
29 $id2 = $obj2->getId();
30
31 if ($id2 == ($id + 1)) {
32 $value .= "create1-";
33 }
34
36 $value .= "create2-";
37 }
38
39 $obj->delete();
40 $obj2->delete();
41
42 if (!ilObject::_exists($id)) {
43 $value .= "create3-";
44 }
45
46
47 $this->assertEquals("create1-create2-create3-", $value);
48 }
49
53 public function testSetGetLookup()
54 {
55 global $DIC;
56 $ilUser = $DIC->user();
57
58
59 $obj = new ilObject();
60 $obj->setType(""); // otherwise type check will fail
61 $obj->setTitle("TestObject");
62 $obj->setDescription("TestDescription");
63 $obj->setImportId("imp_44");
64 $obj->create();
65 $obj->createReference();
66 $id = $obj->getId();
67 $ref_id = $obj->getRefId();
68 $obj = new ilObject($id, false);
69
70 if ($obj->getType() == "") {
71 $value .= "sg1-";
72 }
73 if ($obj->getTitle() == "TestObject") {
74 $value .= "sg2-";
75 }
76 if ($obj->getDescription() == "TestDescription") {
77 $value .= "sg3-";
78 }
79 if ($obj->getImportId() == "imp_44") {
80 $value .= "sg4-";
81 }
82 if ($obj->getOwner() == $ilUser->getId()) {
83 $value .= "sg5-";
84 }
85
86 $obj = new ilObject($ref_id);
87 if ($obj->getTitle() == "TestObject") {
88 $value .= "sg6-";
89 }
90
91 if ($obj->getCreateDate() == ($lu = $obj->getLastUpdateDate())) {
92 $value .= "sg7-";
93 }
94 $obj->setTitle("TestObject2");
95 sleep(2); // we want a different date here...
96 $obj->update();
97
98 $obj = new ilObject($ref_id);
99 if ($lu != ($lu2 = $obj->getLastUpdateDate())) {
100 $value .= "up1-";
101 }
102 if ($obj->getTitle() == "TestObject2") {
103 $value .= "up2-";
104 }
105
106 if ($id == ilObject::_lookupObjIdByImportId("imp_44")) {
107 $value .= "lu1-";
108 }
109
111 $value .= "lu2-";
112 }
113
114 if (ilObject::_lookupTitle($id) == "TestObject2") {
115 $value .= "lu3-";
116 }
117 if (ilObject::_lookupDescription($id) == "TestDescription") {
118 $value .= "lu4-";
119 }
120 if (ilObject::_lookupLastUpdate($id) == $lu2) {
121 $value .= "lu5-";
122 }
123 if (ilObject::_lookupObjId($ref_id) == $id) {
124 $value .= "lu6-";
125 }
126 if (ilObject::_lookupType($id) == "") {
127 $value .= "lu7-";
128 }
129 if (ilObject::_lookupObjectId($ref_id) == $id) {
130 $value .= "lu8-";
131 }
133 if (is_array($ar) && count($ar) == 1 && $ar[$ref_id] == $ref_id) {
134 $value .= "lu9-";
135 }
136
137 $ids = ilObject::_getIdsForTitle("TestObject2");
138 foreach ($ids as $i) {
139 if ($i == $id) {
140 $value .= "lu10-";
141 }
142 }
143
144 $obs = ilObject::_getObjectsByType("usr");
145 foreach ($obs as $ob) {
146 if ($ob["obj_id"] == $ilUser->getId()) {
147 $value .= "lu11-";
148 }
149 }
150
151 $d1 = ilObject::_lookupDeletedDate($ref_id);
153 $d2 = ilObject::_lookupDeletedDate($ref_id);
155 $d3 = ilObject::_lookupDeletedDate($ref_id);
156 if ($d1 != $d2 && $d1 == $d3 && $d3 == null) {
157 $value .= "dd1-";
158 }
159
160 $obj->delete();
161
162 $this->assertEquals("sg1-sg2-sg3-sg4-sg5-sg6-sg7-up1-up2-" .
163 "lu1-lu2-lu3-lu4-lu5-lu6-lu7-lu8-lu9-lu10-lu11-dd1-", $value);
164 }
165
169 public function testTreeTrash()
170 {
171 global $DIC;
172 $tree = $DIC->repositoryTree();
173
174 $obj = new ilObject();
175 $obj->setType("xxx");
176 $obj->setTitle("TestObject");
177 $obj->setDescription("TestDescription");
178 $obj->setImportId("imp_44");
179 $obj->create();
180 $obj->createReference();
181 $id = $obj->getId();
182 $ref_id = $obj->getRefId();
183 $obj = new ilObject($ref_id);
184
185 $obj->putInTree(ROOT_FOLDER_ID);
186 $obj->setPermissions(ROOT_FOLDER_ID);
187 if ($tree->isInTree($ref_id)) {
188 $value .= "tree1-";
189 }
191 $value .= "tree2-";
192 }
193
194 // isSaved() uses internal cache!
195 $tree->useCache(false);
196
197 $tree->saveSubTree($ref_id, true);
198 if ($tree->isDeleted($ref_id)) {
199 $value .= "tree3-";
200 }
201 if ($tree->isSaved($ref_id)) {
202 $value .= "tree4-";
203 }
204 if (ilObject::_isInTrash($ref_id)) {
205 $value .= "tree5-";
206 }
208 $value .= "tree6-";
209 }
210
211 $saved_tree = new ilTree(-(int) $ref_id);
212 $node_data = $saved_tree->getNodeData($ref_id);
213 $saved_tree->deleteTree($node_data);
214
215 if (!ilObject::_isInTrash($ref_id)) {
216 $value .= "tree7-";
217 }
218
219 $obs = ilUtil::_getObjectsByOperations("cat", "read");
220 foreach ($obs as $ob) {
222 $value .= "nocat-";
223 }
224 }
225
226 $obj->delete();
227
228 $this->assertEquals("tree1-tree2-tree3-tree4-tree5-tree6-tree7-", $value);
229 }
230
235 public function testObjectReference()
236 {
237 include_once './Services/Object/classes/class.ilObject.php';
238
239 $ref_ids = ilObject::_getAllReferences(1);
240 $bool = ilObject::_setDeletedDate(1);
243
244 $this->assertEquals($date, null);
245 }
246}
An exception for terminatinating execution or to throw for unit testing.
@group needsInstalledILIAS
Definition: ilObjectTest.php:7
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 _lookupOwnerName($a_owner_id)
lookup owner name for owner id
static _lookupObjId($a_id)
static _resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _lookupTitle($a_id)
lookup object title
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
static _setDeletedDate($a_ref_id)
only called in ilTree::saveSubTree
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 _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _lookupObjIdByImportId($a_import_id)
static _lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _lookupLastUpdate($a_id, $a_as_string=false)
lookup last update
static _lookupOwner($a_id)
lookup object owner
static _isInTrash($a_ref_id)
checks wether object is in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
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,...
$i
Definition: disco.tpl.php:19
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18