ILIAS  Release_4_1_x_branch Revision 61804
 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");
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  // password methods
79  if (ilObjUser::_checkPassword($id, "password"))
80  {
81  $value.= "pw1-";
82  }
83  $user->replacePassword(md5("password2"));
84  if (ilObjUser::_checkPassword($id, "password2"))
85  {
86  $value.= "pw2-";
87  }
88  $user->updatePassword("password2", "password3", "password3");
89  if (ilObjUser::_checkPassword($id, "password3"))
90  {
91  $value.= "pw3-";
92  }
93  $user->resetPassword("password4", "password4");
94  if (ilObjUser::_checkPassword($id, "password4"))
95  {
96  $value.= "pw4-";
97  }
98 
99  // preferences...
100  $user->writePref("testpref", "pref1");
101  $value.= ilObjUser::_lookupPref($id, "testpref")."-";
102  $user->deletePref("testpref");
103  if (ilObjUser::_lookupPref($id, "testpref") == "")
104  {
105  $value.= "pref2"."-";
106  }
107 
108  // user agreement acceptance
109  if (!ilObjUser::_hasAcceptedAgreement("aatestuser"))
110  {
111  $value.= "agr1-";
112  }
113  $user->writeAccepted();
114  if (ilObjUser::_hasAcceptedAgreement("aatestuser"))
115  {
116  $value.= "agr2-";
117  }
118 
119  // activation
120  $user->setActive(false);
121  if (!ilObjUser::getStoredActive($id));
122  {
123  $value.= "act1-";
124  }
125  $user->setActive(true);
126  if (ilObjUser::getStoredActive($id));
127  {
128  $value.= "act2-";
129  }
130  ilObjUser::_toggleActiveStatusOfUsers(array($id), false);
131  if (!ilObjUser::getStoredActive($id));
132  {
133  $value.= "act3-";
134  }
135 
136  // deletion
137  $user->delete();
138 
139  $this->assertEquals("Max-Maxi-de@de.de-m-1.2.3.4-Mutzke-aatestuser-ext_mutzke-$id-no-le-".
140  "pw1-pw2-pw3-pw4-pref1-pref2-agr1-agr2-act1-act2-act3-",
141  $value);
142  }
143 
144 
148  public function testAuthAndEmailMethods()
149  {
150  include_once("./Services/User/classes/class.ilObjUser.php");
151 
152  $value = "";
153 
154  // creation
155  $user = new ilObjUser();
156  $d = array(
157  "login" => "aatestuser2",
158  "passwd_type" => IL_PASSWD_PLAIN,
159  "passwd" => "password",
160  "gender" => "f",
161  "firstname" => "Heidi",
162  "lastname" => "Kabel",
163  "email" => "qwe@ty.de",
164  "ext_account" => "ext_"
165  );
166  $user->assignData($d);
167  $user->setActive(true);
168  $user->create();
169  $user->saveAsNew();
170  $user->setLanguage("de");
171  $user->writePrefs();
172  $id = $user->getId();
173 
174  ilObjUser::_writeExternalAccount($id, "ext_kabel");
175  ilObjUser::_writeAuthMode($id, "cas");
176  $ids = ilObjUser::_getUserIdsByEmail("qwe@ty.de");
177 //var_dump($ids);
178  if (is_array($ids) && count($ids) == 1 && $ids[0] == "aatestuser2")
179  {
180  $value.= "email1-";
181  }
182  $uid = ilObjUser::getUserIdByEmail("qwe@ty.de");
183  if ($uid == $id)
184  {
185  $value.= "email2-";
186  }
187 
189  foreach ($acc as $k => $v)
190  if ($k == $id && $v == "ext_kabel")
191  {
192  $value.= "auth1-";
193  }
194 
195  if (ilObjUser::_lookupAuthMode($id) == "cas")
196  {
197  $value.= "auth2-";
198  }
199 
200  if (ilObjUser::_checkExternalAuthAccount("cas", "ext_kabel") == "aatestuser2")
201  {
202  $value.= "auth3-";
203  }
204 
205  if (ilObjUser::_externalAccountExists("ext_kabel","cas"))
206  {
207  $value.= "auth4-";
208  }
209 
211  $la = ilObjUser::_getLocalAccountsForEmail("qwe@ty.de");
212 
217 
218  // deletion
219  $user->delete();
220 
221  $this->assertEquals("email1-email2-auth1-auth2-auth3-auth4-",
222  $value);
223  }
224 
228  public function testPersonalDesktopItems()
229  {
230  include_once("./Services/User/classes/class.ilObjUser.php");
231 
232  $value = "";
233 
234  // creation
235  $user = new ilObjUser();
236  $d = array(
237  "login" => "aatestuser3",
238  "passwd_type" => IL_PASSWD_PLAIN,
239  "passwd" => "password",
240  "gender" => "f",
241  "firstname" => "Heidi",
242  "lastname" => "Kabel",
243  "email" => "de@de.de"
244  );
245  $user->assignData($d);
246  $user->setActive(true);
247  $user->create();
248  $user->saveAsNew();
249  $user->setLanguage("de");
250  $user->writePrefs();
251  $id = $user->getId();
252 
253  $user->addDesktopItem(ROOT_FOLDER_ID, "root");
254  if ($user->isDesktopItem(ROOT_FOLDER_ID, "root"))
255  {
256  $value.= "desk1-";
257  }
258  $user->setDesktopItemParameters(ROOT_FOLDER_ID, "root", "par1");
259  $di = $user->getDesktopItems();
260  if ($item = current($di))
261  {
262  if ($item["type"] == "root" && $item["ref_id"] == ROOT_FOLDER_ID)
263  {
264  $value.= "desk2-";
265  }
266  }
267 
268  $user->dropDesktopItem(ROOT_FOLDER_ID, "root");
269  if (!$user->isDesktopItem(ROOT_FOLDER_ID, "root"))
270  {
271  $value.= "desk3-";
272  }
273  $user->_removeItemFromDesktops(ROOT_FOLDER_ID);
274 
275  // deletion
276  $user->delete();
277 
278  $this->assertEquals("desk1-desk2-desk3-",
279  $value);
280  }
281 
285  public function testSearch()
286  {
287  include_once("./Services/User/classes/class.ilObjUser.php");
288 
289  $value = "";
290 
291  ilObjUser::searchUsers("test", 1, false, false);
292  ilObjUser::searchUsers("test", 0, true, false);
293  ilObjUser::searchUsers("test", 1, false, 1);
294  ilObjUser::searchUsers("test", 1, false, 2);
295  ilObjUser::searchUsers("test", 1, false, 3);
296  ilObjUser::searchUsers("test", 1, false, 4);
297  ilObjUser::searchUsers("test", 1, false, 5);
298  ilObjUser::searchUsers("test", 1, false, 6);
299  ilObjUser::searchUsers("test", 1, false, 7);
300 
301  ilObjUser::_getAllUserData(array("lastname", "online_time"));
302  ilObjUser::_getAllUserData(array("lastname", "online_time"), 1);
303  ilObjUser::_getAllUserData(array("lastname", "online_time"), 2);
304  ilObjUser::_getAllUserData(array("lastname", "online_time"), 3);
305  ilObjUser::_getAllUserData(array("lastname", "online_time"), 4);
306  ilObjUser::_getAllUserData(array("lastname", "online_time"), 5);
307  ilObjUser::_getAllUserData(array("lastname", "online_time"), 6);
308  ilObjUser::_getAllUserData(array("lastname", "online_time"), 7);
309 
310  $this->assertEquals("",
311  $value);
312  }
313 
317  public function testClipboard()
318  {
319  $value = "";
320 
321  // creation
322  $user = new ilObjUser();
323  $d = array(
324  "login" => "aatestuser3",
325  "passwd_type" => IL_PASSWD_PLAIN,
326  "passwd" => "password",
327  "gender" => "f",
328  "firstname" => "Heidi",
329  "lastname" => "Kabel",
330  "email" => "de@de.de"
331  );
332  $user->assignData($d);
333  $user->setActive(true);
334  $user->create();
335  $user->saveAsNew();
336  $user->setLanguage("de");
337  $user->writePrefs();
338  $id = $user->getId();
339 
340  $user->addObjectToClipboard($id, "user", "aatestuser");
341  $user->addObjectToClipboard(56, "mump", "mumpitz");
342  if ($user->clipboardHasObjectsOfType("user"))
343  {
344  $value.= "clip1-";
345  }
346 
347  $user->clipboardDeleteObjectsOfType("user");
348  if ($user->clipboardHasObjectsOfType("mump") &&
349  !$user->clipboardHasObjectsOfType("user"))
350  {
351  $value.= "clip2-";
352  }
353 
354  $objs = $user->getClipboardObjects("mump");
355  if (is_array($objs) && count($objs) == 1 && $objs[0]["id"] == 56)
356  {
357  $value.= "clip3-";
358  }
359 
360  $objs = $user->getClipboardChilds(56, "2008-10-10");
361 
362  $us = ilObjUser::_getUsersForClipboadObject("mump", 56);
363 
364  if (is_array($us) && count($us) == 1 && $us[0] == $id)
365  {
366  $value.= "clip4-";
367  }
368 
369  $user->delete();
370 
371  $this->assertEquals("clip1-clip2-clip3-clip4-",
372  $value);
373  }
374 
378  public function testMiscellaneous()
379  {
380  $value = "";
381 
382  include_once("./Services/User/classes/class.ilObjUser.php");
383  ilObjUser::_getNumberOfUsersForStyle("default", "delos");
385  ilObjUser::_moveUsersToStyle("default", "delos", "default", "delos");
386 
387  $this->assertEquals("",
388  $value);
389  }
390 
391 }
392 ?>