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