ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
9 {
10  protected $backupGlobals = false;
11 
12  protected function setUp()
13  {
14  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
15  ilUnitUtil::performInitialisation();
16  }
17 
22  public function testCreateSetLookupDelete()
23  {
24  include_once("./Services/User/classes/class.ilObjUser.php");
25 
26 
27  // delete all aatestuser from previous runs
28  while (($i = ilObjUser::_lookupId("aatestuser")) > 0) {
29  $user = new ilObjUser($i);
30  $user->delete();
31  }
32 
33  $user = new ilObjUser();
34 
35  // creation
36  $d = array(
37  "login" => "aatestuser",
38  "passwd_type" => IL_PASSWD_PLAIN,
39  "passwd" => "password",
40  "gender" => "m",
41  "firstname" => "Max",
42  "lastname" => "Mutzke",
43  "email" => "de@de.de",
44  "client_ip" => "1.2.3.4",
45  "ext_account" => "ext_mutzke"
46  );
47  $user->assignData($d);
48  $user->create();
49  $user->saveAsNew();
50  $user->setLanguage("no");
51  $user->writePrefs();
52  $id = $user->getId();
53  $value .= $user->getFirstname() . "-";
54 
55  // update
56  $user->setFirstname("Maxi");
57  $user->update();
58  $value .= $user->getFirstname() . "-";
59 
60  // other update methods
61  $user->refreshLogin();
62 
63  // lookups
64  $value .= ilObjUser::_lookupEmail($id) . "-";
65  $value .= ilObjUser::_lookupGender($id) . "-";
66  $value .= ilObjUser::_lookupClientIP($id) . "-";
68  $value .= $n["lastname"] . "-";
70  $value .= ilObjUser::_lookupLogin($id) . "-";
71  $value .= ilObjUser::_lookupExternalAccount($id) . "-";
72  $value .= ilObjUser::_lookupId("aatestuser") . "-";
74  $value .= ilObjUser::_lookupLanguage($id) . "-";
76  if (ilObjUser::_loginExists("aatestuser")) {
77  $value .= "le-";
78  }
79 
80  // preferences...
81  $user->writePref("testpref", "pref1");
82  $value .= ilObjUser::_lookupPref($id, "testpref") . "-";
83  $user->deletePref("testpref");
84  if (ilObjUser::_lookupPref($id, "testpref") == "") {
85  $value .= "pref2" . "-";
86  }
87 
88  // activation
89  $user->setActive(false);
91  $value .= "act1-";
92  }
93  $user->setActive(true);
95  $value .= "act2-";
96  }
99  $value .= "act3-";
100  }
101 
102  // deletion
103  $user->delete();
104 
105  $this->assertEquals(
106  "Max-Maxi-de@de.de-m-1.2.3.4-Mutzke-aatestuser-ext_mutzke-$id-no-le-" .
107  "pref1-pref2-act1-act2-act3-",
108  $value
109  );
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 
145  $logins = ilObjUser::getUserLoginsByEmail("qwe@ty.de");
146  //var_dump($ids);
147  if (is_array($logins) && count($logins) == 1 && $logins[0] == "aatestuser2") {
148  $value .= "email1-";
149  $uid = ilObjUser::getUserIdByLogin($logins[0]);
150  } else {
151  $uid = 0;
152  }
153 
154  if ($uid == $id) {
155  $value .= "email2-";
156  }
157 
159  foreach ($acc as $k => $v) {
160  if ($k == $id && $v == "ext_kabel") {
161  $value .= "auth1-";
162  }
163  }
164 
165  if (ilObjUser::_lookupAuthMode($id) == "cas") {
166  $value .= "auth2-";
167  }
168 
169  if (ilObjUser::_checkExternalAuthAccount("cas", "ext_kabel") == "aatestuser2") {
170  $value .= "auth3-";
171  }
172 
173  if (ilObjUser::_externalAccountExists("ext_kabel", "cas")) {
174  $value .= "auth4-";
175  }
176 
178  $la = ilObjUser::_getLocalAccountsForEmail("qwe@ty.de");
179 
184 
185  // deletion
186  $user->delete();
187 
188  $this->assertEquals(
189  "email1-email2-auth1-auth2-auth3-auth4-",
190  $value
191  );
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  $value .= "desk1-";
226  }
227  $user->setDesktopItemParameters(ROOT_FOLDER_ID, "root", "par1");
228  $di = $user->getDesktopItems();
229  if ($item = current($di)) {
230  if ($item["type"] == "root" && $item["ref_id"] == ROOT_FOLDER_ID) {
231  $value .= "desk2-";
232  }
233  }
234 
235  $user->dropDesktopItem(ROOT_FOLDER_ID, "root");
236  if (!$user->isDesktopItem(ROOT_FOLDER_ID, "root")) {
237  $value .= "desk3-";
238  }
239  $user->_removeItemFromDesktops(ROOT_FOLDER_ID);
240 
241  // deletion
242  $user->delete();
243 
244  $this->assertEquals(
245  "desk1-desk2-desk3-",
246  $value
247  );
248  }
249 
254  public function testSearch()
255  {
256  include_once("./Services/User/classes/class.ilObjUser.php");
257 
258  $value = "";
259 
260  ilObjUser::searchUsers("test", 1, false, false);
261  ilObjUser::searchUsers("test", 0, true, false);
262  ilObjUser::searchUsers("test", 1, false, 1);
263  ilObjUser::searchUsers("test", 1, false, 2);
264  ilObjUser::searchUsers("test", 1, false, 3);
265  ilObjUser::searchUsers("test", 1, false, 4);
266  ilObjUser::searchUsers("test", 1, false, 5);
267  ilObjUser::searchUsers("test", 1, false, 6);
268  ilObjUser::searchUsers("test", 1, false, 7);
269 
270  ilObjUser::_getAllUserData(array("lastname", "online_time"));
271  ilObjUser::_getAllUserData(array("lastname", "online_time"), 1);
272  ilObjUser::_getAllUserData(array("lastname", "online_time"), 2);
273  ilObjUser::_getAllUserData(array("lastname", "online_time"), 3);
274  ilObjUser::_getAllUserData(array("lastname", "online_time"), 4);
275  ilObjUser::_getAllUserData(array("lastname", "online_time"), 5);
276  ilObjUser::_getAllUserData(array("lastname", "online_time"), 6);
277  ilObjUser::_getAllUserData(array("lastname", "online_time"), 7);
278 
279  $this->assertEquals(
280  "",
281  $value
282  );
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  $value .= "clip1-";
316  }
317 
318  $user->clipboardDeleteObjectsOfType("user");
319  if ($user->clipboardHasObjectsOfType("mump") &&
320  !$user->clipboardHasObjectsOfType("user")) {
321  $value .= "clip2-";
322  }
323 
324  $objs = $user->getClipboardObjects("mump");
325  if (is_array($objs) && count($objs) == 1 && $objs[0]["id"] == 56) {
326  $value .= "clip3-";
327  }
328 
329  $objs = $user->getClipboardChilds(56, "2008-10-10");
330 
331  $us = ilObjUser::_getUsersForClipboadObject("mump", 56);
332 
333  if (is_array($us) && count($us) == 1 && $us[0] == $id) {
334  $value .= "clip4-";
335  }
336 
337  $user->delete();
338 
339  $this->assertEquals(
340  "clip1-clip2-clip3-clip4-",
341  $value
342  );
343  }
344 
349  public function testMiscellaneous()
350  {
351  $value = "";
352 
353  include_once("./Services/User/classes/class.ilObjUser.php");
354  ilObjUser::_getNumberOfUsersForStyle("default", "delos");
356  ilObjUser::_moveUsersToStyle("default", "delos", "default", "delos");
357 
358  $this->assertEquals(
359  "",
360  $value
361  );
362  }
363 }
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static getUserIdByLogin($a_login)
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
const IL_PASSWD_PLAIN
static _getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
Class ilObjUserTest needsInstalledILIAS.
testAuthAndEmailMethods()
Auth and email related methods IL_Init.
testClipboard()
Clipboard IL_Init.
static _getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
testSearch()
Search methods IL_Init.
static _incrementLoginAttempts($a_usr_id)
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
static _lookupId($a_user_str)
Lookup id by login.
static _lookupClientIP($a_user_id)
Lookup client ip.
static _lookupGender($a_user_id)
Lookup gender.
static _resetLoginAttempts($a_usr_id)
static _getLoginAttempts($a_usr_id)
static _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
Toggle active status of users.
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
static _externalAccountExists($a_external_account, $a_auth_mode)
Check if an external account name already exists.
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
static _getAllUserData($a_fields=null, $active=-1)
STATIC METHOD get all user data.
static getUserLoginsByEmail($a_email)
get all user login names of an email address
static _getLocalAccountsForEmail($a_email)
check whether external account and authentication method matches with a user
static _getNumberOfUsersPerAuthMode()
get number of users per auth mode
static searchUsers($a_search_str, $active=1, $a_return_ids_only=false, $filter_settings=false)
STATIC METHOD get the user_ids which correspond a search string.
$n
Definition: RandomTest.php:85
$user
Definition: migrateto20.php:57
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
testMiscellaneous()
Miscellaneous IL_Init.
static _lookupAuthMode($a_usr_id)
lookup auth mode
static _setUserInactive($a_usr_id)
static _lookupLanguage($a_usr_id)
testPersonalDesktopItems()
Personal Desktop Items IL_Init.
static _lookupEmail($a_user_id)
Lookup email.
static _lookupPref($a_usr_id, $a_keyword)
$i
Definition: disco.tpl.php:19
testCreateSetLookupDelete()
Creates a user, sets preferences, lookups data, delete user IL_Init.
static _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
skins and styles
getStoredActive($a_id)
get user active state
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
static _writeAuthMode($a_usr_id, $a_auth_mode)
static _writeExternalAccount($a_usr_id, $a_ext_id)
static _getAllUserAssignedStyles()
skins and styles
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
static _lookupLastLogin($a_user_id)
lookup last login