ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules 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 
10 class ilObjUserTest extends TestCase
11 {
12  protected $backupGlobals = false;
13 
14  protected function setUp() : void
15  {
16  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
17  ilUnitUtil::performInitialisation();
18  }
19 
24  public function testCreateSetLookupDelete()
25  {
26  include_once("./Services/User/classes/class.ilObjUser.php");
27 
28 
29  // delete all aatestuser from previous runs
30  while (($i = ilObjUser::_lookupId("aatestuser")) > 0) {
31  $user = new ilObjUser($i);
32  $user->delete();
33  }
34 
35  $user = new ilObjUser();
36 
37  // creation
38  $d = array(
39  "login" => "aatestuser",
40  "passwd_type" => IL_PASSWD_PLAIN,
41  "passwd" => "password",
42  "gender" => "m",
43  "firstname" => "Max",
44  "lastname" => "Mutzke",
45  "email" => "de@de.de",
46  "client_ip" => "1.2.3.4",
47  "ext_account" => "ext_mutzke"
48  );
49  $user->assignData($d);
50  $user->create();
51  $user->saveAsNew();
52  $user->setLanguage("no");
53  $user->writePrefs();
54  $id = $user->getId();
55  $value .= $user->getFirstname() . "-";
56 
57  // update
58  $user->setFirstname("Maxi");
59  $user->update();
60  $value .= $user->getFirstname() . "-";
61 
62  // other update methods
63  $user->refreshLogin();
64 
65  // lookups
66  $value .= ilObjUser::_lookupEmail($id) . "-";
67  $value .= ilObjUser::_lookupGender($id) . "-";
68  $value .= ilObjUser::_lookupClientIP($id) . "-";
70  $value .= $n["lastname"] . "-";
72  $value .= ilObjUser::_lookupLogin($id) . "-";
73  $value .= ilObjUser::_lookupExternalAccount($id) . "-";
74  $value .= ilObjUser::_lookupId("aatestuser") . "-";
76  $value .= ilObjUser::_lookupLanguage($id) . "-";
78  if (ilObjUser::_loginExists("aatestuser")) {
79  $value .= "le-";
80  }
81 
82  // preferences...
83  $user->writePref("testpref", "pref1");
84  $value .= ilObjUser::_lookupPref($id, "testpref") . "-";
85  $user->deletePref("testpref");
86  if (ilObjUser::_lookupPref($id, "testpref") == "") {
87  $value .= "pref2" . "-";
88  }
89 
90  // activation
91  $user->setActive(false);
92  if (!ilObjUser::getStoredActive($id)) {
93  $value .= "act1-";
94  }
95  $user->setActive(true);
96  if (ilObjUser::getStoredActive($id)) {
97  $value .= "act2-";
98  }
99  ilObjUser::_toggleActiveStatusOfUsers(array($id), false);
100  if (!ilObjUser::getStoredActive($id)) {
101  $value .= "act3-";
102  }
103 
104  // deletion
105  $user->delete();
106 
107  $this->assertEquals(
108  "Max-Maxi-de@de.de-m-1.2.3.4-Mutzke-aatestuser-ext_mutzke-$id-no-le-" .
109  "pref1-pref2-act1-act2-act3-",
110  $value
111  );
112  }
113 
114 
119  public function testAuthAndEmailMethods()
120  {
121  include_once("./Services/User/classes/class.ilObjUser.php");
122 
123  $value = "";
124 
125  // creation
126  $user = new ilObjUser();
127  $d = array(
128  "login" => "aatestuser2",
129  "passwd_type" => IL_PASSWD_PLAIN,
130  "passwd" => "password",
131  "gender" => "f",
132  "firstname" => "Heidi",
133  "lastname" => "Kabel",
134  "email" => "qwe@ty.de",
135  "ext_account" => "ext_"
136  );
137  $user->assignData($d);
138  $user->setActive(true);
139  $user->create();
140  $user->saveAsNew();
141  $user->setLanguage("de");
142  $user->writePrefs();
143  $id = $user->getId();
144 
145  ilObjUser::_writeExternalAccount($id, "ext_kabel");
146  ilObjUser::_writeAuthMode($id, "cas");
147  $logins = ilObjUser::getUserLoginsByEmail("qwe@ty.de");
148  //var_dump($ids);
149  if (is_array($logins) && count($logins) == 1 && $logins[0] == "aatestuser2") {
150  $value .= "email1-";
151  $uid = ilObjUser::getUserIdByLogin($logins[0]);
152  } else {
153  $uid = 0;
154  }
155 
156  if ($uid == $id) {
157  $value .= "email2-";
158  }
159 
161  foreach ($acc as $k => $v) {
162  if ($k == $id && $v == "ext_kabel") {
163  $value .= "auth1-";
164  }
165  }
166 
167  if (ilObjUser::_lookupAuthMode($id) == "cas") {
168  $value .= "auth2-";
169  }
170 
171  if (ilObjUser::_checkExternalAuthAccount("cas", "ext_kabel") == "aatestuser2") {
172  $value .= "auth3-";
173  }
174 
175  if (ilObjUser::_externalAccountExists("ext_kabel", "cas")) {
176  $value .= "auth4-";
177  }
178 
180  $la = ilObjUser::_getLocalAccountsForEmail("qwe@ty.de");
181 
186 
187  // deletion
188  $user->delete();
189 
190  $this->assertEquals(
191  "email1-email2-auth1-auth2-auth3-auth4-",
192  $value
193  );
194  }
195 
196 
201  public function testSearch()
202  {
203  include_once("./Services/User/classes/class.ilObjUser.php");
204 
205  $value = "";
206 
207  ilObjUser::searchUsers("test", 1, false, false);
208  ilObjUser::searchUsers("test", 0, true, false);
209  ilObjUser::searchUsers("test", 1, false, 1);
210  ilObjUser::searchUsers("test", 1, false, 2);
211  ilObjUser::searchUsers("test", 1, false, 3);
212  ilObjUser::searchUsers("test", 1, false, 4);
213  ilObjUser::searchUsers("test", 1, false, 5);
214  ilObjUser::searchUsers("test", 1, false, 6);
215  ilObjUser::searchUsers("test", 1, false, 7);
216 
217  ilObjUser::_getAllUserData(array("lastname", "online_time"));
218  ilObjUser::_getAllUserData(array("lastname", "online_time"), 1);
219  ilObjUser::_getAllUserData(array("lastname", "online_time"), 2);
220  ilObjUser::_getAllUserData(array("lastname", "online_time"), 3);
221  ilObjUser::_getAllUserData(array("lastname", "online_time"), 4);
222  ilObjUser::_getAllUserData(array("lastname", "online_time"), 5);
223  ilObjUser::_getAllUserData(array("lastname", "online_time"), 6);
224  ilObjUser::_getAllUserData(array("lastname", "online_time"), 7);
225 
226  $this->assertEquals(
227  "",
228  $value
229  );
230  }
231 
236  public function testClipboard()
237  {
238  $value = "";
239 
240  // creation
241  $user = new ilObjUser();
242  $d = array(
243  "login" => "aatestuser3",
244  "passwd_type" => IL_PASSWD_PLAIN,
245  "passwd" => "password",
246  "gender" => "f",
247  "firstname" => "Heidi",
248  "lastname" => "Kabel",
249  "email" => "de@de.de"
250  );
251  $user->assignData($d);
252  $user->setActive(true);
253  $user->create();
254  $user->saveAsNew();
255  $user->setLanguage("de");
256  $user->writePrefs();
257  $id = $user->getId();
258 
259  $user->addObjectToClipboard($id, "user", "aatestuser");
260  $user->addObjectToClipboard(56, "mump", "mumpitz");
261  if ($user->clipboardHasObjectsOfType("user")) {
262  $value .= "clip1-";
263  }
264 
265  $user->clipboardDeleteObjectsOfType("user");
266  if ($user->clipboardHasObjectsOfType("mump") &&
267  !$user->clipboardHasObjectsOfType("user")) {
268  $value .= "clip2-";
269  }
270 
271  $objs = $user->getClipboardObjects("mump");
272  if (is_array($objs) && count($objs) == 1 && $objs[0]["id"] == 56) {
273  $value .= "clip3-";
274  }
275 
276  $objs = $user->getClipboardChilds(56, "2008-10-10");
277 
278  $us = ilObjUser::_getUsersForClipboadObject("mump", 56);
279 
280  if (is_array($us) && count($us) == 1 && $us[0] == $id) {
281  $value .= "clip4-";
282  }
283 
284  $user->delete();
285 
286  $this->assertEquals(
287  "clip1-clip2-clip3-clip4-",
288  $value
289  );
290  }
291 
296  public function testMiscellaneous()
297  {
298  $value = "";
299 
300  include_once("./Services/User/classes/class.ilObjUser.php");
301  ilObjUser::_getNumberOfUsersForStyle("default", "delos");
303  ilObjUser::_moveUsersToStyle("default", "delos", "default", "delos");
304 
305  $this->assertEquals(
306  "",
307  $value
308  );
309  }
310 }
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)
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
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)
static _lookupEmail($a_user_id)
Lookup email.
static _lookupPref($a_usr_id, $a_keyword)
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
$i
Definition: metadata.php:24
static _lookupLastLogin($a_user_id)
lookup last login