ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilObjUserTest.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 
18  public function testCreateSetLookupDelete()
19  {
20  include_once("./Services/User/classes/class.ilObjUser.php");
21 
22 
23  // delete all aatestuser from previous runs
24  while (($i = ilObjUser::_lookupId("aatestuser")) > 0)
25  {
26  $user = new ilObjUser($i);
27  $user->delete();
28  }
29 
30  $user = new ilObjUser();
31 
32  // creation
33  $d = array(
34  "login" => "aatestuser",
35  "passwd_type" => IL_PASSWD_PLAIN,
36  "passwd" => "password",
37  "gender" => "m",
38  "firstname" => "Max",
39  "lastname" => "Mutzke",
40  "email" => "de@de.de",
41  "client_ip" => "1.2.3.4",
42  "ext_account" => "ext_mutzke"
43  );
44  $user->assignData($d);
45  $user->create();
46  $user->saveAsNew();
47  $user->setLanguage("no");
48  $user->writePrefs();
49  $id = $user->getId();
50  $value.= $user->getFirstname()."-";
51 
52  // update
53  $user->setFirstname("Maxi");
54  $user->update();
55  $value.= $user->getFirstname()."-";
56 
57  // other update methods
58  $user->refreshLogin();
59 
60  // lookups
61  $value.= ilObjUser::_lookupEmail($id)."-";
62  $value.= ilObjUser::_lookupGender($id)."-";
63  $value.= ilObjUser::_lookupClientIP($id)."-";
65  $value.= $n["lastname"]."-";
67  $value.= ilObjUser::_lookupLogin($id)."-";
68  $value.= ilObjUser::_lookupExternalAccount($id)."-";
69  $value.= ilObjUser::_lookupId("aatestuser")."-";
71  $value.= ilObjUser::_lookupLanguage($id)."-";
73  if (ilObjUser::_loginExists("aatestuser"))
74  {
75  $value.= "le-";
76  }
77 
78  // preferences...
79  $user->writePref("testpref", "pref1");
80  $value.= ilObjUser::_lookupPref($id, "testpref")."-";
81  $user->deletePref("testpref");
82  if (ilObjUser::_lookupPref($id, "testpref") == "")
83  {
84  $value.= "pref2"."-";
85  }
86 
87  // activation
88  $user->setActive(false);
89  if (!ilObjUser::getStoredActive($id));
90  {
91  $value.= "act1-";
92  }
93  $user->setActive(true);
95  {
96  $value.= "act2-";
97  }
98  ilObjUser::_toggleActiveStatusOfUsers(array($id), false);
99  if (!ilObjUser::getStoredActive($id));
100  {
101  $value.= "act3-";
102  }
103 
104  // deletion
105  $user->delete();
106 
107  $this->assertEquals("Max-Maxi-de@de.de-m-1.2.3.4-Mutzke-aatestuser-ext_mutzke-$id-no-le-".
108  "pref1-pref2-act1-act2-act3-",
109  $value);
110  }
111 
112 
117  public function testAuthAndEmailMethods()
118  {
119  include_once("./Services/User/classes/class.ilObjUser.php");
120 
121  $value = "";
122 
123  // creation
124  $user = new ilObjUser();
125  $d = array(
126  "login" => "aatestuser2",
127  "passwd_type" => IL_PASSWD_PLAIN,
128  "passwd" => "password",
129  "gender" => "f",
130  "firstname" => "Heidi",
131  "lastname" => "Kabel",
132  "email" => "qwe@ty.de",
133  "ext_account" => "ext_"
134  );
135  $user->assignData($d);
136  $user->setActive(true);
137  $user->create();
138  $user->saveAsNew();
139  $user->setLanguage("de");
140  $user->writePrefs();
141  $id = $user->getId();
142 
143  ilObjUser::_writeExternalAccount($id, "ext_kabel");
144  ilObjUser::_writeAuthMode($id, "cas");
145  $ids = ilObjUser::_getUserIdsByEmail("qwe@ty.de");
146 //var_dump($ids);
147  if (is_array($ids) && count($ids) == 1 && $ids[0] == "aatestuser2")
148  {
149  $value.= "email1-";
150  }
151  $uid = ilObjUser::getUserIdByEmail("qwe@ty.de");
152  if ($uid == $id)
153  {
154  $value.= "email2-";
155  }
156 
158  foreach ($acc as $k => $v)
159  if ($k == $id && $v == "ext_kabel")
160  {
161  $value.= "auth1-";
162  }
163 
164  if (ilObjUser::_lookupAuthMode($id) == "cas")
165  {
166  $value.= "auth2-";
167  }
168 
169  if (ilObjUser::_checkExternalAuthAccount("cas", "ext_kabel") == "aatestuser2")
170  {
171  $value.= "auth3-";
172  }
173 
174  if (ilObjUser::_externalAccountExists("ext_kabel","cas"))
175  {
176  $value.= "auth4-";
177  }
178 
180  $la = ilObjUser::_getLocalAccountsForEmail("qwe@ty.de");
181 
186 
187  // deletion
188  $user->delete();
189 
190  $this->assertEquals("email1-email2-auth1-auth2-auth3-auth4-",
191  $value);
192  }
193 
198  public function testPersonalDesktopItems()
199  {
200  include_once("./Services/User/classes/class.ilObjUser.php");
201 
202  $value = "";
203 
204  // creation
205  $user = new ilObjUser();
206  $d = array(
207  "login" => "aatestuser3",
208  "passwd_type" => IL_PASSWD_PLAIN,
209  "passwd" => "password",
210  "gender" => "f",
211  "firstname" => "Heidi",
212  "lastname" => "Kabel",
213  "email" => "de@de.de"
214  );
215  $user->assignData($d);
216  $user->setActive(true);
217  $user->create();
218  $user->saveAsNew();
219  $user->setLanguage("de");
220  $user->writePrefs();
221  $id = $user->getId();
222 
223  $user->addDesktopItem(ROOT_FOLDER_ID, "root");
224  if ($user->isDesktopItem(ROOT_FOLDER_ID, "root"))
225  {
226  $value.= "desk1-";
227  }
228  $user->setDesktopItemParameters(ROOT_FOLDER_ID, "root", "par1");
229  $di = $user->getDesktopItems();
230  if ($item = current($di))
231  {
232  if ($item["type"] == "root" && $item["ref_id"] == ROOT_FOLDER_ID)
233  {
234  $value.= "desk2-";
235  }
236  }
237 
238  $user->dropDesktopItem(ROOT_FOLDER_ID, "root");
239  if (!$user->isDesktopItem(ROOT_FOLDER_ID, "root"))
240  {
241  $value.= "desk3-";
242  }
243  $user->_removeItemFromDesktops(ROOT_FOLDER_ID);
244 
245  // deletion
246  $user->delete();
247 
248  $this->assertEquals("desk1-desk2-desk3-",
249  $value);
250  }
251 
256  public function testSearch()
257  {
258  include_once("./Services/User/classes/class.ilObjUser.php");
259 
260  $value = "";
261 
262  ilObjUser::searchUsers("test", 1, false, false);
263  ilObjUser::searchUsers("test", 0, true, false);
264  ilObjUser::searchUsers("test", 1, false, 1);
265  ilObjUser::searchUsers("test", 1, false, 2);
266  ilObjUser::searchUsers("test", 1, false, 3);
267  ilObjUser::searchUsers("test", 1, false, 4);
268  ilObjUser::searchUsers("test", 1, false, 5);
269  ilObjUser::searchUsers("test", 1, false, 6);
270  ilObjUser::searchUsers("test", 1, false, 7);
271 
272  ilObjUser::_getAllUserData(array("lastname", "online_time"));
273  ilObjUser::_getAllUserData(array("lastname", "online_time"), 1);
274  ilObjUser::_getAllUserData(array("lastname", "online_time"), 2);
275  ilObjUser::_getAllUserData(array("lastname", "online_time"), 3);
276  ilObjUser::_getAllUserData(array("lastname", "online_time"), 4);
277  ilObjUser::_getAllUserData(array("lastname", "online_time"), 5);
278  ilObjUser::_getAllUserData(array("lastname", "online_time"), 6);
279  ilObjUser::_getAllUserData(array("lastname", "online_time"), 7);
280 
281  $this->assertEquals("",
282  $value);
283  }
284 
289  public function testClipboard()
290  {
291  $value = "";
292 
293  // creation
294  $user = new ilObjUser();
295  $d = array(
296  "login" => "aatestuser3",
297  "passwd_type" => IL_PASSWD_PLAIN,
298  "passwd" => "password",
299  "gender" => "f",
300  "firstname" => "Heidi",
301  "lastname" => "Kabel",
302  "email" => "de@de.de"
303  );
304  $user->assignData($d);
305  $user->setActive(true);
306  $user->create();
307  $user->saveAsNew();
308  $user->setLanguage("de");
309  $user->writePrefs();
310  $id = $user->getId();
311 
312  $user->addObjectToClipboard($id, "user", "aatestuser");
313  $user->addObjectToClipboard(56, "mump", "mumpitz");
314  if ($user->clipboardHasObjectsOfType("user"))
315  {
316  $value.= "clip1-";
317  }
318 
319  $user->clipboardDeleteObjectsOfType("user");
320  if ($user->clipboardHasObjectsOfType("mump") &&
321  !$user->clipboardHasObjectsOfType("user"))
322  {
323  $value.= "clip2-";
324  }
325 
326  $objs = $user->getClipboardObjects("mump");
327  if (is_array($objs) && count($objs) == 1 && $objs[0]["id"] == 56)
328  {
329  $value.= "clip3-";
330  }
331 
332  $objs = $user->getClipboardChilds(56, "2008-10-10");
333 
334  $us = ilObjUser::_getUsersForClipboadObject("mump", 56);
335 
336  if (is_array($us) && count($us) == 1 && $us[0] == $id)
337  {
338  $value.= "clip4-";
339  }
340 
341  $user->delete();
342 
343  $this->assertEquals("clip1-clip2-clip3-clip4-",
344  $value);
345  }
346 
351  public function testMiscellaneous()
352  {
353  $value = "";
354 
355  include_once("./Services/User/classes/class.ilObjUser.php");
356  ilObjUser::_getNumberOfUsersForStyle("default", "delos");
358  ilObjUser::_moveUsersToStyle("default", "delos", "default", "delos");
359 
360  $this->assertEquals("",
361  $value);
362  }
363 
364 }
365 ?>